Dev/fix docker workflow buildx bake #122
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker | |
on: | |
schedule: | |
- cron: "0 17 * * 6" | |
push: | |
branches: | |
- main | |
pull_request: | |
paths: | |
- .docker/** | |
- .github/workflows/docker.yaml | |
- blue.repos | |
- requirements-build.txt | |
workflow_dispatch: | |
env: | |
PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'Robotic-Decision-Making-Lab/blue') }} | |
jobs: | |
docker_build: | |
strategy: | |
fail-fast: false | |
matrix: | |
ROS_DISTRO: [rolling] | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: read | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- # 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 | |
with: | |
# Pin buildx to this version | |
# Issues with setting "*.cache-to=" below with v0.19.2 | |
version: v0.18.0 | |
- if: env.PUSH == 'true' | |
name: Log into registry | |
uses: docker/#-action@v3.3.0 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# 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 | |
# Set metadata for each stage-image separately | |
- name: Set Docker metadata for "ci" | |
if: env.PUSH == 'true' | |
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 }}-ci | |
- name: Set Docker metadata for "robot" | |
if: env.PUSH == 'true' | |
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 }}-robot | |
- name: Set Docker metadata for "desktop" | |
if: env.PUSH == 'true' | |
id: meta-desktop | |
uses: docker/metadata-action@v5.5.1 | |
with: | |
images: ghcr.io/${{ github.repository }} | |
bake-target: docker-metadata-action-desktop | |
tags: | | |
type=raw,value=${{ matrix.ROS_DISTRO }}-desktop | |
- name: Set Docker metadata for "desktop-nvidia" | |
if: env.PUSH == 'true' | |
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 }}-desktop-nvidia | |
- if: github.event_name == 'push' | |
name: Build and push (non PR) | |
uses: docker/bake-action@v5.10.0 | |
env: | |
BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }} | |
BLUE_GITHUB_REPO: ${{ steps.lowercase-repo.outputs.repository }} | |
with: | |
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/${{ steps.lowercase-repo.outputs.repository }}:cache-${{ matrix.ROS_DISTRO }} | |
*.cache-to=type=registry,mode=max,ref=ghcr.io/${{ steps.lowercase-repo.outputs.repository }}:cache-${{ matrix.ROS_DISTRO }} | |
# Pull request builds are not cached; and only built for AMD64 | |
- if: github.event_name == 'pull_request' | |
name: Build and push (PR) | |
uses: docker/bake-action@v5.10.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/${{ steps.lowercase-repo.outputs.repository }}:cache-${{ matrix.ROS_DISTRO }} | |
*.cache-to= |