Skip to content

Commit 9d98b26

Browse files
committed
Preliminary version of docker-bake.hcl and updated Docker workflow.
1 parent 9632b0f commit 9d98b26

File tree

3 files changed

+140
-150
lines changed

3 files changed

+140
-150
lines changed

.docker/docker-bake.hcl

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
#
20+
# All images can pull cache from the images published at Github
21+
# or local storage (within the Buildkit image)
22+
#
23+
# ... and push cache to local storage
24+
#
25+
target "ci" {
26+
dockerfile = ".docker/Dockerfile"
27+
target = "ci"
28+
context = ".."
29+
args = {
30+
ROS_DISTRO = "${BLUE_ROS_DISTRO}"
31+
}
32+
tags = [
33+
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-ci"
34+
]
35+
cache_from =[
36+
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-ci",
37+
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-robot",
38+
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop",
39+
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop-nvidia",
40+
"type=local,dest=.docker-cache"
41+
]
42+
cache_to = [
43+
"type=local,dest=.docker-cache"
44+
]
45+
platforms = ["linux/amd64", "linux/arm64"]
46+
}
47+
48+
target "robot" {
49+
inherits = [ "ci" ]
50+
target = "robot"
51+
tags = [
52+
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-robot"
53+
]
54+
cache_to = [
55+
"type=local,dest=.docker-cache"
56+
]
57+
}
58+
59+
target "desktop" {
60+
inherits = [ "ci" ]
61+
target = "desktop"
62+
tags = [
63+
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop"
64+
]
65+
cache_to = [
66+
"type=local,dest=.docker-cache"
67+
]
68+
# amd64 only builds for desktop and desktop-nvidia
69+
platforms = ["linux/amd64"]
70+
}
71+
72+
target "desktop-nvidia" {
73+
inherits = [ "desktop" ]
74+
target = "desktop-nvidia"
75+
tags = [
76+
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop-nvidia"
77+
]
78+
cache_to = [
79+
"type=local,dest=.docker-cache"
80+
]
81+
}

.github/workflows/docker.yaml

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

33
on:
4-
schedule:
5-
- cron: "0 17 * * 6"
4+
# schedule:
5+
# - cron: "0 17 * * 6"
66
push:
77
branches:
88
- main
@@ -15,10 +15,10 @@ on:
1515
workflow_dispatch:
1616

1717
env:
18-
PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'Robotic-Decision-Making-Lab/blue') }}
18+
PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'apl-ocean-engineering/blue') }}
1919

2020
jobs:
21-
ci:
21+
docker_build:
2222
strategy:
2323
fail-fast: false
2424
matrix:
@@ -27,165 +27,71 @@ jobs:
2727
permissions:
2828
packages: write
2929
contents: read
30+
env:
31+
BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }}
32+
BLUE_GITHUB_REPO: ${{ github.repository }}
3033
steps:
31-
- name: Checkout repository
34+
-
35+
name: Checkout repository
3236
uses: actions/checkout@v4
3337

34-
- name: Log into registry
35-
if: env.PUSH == 'true'
36-
uses: docker/login-action@v3.3.0
37-
with:
38-
registry: ghcr.io
39-
username: ${{ github.actor }}
40-
password: ${{ secrets.GITHUB_TOKEN }}
38+
-
39+
# Add support for more platforms with QEMU (optional)
40+
# https://github.com/docker/setup-qemu-action
41+
name: Set up QEMU
42+
uses: docker/setup-qemu-action@v3
4143

42-
- name: Extract Docker metadata
43-
if: env.PUSH == 'true'
44-
id: meta
45-
uses: docker/metadata-action@v5.5.1
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/build-push-action@v6.7.0
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: [rolling]
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/setup-qemu-action@v3.2.0
77-
78-
- name: Set up Docker Buildx
44+
-
45+
name: Set up Docker Buildx
7946
uses: docker/setup-buildx-action@v3
8047

