Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker BuildX config #266

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a714d8b
Allow pushing to apl-ocean-engineering
amarburg Aug 6, 2024
fb1d847
Merge remote-tracking branch 'upstream/main' into main
amarburg Aug 6, 2024
298343c
Merge branch 'main' of https://github.com/Robotic-Decision-Making-Lab…
amarburg Aug 8, 2024
5020803
Merge branch 'main' of https://github.com/Robotic-Decision-Making-Lab…
amarburg Aug 19, 2024
5932e10
Merge branch 'main' of github.com:apl-ocean-engineering/blue into main
amarburg Aug 19, 2024
064c426
Merge branch 'main' of https://github.com/Robotic-Decision-Making-Lab…
amarburg Aug 19, 2024
0a7fe16
Install cppzmq-dev for Gazebo
amarburg Aug 5, 2024
5ad14a3
Allow pushing to apl-ocean-engineering
amarburg Aug 6, 2024
9632b0f
Reverse change in docker.yaml action.
amarburg Aug 8, 2024
9d98b26
Preliminary version of docker-bake.hcl and updated Docker workflow.
amarburg Aug 9, 2024
4fb87d7
Updated comments in Dockerfile
amarburg Aug 19, 2024
9b7be45
Attempt to allow manual triggering of builds
amarburg Aug 19, 2024
6ab2769
Nope, that's not it.
amarburg Aug 19, 2024
028e3e6
Add preliminary label to all Docker images.
amarburg Aug 20, 2024
830f3da
Removed redundant libcppzmq-dev
amarburg Aug 20, 2024
e06a30c
Hack to lowercase repo name
amarburg Aug 20, 2024
10d8dc7
Re-activate the metadata-action, go back to stages in matrix.
amarburg Aug 21, 2024
3b3538d
Add comment on lowercasing.
amarburg Aug 21, 2024
e873d09
Place files config at correct level.
amarburg Aug 21, 2024
f74c060
Merge branch 'dev/reimplement_metadata_action_presquash' into dev/use…
amarburg Aug 21, 2024
5c81971
Re-activate the metadata-action, go back to stages in matrix.
amarburg Aug 21, 2024
df4809a
Place files config at correct level.
amarburg Aug 21, 2024
5ffee9d
Switch to registry cache for CI
amarburg Aug 21, 2024
40da1cf
Merge branch 'dev/use_buildx_bake' of github.com:apl-ocean-engineerin…
amarburg Aug 22, 2024
042584f
Removed stage from matrix
amarburg Aug 22, 2024
1ebbfe3
Merge branch 'main' of github.com:apl-ocean-engineering/blue into dev…
amarburg Aug 22, 2024
2032dd1
Update repo URL, fix list formatting.
amarburg Aug 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .docker/docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#
# Override these variables with environment variables
# e.g.
#
# BLUE_ROS_DISTRO=iron docker buildx bake
#
# or
#
# export BLUE_ROS_DISTRO=iron
# docker buildx bake
#
variable "BLUE_ROS_DISTRO" { default = "rolling" }
variable "BLUE_GITHUB_REPO" { default = "robotic-decision-making-lab/blue" }

group "default" {
targets = ["ci", "robot", "desktop", "desktop-nvidia"]
}

# These are populated by the metadata-action Github action for each target
# when building in CI
#
target "docker-metadata-action-ci" {}
target "docker-metadata-action-robot" {}
target "docker-metadata-action-desktop" {}
target "docker-metadata-action-desktop-nvidia" {}


