Skip to content

Commit dd20df6

Browse files
Add Docker BuildX config (backport #266) (#269)
* 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 * Resolve conflicts while merging #266 --------- Co-authored-by: Aaron Marburg <[email protected]>
1 parent 2671559 commit dd20df6

File tree

3 files changed

+170
-129
lines changed

3 files changed

+170
-129
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

+73-129
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
- humble
@@ -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,163 +29,106 @@ jobs:
2829
packages: write
2930
contents: read
3031
steps:
31-
- name: Checkout repository
32+
- name: Checkout
3233
uses: actions/checkout@v4
3334

34-
- name: Log into registry
35-
if: env.PUSH == 'true'
36-
uses: docker/[email protected]
37-
with:
38-
registry: ghcr.io
39-
username: ${{ github.actor }}
40-
password: ${{ secrets.GITHUB_TOKEN }}
41-
42-
- name: Extract Docker metadata
43-
if: env.PUSH == 'true'
44-
id: meta
45-
uses: docker/[email protected]
46-
with:
47-
images: ghcr.io/${{ github.repository }}
48-
tags: |
49-
type=raw,value=${{ matrix.ROS_DISTRO }}-${{ github.job }}
50-
51-
- name: Build and push Docker image
52-
uses: docker/[email protected]
53-
with:
54-
context: .
55-
file: .docker/Dockerfile
56-
build-args: ROS_DISTRO=${{ matrix.ROS_DISTRO }}
57-
target: ${{ github.job }}
58-
tags: ${{ steps.meta.outputs.tags }}
59-
labels: ${{ steps.meta.outputs.labels }}
60-
push: ${{ env.PUSH }}
61-
62-
robot:
63-
strategy:
64-
fail-fast: false
65-
matrix:
66-
ROS_DISTRO: [humble]
67-
runs-on: ubuntu-latest
68-
permissions:
69-
packages: write
70-
contents: read
71-
steps:
72-
- name: Checkout repository
73-
uses: actions/checkout@v4
74-
75-
- name: Set up QEMU
76-
uses: docker/[email protected]
35+
- # Add support for more platforms with QEMU (optional)
36+
# https://github.com/docker/setup-qemu-action
37+
name: Set up QEMU
38+
uses: docker/setup-qemu-action@v3
7739

7840
- name: Set up Docker Buildx
7941
uses: docker/setup-buildx-action@v3
8042

81-
- name: Log into registry
82-
if: env.PUSH == 'true'
43+
- if: env.PUSH == 'true'
44+
name: Log into registry
8345
uses: docker/[email protected]
8446
with:
8547
registry: ghcr.io
8648
username: ${{ github.actor }}
8749
password: ${{ secrets.GITHUB_TOKEN }}
8850

89-
- name: Extract Docker metadata
51+
# buildx bake, unfortunately, requires lower-cased repository names
52+
# This shell ... er, hack, creates a local variable containing
53+
# a down-cased version of $GITHUB_REPOSITORY
54+
#
55+
- id: lowercase-repo
56+
name: Repository to lowercase
57+
run: |
58+
echo "repository=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT
59+
60+
# Set metadata for each stage-image separately
61+
- name: Set Docker metadata for "ci"
9062
if: env.PUSH == 'true'
91-
id: meta
63+
id: meta-ci
9264
uses: docker/[email protected]
9365
with:
9466
images: ghcr.io/${{ github.repository }}
67+
bake-target: docker-metadata-action-ci
9568
tags: |
96-
type=raw,value=${{ matrix.ROS_DISTRO }}-${{ github.job }}
97-
98-
- name: Build and push Docker image
99-
uses: docker/[email protected]
100-
with:
101-
context: .
102-
file: .docker/Dockerfile
103-
build-args: ROS_DISTRO=${{ matrix.ROS_DISTRO }}
104-
target: ${{ github.job }}
105-
tags: ${{ steps.meta.outputs.tags }}
106-
labels: ${{ steps.meta.outputs.labels }}
107-
push: ${{ env.PUSH }}
108-
platforms: linux/amd64,linux/arm64
109-
110-
desktop:
111-
strategy:
112-
fail-fast: false
113-
matrix:
114-
ROS_DISTRO: [humble]
115-
runs-on: ubuntu-latest
116-
permissions:
117-
packages: write
118-
contents: read
119-
steps:
120-
- name: Checkout repository
121-
uses: actions/checkout@v4
122-
123-
- name: Log into registry
124-
if: env.PUSH == 'true'
125-
uses: docker/[email protected]
126-
with:
127-
registry: ghcr.io
128-
username: ${{ github.actor }}
129-
password: ${{ secrets.GITHUB_TOKEN }}
69+
type=raw,value=${{ matrix.ROS_DISTRO }}-ci
13070
131-
- name: Extract Docker metadata
71+
- name: Set Docker metadata for "robot"
13272
if: env.PUSH == 'true'
133-
id: meta
73+
id: meta-robot
13474
uses: docker/[email protected]
13575
with:
13676
images: ghcr.io/${{ github.repository }}
77+
bake-target: docker-metadata-action-robot
13778
tags: |
138-
type=raw,value=${{ matrix.ROS_DISTRO }}-${{ github.job }}
139-
140-
- name: Build and push Docker image
141-
uses: docker/[email protected]
142-
with:
143-
context: .
144-
file: .docker/Dockerfile
145-
build-args: ROS_DISTRO=${{ matrix.ROS_DISTRO }}
146-
target: ${{ github.job }}
147-
tags: ${{ steps.meta.outputs.tags }}
148-
labels: ${{ steps.meta.outputs.labels }}
149-
push: ${{ env.PUSH }}
150-
151-
desktop-nvidia:
152-
strategy:
153-
fail-fast: false
154-
matrix:
155-
ROS_DISTRO: [humble]
156-
runs-on: ubuntu-latest
157-
permissions:
158-
packages: write
159-
contents: read
160-
steps:
161-
- name: Checkout repository
162-
uses: actions/checkout@v4
79+
type=raw,value=${{ matrix.ROS_DISTRO }}-robot
16380
164-
- name: Log into registry
81+
- name: Set Docker metadata for "desktop"
16582
if: env.PUSH == 'true'
166-
uses: docker/[email protected]
83+
id: meta-desktop
84+
uses: docker/[email protected]
16785
with:
168-
registry: ghcr.io
169-
username: ${{ github.actor }}
170-
password: ${{ secrets.GITHUB_TOKEN }}
86+
images: ghcr.io/${{ github.repository }}
87+
bake-target: docker-metadata-action-desktop
88+
tags: |
89+
type=raw,value=${{ matrix.ROS_DISTRO }}-desktop
17190
172-
- name: Extract Docker metadata
91+
- name: Set Docker metadata for "desktop-nvidia"
17392
if: env.PUSH == 'true'
174-
id: meta
93+
id: meta-desktop-nvidia
17594
uses: docker/[email protected]
17695
with:
17796
images: ghcr.io/${{ github.repository }}
97+
bake-target: docker-metadata-action-desktop-nvidia
17898
tags: |
179-
type=raw,value=${{ matrix.ROS_DISTRO }}-${{ github.job }}
180-
181-
- name: Build and push Docker image
182-
uses: docker/[email protected]
99+
type=raw,value=${{ matrix.ROS_DISTRO }}-desktop-nvidia
100+
101+
- if: github.event_name == 'push'
102+
name: Build and push (non PR)
103+
uses: docker/[email protected]
104+
env:
105+
BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }}
106+
BLUE_GITHUB_REPO: ${{ steps.lowercase-repo.outputs.repository }}
183107
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 }}
108+
workdir: .docker
109+
files: |
110+
./docker-bake.hcl
111+
${{ steps.meta-ci.outputs.bake-file }}
112+
${{ steps.meta-robot.outputs.bake-file }}
113+
${{ steps.meta-desktop.outputs.bake-file }}
114+
${{ steps.meta-desktop-nvidia.outputs.bake-file }}
190115
push: ${{ env.PUSH }}
116+
set: |
117+
*.cache-from=type=registry,ref=ghcr.io/${{ github.repository }}:cache-${{ matrix.ROS_DISTRO }}
118+
*.cache-to=type=registry,mode=max,ref=ghcr.io/${{ github.repository }}:cache-${{ matrix.ROS_DISTRO }}
119+
120+
# Pull request builds are not cached; and only built for AMD64
121+
- if: github.event_name == 'pull_request'
122+
name: Build and push (PR)
123+
uses: docker/[email protected]
124+
env:
125+
BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }}
126+
BLUE_GITHUB_REPO: ${{ steps.lowercase-repo.outputs.repository }}
127+
with:
128+
workdir: .docker
129+
files: |
130+
./docker-bake.hcl
131+
set: |
132+
*.platform=linux/amd64
133+
*.cache-from=type=registry,ref=ghcr.io/${{ github.repository }}:cache-${{ matrix.ROS_DISTRO }}
134+
*.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)