Skip to content

Commit 985264d

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 addbd77 commit 985264d

File tree

3 files changed

+179
-35
lines changed

3 files changed

+179
-35
lines changed

.docker/docker-bake.hcl

+94
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

+82-35
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
- iron
@@ -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:
@@ -121,22 +141,19 @@ jobs:
121141
uses: actions/checkout@v4
122142

123143
- name: Log into registry
144+
=======
145+
- name: Set Docker metadata for "robot"
146+
>>>>>>> a8681d0 (Add Docker BuildX config (#266))
124147
if: env.PUSH == 'true'
125-
uses: docker/[email protected]
126-
with:
127-
registry: ghcr.io
128-
username: ${{ github.actor }}
129-
password: ${{ secrets.GITHUB_TOKEN }}
130-
131-
- name: Extract Docker metadata
132-
if: env.PUSH == 'true'
133-
id: meta
148+
id: meta-robot
134149
uses: docker/[email protected]
135150
with:
136151
images: ghcr.io/${{ github.repository }}
152+
bake-target: docker-metadata-action-robot
137153
tags: |
138-
type=raw,value=${{ matrix.ROS_DISTRO }}-${{ github.job }}
154+
type=raw,value=${{ matrix.ROS_DISTRO }}-robot
139155
156+
<<<<<<< HEAD
140157
- name: Build and push Docker image
141158
uses: docker/[email protected]
142159
with:
@@ -162,29 +179,59 @@ jobs:
162179
uses: actions/checkout@v4
163180

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

.gitignore

+3
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)