Skip to content

Commit bb42151

Browse files
amarburgmergify[bot]
authored andcommitted
Add Docker BuildX config (#266)
* Allow pushing to apl-ocean-engineering * Install cppzmq-dev for Gazebo * Allow pushing to apl-ocean-engineering * Reverse change in docker.yaml action. * Preliminary version of docker-bake.hcl and updated Docker workflow. * Updated comments in Dockerfile * Attempt to allow manual triggering of builds * Nope, that's not it. * Add preliminary label to all Docker images. * Removed redundant libcppzmq-dev * Hack to lowercase repo name * Re-activate the metadata-action, go back to stages in matrix. * Add comment on lowercasing. * Place files config at correct level. * Re-activate the metadata-action, go back to stages in matrix. * Place files config at correct level. * Switch to registry cache for CI * Removed stage from matrix * Update repo URL, fix list formatting. (cherry picked from commit a8681d0) # Conflicts: # .github/workflows/docker.yaml
1 parent 0559e9c commit bb42151

File tree

3 files changed

+179
-35
lines changed

3 files changed

+179
-35
lines changed

.docker/docker-bake.hcl

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#
2+
# Override these variables with environment variables
3+
# e.g.
4+
#
5+
# BLUE_ROS_DISTRO=iron docker buildx bake
6+
#
7+
# or
8+
#
9+
# export BLUE_ROS_DISTRO=iron
10+
# docker buildx bake
11+
#
12+
variable "BLUE_ROS_DISTRO" { default = "rolling" }
13+
variable "BLUE_GITHUB_REPO" { default = "robotic-decision-making-lab/blue" }
14+
15+
group "default" {
16+
targets = ["ci", "robot", "desktop", "desktop-nvidia"]
17+
}
18+
19+
# These are populated by the metadata-action Github action for each target
20+
# when building in CI
21+
#
22+
target "docker-metadata-action-ci" {}
23+
target "docker-metadata-action-robot" {}
24+
target "docker-metadata-action-desktop" {}
25+
target "docker-metadata-action-desktop-nvidia" {}
26+
27+
28+
#
29+
# All images can pull cache from the images published at Github
30+
# or local storage (within the Buildkit image)
31+
#
32+
# ... and push cache to local storage
33+
#
34+
target "ci" {
35+
inherits = ["docker-metadata-action-ci"]
36+
dockerfile = ".docker/Dockerfile"
37+
target = "ci"
38+
context = ".."
39+
args = {
40+
ROS_DISTRO = "${BLUE_ROS_DISTRO}"
41+
}
42+
tags = [
43+
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-ci"
44+
]
45+
labels = {
46+
"org.opencontainers.image.source" = "https://github.com/${BLUE_GITHUB_REPO}"
47+
}
48+
cache_from =[
49+
"ghcr.io/${BLUE_GITHUB_REPO}:cache-${BLUE_ROS_DISTRO}-ci",
50+
"ghcr.io/${BLUE_GITHUB_REPO}:cache-${BLUE_ROS_DISTRO}-robot",
51+
"ghcr.io/${BLUE_GITHUB_REPO}:cache-${BLUE_ROS_DISTRO}-desktop",
52+
"ghcr.io/${BLUE_GITHUB_REPO}:cache-${BLUE_ROS_DISTRO}-desktop-nvidia",
53+
"type=local,dest=.docker-cache"
54+
]
55+
cache_to = [
56+
"type=local,dest=.docker-cache"
57+
]
58+
platforms = ["linux/amd64", "linux/arm64"]
59+
}
60+
61+
target "robot" {
62+
inherits = [ "ci", "docker-metadata-action-robot" ]
63+
target = "robot"
64+
tags = [
65+
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-robot"
66+
]
67+
cache_to = [
68+
"type=local,dest=.docker-cache"
69+
]
70+
}
71+
72+
target "desktop" {
73+
inherits = [ "ci", "docker-metadata-action-desktop" ]
74+
target = "desktop"
75+
tags = [
76+
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop"
77+
]
78+
cache_to = [
79+
"type=local,dest=.docker-cache"
80+
]
81+
# amd64 only builds for desktop and desktop-nvidia
82+
platforms = ["linux/amd64"]
83+
}
84+
85+
target "desktop-nvidia" {
86+
inherits = [ "desktop", "docker-metadata-action-desktop-nvidia" ]
87+
target = "desktop-nvidia"
88+
tags = [
89+
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop-nvidia"
90+
]
91+
cache_to = [
92+
"type=local,dest=.docker-cache"
93+
]
94+
}

.github/workflows/docker.yaml

Lines changed: 82 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: Docker
22

33
on:
4-
schedule:
5-
- cron: "0 17 * * 6"
4+
# Disable schedule for preliminary testing
5+
# schedule:
6+
# - cron: "0 17 * * 6"
67
push:
78
branches:
89
- jazzy
@@ -18,7 +19,7 @@ env:
1819
PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'Robotic-Decision-Making-Lab/blue') }}
1920