81-
- name: Log into registry
82-
if: env.PUSH == 'true'
83-
uses: docker/login-action@v3.3.0
84-
with:
85-
registry: ghcr.io
86-
username: ${{ github.actor }}
87-
password: ${{ secrets.GITHUB_TOKEN }}
88-
89-
- name: Extract Docker metadata
90-
if: env.PUSH == 'true'
91-
id: meta
92-
uses: docker/metadata-action@v5.5.1
93-
with:
94-
images: ghcr.io/${{ github.repository }}
95-
tags: |
96-
type=raw,value=${{ matrix.ROS_DISTRO }}-${{ github.job }}
97-
98-
- name: Build and push Docker image
99-
uses: docker/build-push-action@v6.7.0
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
109-
#platforms: linux/amd64,linux/arm64
110-
111-
desktop:
112-
strategy:
113-
fail-fast: false
114-
matrix:
115-
ROS_DISTRO: [rolling]
116-
runs-on: ubuntu-latest
117-
permissions:
118-
packages: write
119-
contents: read
120-
steps:
121-
- name: Checkout repository
122-
uses: actions/checkout@v4
123-
124-
- name: Log into registry
48+
-
12549
if: env.PUSH == 'true'
50+
name: Log into registry
12651
uses: docker/login-action@v3.3.0
12752
with:
12853
registry: ghcr.io
12954
username: ${{ github.actor }}
13055
password: ${{ secrets.GITHUB_TOKEN }}
13156

132-
- name: Extract Docker metadata
133-
if: env.PUSH == 'true'
134-
id: meta
135-
uses: docker/metadata-action@v5.5.1
57+
# -
58+
# name: Extract Docker metadata
59+
# if: env.PUSH == 'true'
60+
# id: meta
61+
# uses: docker/metadata-action@v5.5.1
62+
# with:
63+
# images: ghcr.io/${{ github.repository }}
64+
# tags: |
65+
# type=raw,value=${{ matrix.ROS_DISTRO }}-${{ matrix.stage }}
66+
67+
- if: github.event_name == 'push'
68+
name: Build and push (non PR)
69+
uses: docker/bake-action@v5.5.0
13670
with:
137-
images: ghcr.io/${{ github.repository }}
138-
tags: |
139-
type=raw,value=${{ matrix.ROS_DISTRO }}-${{ github.job }}
140-
141-
- name: Build and push Docker image
142-
uses: docker/build-push-action@v6.7.0
143-
with:
144-
context: .
145-
file: .docker/Dockerfile
146-
build-args: ROS_DISTRO=${{ matrix.ROS_DISTRO }}
147-
target: ${{ github.job }}
148-
tags: ${{ steps.meta.outputs.tags }}
149-
labels: ${{ steps.meta.outputs.labels }}
71+
workdir: .docker
15072
push: ${{ env.PUSH }}
151-
152-
desktop-nvidia:
153-
strategy:
154-
fail-fast: false
155-
matrix:
156-
ROS_DISTRO: [rolling]
157-
runs-on: ubuntu-latest
158-
permissions:
159-
packages: write
160-
contents: read
161-
steps:
162-
- name: Checkout repository
163-
uses: actions/checkout@v4
164-
165-
- name: Log into registry
166-
if: env.PUSH == 'true'
167-
uses: docker/login-action@v3.3.0
73+
set: |
74+
*.platform=linux/amd64
75+
*.cache-from=type=gha,scope=ci
76+
*.cache-from=type=gha,scope=robot
77+
*.cache-from=type=gha,scope=desktop
78+
*.cache-from=type=gha,scope=desktop-nvidia
79+
ci.cache-to=type=gha,mode=max,scope=ci
80+
robot.cache-to=type=gha,mode=max,scope=robot
81+
desktop.cache-to=type=gha,mode=max,scope=desktop
82+
desktop-nvidia.cache-to=type=gha,mode=max,scope=desktop-nvidia
83+
84+
- if: github.event_name == 'pull_request'
85+
name: Build and push (PR)
86+
uses: docker/bake-action@v5.5.0
16887
with:
169-
registry: ghcr.io
170-
username: ${{ github.actor }}
171-
password: ${{ secrets.GITHUB_TOKEN }}
172-
173-
- name: Extract Docker metadata
174-
if: env.PUSH == 'true'
175-
id: meta
176-
uses: docker/metadata-action@v5.5.1
177-
with:
178-
images: ghcr.io/${{ github.repository }}
179-
tags: |
180-
type=raw,value=${{ matrix.ROS_DISTRO }}-${{ github.job }}
181-
182-
- name: Build and push Docker image
183-
uses: docker/build-push-action@v6.7.0
184-
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 }}
191-
push: ${{ env.PUSH }}
88+
workdir: .docker
89+
targets: |
90+
${{ matrix.stage }}
91+
set: |
92+
*.platform=linux/amd64
93+
*.cache-from=type=gha,scope=ci
94+
*.cache-from=type=gha,scope=robot
95+
*.cache-from=type=gha,scope=desktop
96+
*.cache-from=type=gha,scope=desktop-nvidia
97+
*.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)