#
# All images can pull cache from the images published at Github
# or local storage (within the Buildkit image)
#
# ... and push cache to local storage
#
target "ci" {
inherits = ["docker-metadata-action-ci"]
dockerfile = ".docker/Dockerfile"
target = "ci"
context = ".."
args = {
ROS_DISTRO = "${BLUE_ROS_DISTRO}"
}
tags = [
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-ci"
]
labels = {
"org.opencontainers.image.source" = "https://github.com/${BLUE_GITHUB_REPO}"
}
cache_from =[
"ghcr.io/${BLUE_GITHUB_REPO}:cache-${BLUE_ROS_DISTRO}-ci",
"ghcr.io/${BLUE_GITHUB_REPO}:cache-${BLUE_ROS_DISTRO}-robot",
"ghcr.io/${BLUE_GITHUB_REPO}:cache-${BLUE_ROS_DISTRO}-desktop",
"ghcr.io/${BLUE_GITHUB_REPO}:cache-${BLUE_ROS_DISTRO}-desktop-nvidia",
"type=local,dest=.docker-cache"
]
cache_to = [
"type=local,dest=.docker-cache"
]
platforms = ["linux/amd64", "linux/arm64"]
}

target "robot" {
inherits = [ "ci", "docker-metadata-action-robot" ]
target = "robot"
tags = [
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-robot"
]
cache_to = [
"type=local,dest=.docker-cache"
]
}

target "desktop" {
inherits = [ "ci", "docker-metadata-action-desktop" ]
target = "desktop"
tags = [
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop"
]
cache_to = [
"type=local,dest=.docker-cache"
]
# amd64 only builds for desktop and desktop-nvidia
platforms = ["linux/amd64"]
}

target "desktop-nvidia" {
inherits = [ "desktop", "docker-metadata-action-desktop-nvidia" ]
target = "desktop-nvidia"
tags = [
"ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop-nvidia"
]
cache_to = [
"type=local,dest=.docker-cache"
]
}
203 changes: 73 additions & 130 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Docker

on:
schedule:
- cron: "0 17 * * 6"
# Disable schedule for preliminary testing
# schedule:
# - cron: "0 17 * * 6"
push:
branches:
- main
Expand All @@ -18,7 +19,7 @@ env:
PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'Robotic-Decision-Making-Lab/blue') }}

jobs:
ci:
docker_build:
strategy:
fail-fast: false
matrix:
Expand All @@ -28,164 +29,106 @@ jobs:
packages: write
contents: read
steps:
- name: Checkout repository
- name: Checkout
uses: actions/checkout@v4

- name: Log into registry
if: env.PUSH == 'true'
uses: docker/login-action@v3.3.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
if: env.PUSH == 'true'
id: meta
uses: docker/metadata-action@v5.5.1
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=${{ matrix.ROS_DISTRO }}-${{ github.job }}