2021
jobs:
21-
ci:
22+
docker_build:
2223
strategy:
2324
fail-fast: false
2425
matrix:
@@ -28,9 +29,10 @@ jobs:
2829
packages: write
2930
contents: read
3031
steps:
31-
- name: Checkout repository
32+
- name: Checkout
3233
uses: actions/checkout@v4
3334

35+
<<<<<<< HEAD
3436
- name: Log into registry
3537
if: env.PUSH == 'true'
3638
uses: docker/[email protected]
@@ -74,27 +76,45 @@ jobs:
7476

7577
- name: Set up QEMU
7678
uses: docker/[email protected]
79+
=======
80+
- # Add support for more platforms with QEMU (optional)
81+
# https://github.com/docker/setup-qemu-action
82+
name: Set up QEMU
83+
uses: docker/setup-qemu-action@v3
84+
>>>>>>> a8681d0 (Add Docker BuildX config (#266))
7785

7886
- name: Set up Docker Buildx
7987
uses: docker/setup-buildx-action@v3
8088

81-
- name: Log into registry
82-
if: env.PUSH == 'true'
89+
- if: env.PUSH == 'true'
90+
name: Log into registry
8391
uses: docker/[email protected]
8492
with:
8593
registry: ghcr.io
8694
username: ${{ github.actor }}
8795
password: ${{ secrets.GITHUB_TOKEN }}
8896

89-
- name: Extract Docker metadata
97+
# buildx bake, unfortunately, requires lower-cased repository names
98+
# This shell ... er, hack, creates a local variable containing
99+
# a down-cased version of $GITHUB_REPOSITORY
100+
#
101+
- id: lowercase-repo
102+
name: Repository to lowercase
103+
run: |
104+
echo "repository=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT
105+
106+
# Set metadata for each stage-image separately
107+
- name: Set Docker metadata for "ci"
90108
if: env.PUSH == 'true'
91-
id: meta
109+
id: meta-ci
92110
uses: docker/[email protected]
93111
with:
94112
images: ghcr.io/${{ github.repository }}
113+
bake-target: docker-metadata-action-ci
95114
tags: |
96-
type=raw,value=${{ matrix.ROS_DISTRO }}-${{ github.job }}
115+
type=raw,value=${{ matrix.ROS_DISTRO }}-ci
97116
117+
<<<<<<< HEAD
98118
- name: Build and push Docker image
99119
uses: docker/[email protected]
100120
with:
@@ -122,22 +142,19 @@ jobs:
122142
uses: actions/checkout@v4
123143

124144
- name: Log into registry
145+
=======
146+
- name: Set Docker metadata for "robot"
147+
>>>>>>> a8681d0 (Add Docker BuildX config (#266))
125148
if: env.PUSH == 'true'
126-
uses: docker/[email protected]
127-
with:
128-
registry: ghcr.io
129-
username: ${{ github.actor }}
130-
password: ${{ secrets.GITHUB_TOKEN }}
131-
132-
- name: Extract Docker metadata
133-
if: env.PUSH == 'true'
134-
id: meta
149+
id: meta-robot
135150
uses: docker/[email protected]
136151
with:
137152
images: ghcr.io/${{ github.repository }}
153+
bake-target: docker-metadata-action-robot
138154
tags: |
139-
type=raw,value=${{ matrix.ROS_DISTRO }}-${{ github.job }}
155+
type=raw,value=${{ matrix.ROS_DISTRO }}-robot
140156
157+
<<<<<<< HEAD
141158
- name: Build and push Docker image
142159
uses: docker/[email protected]
143160
with:
@@ -163,29 +180,59 @@ jobs:
163180
uses: actions/checkout@v4
164181

165182
- name: Log into registry
183+
=======
184+
- name: Set Docker metadata for "desktop"
185+
>>>>>>> a8681d0 (Add Docker BuildX config (#266))
166186
if: env.PUSH == 'true'
167-
uses: docker/[email protected]
187+
id: meta-desktop
188+
uses: docker/[email protected]
168189
with:
169-
registry: ghcr.io
170-
username: ${{ github.actor }}
171-
password: ${{ secrets.GITHUB_TOKEN }}
190+
images: ghcr.io/${{ github.repository }}
191+
bake-target: docker-metadata-action-desktop
192+
tags: |
193+
type=raw,value=${{ matrix.ROS_DISTRO }}-desktop
172194
173-
- name: Extract Docker metadata
195+
- name: Set Docker metadata for "desktop-nvidia"
174196
if: env.PUSH == 'true'
175-
id: meta
197+
id: meta-desktop-nvidia
176198
uses: docker/[email protected]
177199
with:
178200
images: ghcr.io/${{ github.repository }}
201+
bake-target: docker-metadata-action-desktop-nvidia
179202
tags: |
180-
type=raw,value=${{ matrix.ROS_DISTRO }}-${{ github.job }}
181-
182-
- name: Build and push Docker image
183-
uses: docker/[email protected]
203+
type=raw,value=${{ matrix.ROS_DISTRO }}-desktop-nvidia
204+
205+
- if: github.event_name == 'push'
206+
name: Build and push (non PR)
207+
uses: docker/[email protected]
208+
env:
209+
BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }}
210+
BLUE_GITHUB_REPO: ${{ steps.lowercase-repo.outputs.repository }}
184211
with:
185-
context: .
186-
file: .docker/Dockerfile
187-
build-args: ROS_DISTRO=${{ matrix.ROS_DISTRO }}
188-
target: ${{ github.job }}
189-
tags: ${{ steps.meta.outputs.tags }}
190-
labels: ${{ steps.meta.outputs.labels }}
212+
workdir: .docker
213+
files: |
214+
./docker-bake.hcl
215+
${{ steps.meta-ci.outputs.bake-file }}
216+
${{ steps.meta-robot.outputs.bake-file }}
217+
${{ steps.meta-desktop.outputs.bake-file }}
218+
${{ steps.meta-desktop-nvidia.outputs.bake-file }}
191219
push: ${{ env.PUSH }}
220+
set: |
221+
*.cache-from=type=registry,ref=ghcr.io/${{ github.repository }}:cache-${{ matrix.ROS_DISTRO }}
222+
*.cache-to=type=registry,mode=max,ref=ghcr.io/${{ github.repository }}:cache-${{ matrix.ROS_DISTRO }}
223+
224+
# Pull request builds are not cached; and only built for AMD64
225+
- if: github.event_name == 'pull_request'
226+
name: Build and push (PR)
227+
uses: docker/[email protected]
228+
env:
229+
BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }}
230+
BLUE_GITHUB_REPO: ${{ steps.lowercase-repo.outputs.repository }}
231+
with:
232+
workdir: .docker
233+
files: |
234+
./docker-bake.hcl
235+
set: |
236+
*.platform=linux/amd64
237+
*.cache-from=type=registry,ref=ghcr.io/${{ github.repository }}:cache-${{ matrix.ROS_DISTRO }}
238+
*.cache-to=

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ mav.parm
1616
mav.tlog
1717
mav.tlog.raw
1818
logs/
19+
20+
# Allow overrides in docker-bake
21+
.docker/docker-bake.override.hcl

0 commit comments

Comments
 (0)