- name: Build and push Docker image
uses: docker/build-push-action@v6.7.0
with:
context: .
file: .docker/Dockerfile
build-args: ROS_DISTRO=${{ matrix.ROS_DISTRO }}
target: ${{ github.job }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: ${{ env.PUSH }}

robot:
strategy:
fail-fast: false
matrix:
ROS_DISTRO: [rolling]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3.2.0
- # Add support for more platforms with QEMU (optional)
# https://github.com/docker/setup-qemu-action
name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Log into registry
if: env.PUSH == 'true'
- if: env.PUSH == 'true'
name: Log into registry
uses: docker/login-action@v3.3.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
# buildx bake, unfortunately, requires lower-cased repository names
# This shell ... er, hack, creates a local variable containing
# a down-cased version of $GITHUB_REPOSITORY
#
- id: lowercase-repo
name: Repository to lowercase
run: |
echo "repository=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT
evan-palmer marked this conversation as resolved.
Show resolved Hide resolved

# Set metadata for each stage-image separately
- name: Set Docker metadata for "ci"
if: env.PUSH == 'true'
id: meta
id: meta-ci
uses: docker/metadata-action@v5.5.1
with:
images: ghcr.io/${{ github.repository }}
bake-target: docker-metadata-action-ci
tags: |
type=raw,value=${{ matrix.ROS_DISTRO }}-${{ github.job }}

- name: Build and push Docker image
uses: docker/build-push-action@v6.7.0
with:
context: .
file: .docker/Dockerfile
build-args: ROS_DISTRO=${{ matrix.ROS_DISTRO }}
target: ${{ github.job }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: ${{ env.PUSH }}
platforms: linux/amd64
#platforms: linux/amd64,linux/arm64

desktop:
strategy:
fail-fast: false
matrix:
ROS_DISTRO: [rolling]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log into registry
if: env.PUSH == 'true'
uses: docker/login-action@v3.3.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
type=raw,value=${{ matrix.ROS_DISTRO }}-ci

- name: Extract Docker metadata
- name: Set Docker metadata for "robot"
if: env.PUSH == 'true'
id: meta
id: meta-robot
uses: docker/metadata-action@v5.5.1
with:
images: ghcr.io/${{ github.repository }}
bake-target: docker-metadata-action-robot
tags: |
type=raw,value=${{ matrix.ROS_DISTRO }}-${{ github.job }}

- name: Build and push Docker image
uses: docker/build-push-action@v6.7.0
with:
context: .
file: .docker/Dockerfile
build-args: ROS_DISTRO=${{ matrix.ROS_DISTRO }}
target: ${{ github.job }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: ${{ env.PUSH }}

desktop-nvidia:
strategy:
fail-fast: false
matrix:
ROS_DISTRO: [rolling]
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
type=raw,value=${{ matrix.ROS_DISTRO }}-robot

- name: Log into registry
- name: Set Docker metadata for "desktop"
if: env.PUSH == 'true'
uses: docker/login-action@v3.3.0
id: meta-desktop
uses: docker/metadata-action@v5.5.1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
images: ghcr.io/${{ github.repository }}
bake-target: docker-metadata-action-desktop
tags: |
type=raw,value=${{ matrix.ROS_DISTRO }}-desktop

- name: Extract Docker metadata
- name: Set Docker metadata for "desktop-nvidia"
if: env.PUSH == 'true'
id: meta
id: meta-desktop-nvidia
uses: docker/metadata-action@v5.5.1
with:
images: ghcr.io/${{ github.repository }}
bake-target: docker-metadata-action-desktop-nvidia
tags: |
type=raw,value=${{ matrix.ROS_DISTRO }}-${{ github.job }}

- name: Build and push Docker image
uses: docker/build-push-action@v6.7.0
type=raw,value=${{ matrix.ROS_DISTRO }}-desktop-nvidia

- if: github.event_name == 'push'
name: Build and push (non PR)
uses: docker/bake-action@v5.5.0
env:
BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }}
BLUE_GITHUB_REPO: ${{ steps.lowercase-repo.outputs.repository }}
with:
context: .
file: .docker/Dockerfile
build-args: ROS_DISTRO=${{ matrix.ROS_DISTRO }}
target: ${{ github.job }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
workdir: .docker
files: |
./docker-bake.hcl
${{ steps.meta-ci.outputs.bake-file }}
${{ steps.meta-robot.outputs.bake-file }}
${{ steps.meta-desktop.outputs.bake-file }}
${{ steps.meta-desktop-nvidia.outputs.bake-file }}
push: ${{ env.PUSH }}
set: |
*.cache-from=type=registry,ref=ghcr.io/${{ github.repository }}:cache-${{ matrix.ROS_DISTRO }}
*.cache-to=type=registry,mode=max,ref=ghcr.io/${{ github.repository }}:cache-${{ matrix.ROS_DISTRO }}

# Pull request builds are not cached; and only built for AMD64
evan-palmer marked this conversation as resolved.
Show resolved Hide resolved
- if: github.event_name == 'pull_request'
name: Build and push (PR)
uses: docker/bake-action@v5.5.0
env:
BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }}
BLUE_GITHUB_REPO: ${{ steps.lowercase-repo.outputs.repository }}
with:
workdir: .docker
files: |
./docker-bake.hcl
set: |
*.platform=linux/amd64
*.cache-from=type=registry,ref=ghcr.io/${{ github.repository }}:cache-${{ matrix.ROS_DISTRO }}
*.cache-to=
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ mav.parm
mav.tlog
mav.tlog.raw
logs/

# Allow overrides in docker-bake
.docker/docker-bake.override.hcl