From a714d8b07862a6faadf52c88599fe991d986eccc Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Mon, 5 Aug 2024 17:27:33 -0700 Subject: [PATCH 01/19] Allow pushing to apl-ocean-engineering --- .github/workflows/docker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 82fe5a2b..b809dc5a 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -15,7 +15,7 @@ on: workflow_dispatch: env: - PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'Robotic-Decision-Making-Lab/blue') }} + PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'apl-ocean-engineering/blue') }} jobs: ci: From 0a7fe16a1f4ed696542717ea245573225733dac6 Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Mon, 5 Aug 2024 14:39:08 -0700 Subject: [PATCH 02/19] Install cppzmq-dev for Gazebo --- .docker/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 85540dee..67e39b1d 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -170,6 +170,7 @@ RUN wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pk xterm \ rapidjson-dev \ libopencv-dev \ + cppzmq-dev \ && apt-get autoremove -y \ && apt-get clean -y \ && rm -rf /var/lib/apt/lists/* From 5ad14a3190bcd4fc3b8131c03c1fe997526bd92d Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Mon, 5 Aug 2024 17:27:33 -0700 Subject: [PATCH 03/19] Allow pushing to apl-ocean-engineering --- .github/workflows/docker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 356e4ee2..40313522 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -15,7 +15,7 @@ on: workflow_dispatch: env: - PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'Robotic-Decision-Making-Lab/blue') }} + PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'apl-ocean-engineering/blue') }} jobs: ci: From 9632b0f9898ad3bb58625ea3b35c934def476add Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Thu, 8 Aug 2024 13:48:23 -0700 Subject: [PATCH 04/19] Reverse change in docker.yaml action. --- .github/workflows/docker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 40313522..356e4ee2 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -15,7 +15,7 @@ on: workflow_dispatch: env: - PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'apl-ocean-engineering/blue') }} + PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'Robotic-Decision-Making-Lab/blue') }} jobs: ci: From 9d98b26cd3712c3148f22b3c7b7a0566b5d794d1 Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Fri, 9 Aug 2024 14:24:43 -0700 Subject: [PATCH 05/19] Preliminary version of docker-bake.hcl and updated Docker workflow. --- .docker/docker-bake.hcl | 81 +++++++++++++ .github/workflows/docker.yaml | 206 +++++++++------------------------- .gitignore | 3 + 3 files changed, 140 insertions(+), 150 deletions(-) create mode 100644 .docker/docker-bake.hcl diff --git a/.docker/docker-bake.hcl b/.docker/docker-bake.hcl new file mode 100644 index 00000000..c4f3f8df --- /dev/null +++ b/.docker/docker-bake.hcl @@ -0,0 +1,81 @@ +# +# 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"] +} + +# +# 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" { + dockerfile = ".docker/Dockerfile" + target = "ci" + context = ".." + args = { + ROS_DISTRO = "${BLUE_ROS_DISTRO}" + } + tags = [ + "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-ci" + ] + cache_from =[ + "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-ci", + "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-robot", + "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop", + "ghcr.io/${BLUE_GITHUB_REPO}:${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" ] + target = "robot" + tags = [ + "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-robot" + ] + cache_to = [ + "type=local,dest=.docker-cache" + ] +} + +target "desktop" { + inherits = [ "ci" ] + 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" ] + target = "desktop-nvidia" + tags = [ + "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop-nvidia" + ] + cache_to = [ + "type=local,dest=.docker-cache" + ] +} diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 356e4ee2..bcbb2114 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -1,8 +1,8 @@ name: Docker on: - schedule: - - cron: "0 17 * * 6" + # schedule: + # - cron: "0 17 * * 6" push: branches: - main @@ -15,10 +15,10 @@ on: workflow_dispatch: env: - PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'Robotic-Decision-Making-Lab/blue') }} + PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'apl-ocean-engineering/blue') }} jobs: - ci: + docker_build: strategy: fail-fast: false matrix: @@ -27,165 +27,71 @@ jobs: permissions: packages: write contents: read + env: + BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }} + BLUE_GITHUB_REPO: ${{ github.repository }} steps: - - name: Checkout repository + - + 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 }} + - + # 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: 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 - - - name: Set up Docker Buildx + - + name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - 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 }} - 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' + 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 - if: env.PUSH == 'true' - id: meta - uses: docker/metadata-action@v5.5.1 + # - + # 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 }}-${{ matrix.stage }} + + - if: github.event_name == 'push' + name: Build and push (non PR) + uses: docker/bake-action@v5.5.0 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 }} + workdir: .docker 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 - - - name: Log into registry - if: env.PUSH == 'true' - uses: docker/login-action@v3.3.0 + set: | + *.platform=linux/amd64 + *.cache-from=type=gha,scope=ci + *.cache-from=type=gha,scope=robot + *.cache-from=type=gha,scope=desktop + *.cache-from=type=gha,scope=desktop-nvidia + ci.cache-to=type=gha,mode=max,scope=ci + robot.cache-to=type=gha,mode=max,scope=robot + desktop.cache-to=type=gha,mode=max,scope=desktop + desktop-nvidia.cache-to=type=gha,mode=max,scope=desktop-nvidia + + - if: github.event_name == 'pull_request' + name: Build and push (PR) + uses: docker/bake-action@v5.5.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 }} + workdir: .docker + targets: | + ${{ matrix.stage }} + set: | + *.platform=linux/amd64 + *.cache-from=type=gha,scope=ci + *.cache-from=type=gha,scope=robot + *.cache-from=type=gha,scope=desktop + *.cache-from=type=gha,scope=desktop-nvidia + *.cache-to= diff --git a/.gitignore b/.gitignore index eb28dd58..fce2ec85 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ mav.parm mav.tlog mav.tlog.raw logs/ + +# Allow overrides in docker-bake +.docker/docker-bake.override.hcl From 4fb87d7769a8bd8f87a3d3573191ff9ad4e2eb02 Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Mon, 19 Aug 2024 15:22:04 -0700 Subject: [PATCH 06/19] Updated comments in Dockerfile --- .github/workflows/docker.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index bcbb2114..21ef264e 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -1,6 +1,7 @@ name: Docker on: + # Disable schedule for preliminary testing # schedule: # - cron: "0 17 * * 6" push: @@ -15,7 +16,7 @@ on: workflow_dispatch: env: - PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'apl-ocean-engineering/blue') }} + PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'Robotic-Decision-Making-Lab/blue') }} jobs: docker_build: @@ -54,6 +55,8 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + # tbd: not sure how to update this for buildx + # # - # name: Extract Docker metadata # if: env.PUSH == 'true' @@ -71,7 +74,6 @@ jobs: workdir: .docker push: ${{ env.PUSH }} set: | - *.platform=linux/amd64 *.cache-from=type=gha,scope=ci *.cache-from=type=gha,scope=robot *.cache-from=type=gha,scope=desktop @@ -81,6 +83,7 @@ jobs: desktop.cache-to=type=gha,mode=max,scope=desktop desktop-nvidia.cache-to=type=gha,mode=max,scope=desktop-nvidia + # 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.5.0 From 9b7be45fabd7014bfff9a2ac73c316943ef61209 Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Mon, 19 Aug 2024 16:44:52 -0700 Subject: [PATCH 07/19] Attempt to allow manual triggering of builds --- .github/workflows/docker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 21ef264e..54ff19ef 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -84,7 +84,7 @@ jobs: desktop-nvidia.cache-to=type=gha,mode=max,scope=desktop-nvidia # Pull request builds are not cached; and only built for AMD64 - - if: github.event_name == 'pull_request' + - if: (github.event_name == 'pull_request') || (workflow_dispath) name: Build and push (PR) uses: docker/bake-action@v5.5.0 with: From 6ab2769cd5e4d19c81128ef22c3be11eafafa698 Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Mon, 19 Aug 2024 16:46:10 -0700 Subject: [PATCH 08/19] Nope, that's not it. --- .github/workflows/docker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 54ff19ef..21ef264e 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -84,7 +84,7 @@ jobs: desktop-nvidia.cache-to=type=gha,mode=max,scope=desktop-nvidia # Pull request builds are not cached; and only built for AMD64 - - if: (github.event_name == 'pull_request') || (workflow_dispath) + - if: github.event_name == 'pull_request' name: Build and push (PR) uses: docker/bake-action@v5.5.0 with: From 028e3e6c1347fe1e5553cb191dae2a41ef223d0b Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Mon, 19 Aug 2024 17:56:25 -0700 Subject: [PATCH 09/19] Add preliminary label to all Docker images. --- .docker/docker-bake.hcl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.docker/docker-bake.hcl b/.docker/docker-bake.hcl index c4f3f8df..a3f9e8db 100644 --- a/.docker/docker-bake.hcl +++ b/.docker/docker-bake.hcl @@ -32,6 +32,9 @@ target "ci" { 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}:${BLUE_ROS_DISTRO}-ci", "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-robot", From 830f3da9bb55995e4ab2d17fd4c003f0fd812bbe Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Mon, 19 Aug 2024 21:16:41 -0700 Subject: [PATCH 10/19] Removed redundant libcppzmq-dev --- .docker/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 67e39b1d..85540dee 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -170,7 +170,6 @@ RUN wget https://packages.osrfoundation.org/gazebo.gpg -O /usr/share/keyrings/pk xterm \ rapidjson-dev \ libopencv-dev \ - cppzmq-dev \ && apt-get autoremove -y \ && apt-get clean -y \ && rm -rf /var/lib/apt/lists/* From e06a30c1a9dc0817584165b38210e5b7bf652caa Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Mon, 19 Aug 2024 22:34:44 -0700 Subject: [PATCH 11/19] Hack to lowercase repo name --- .github/workflows/docker.yaml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 21ef264e..e9e29f04 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -28,9 +28,6 @@ jobs: permissions: packages: write contents: read - env: - BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }} - BLUE_GITHUB_REPO: ${{ github.repository }} steps: - name: Checkout repository @@ -55,6 +52,11 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - id: lower-repo + name: Repository to lowercase + run: | + echo "repository=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT + # tbd: not sure how to update this for buildx # # - @@ -70,6 +72,9 @@ jobs: - 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.lower-repo.outputs.repository }} with: workdir: .docker push: ${{ env.PUSH }} @@ -87,6 +92,9 @@ jobs: - 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.lower-repo.outputs.repository }} with: workdir: .docker targets: | From 10d8dc7ade683cfff8363c26aebaf3f3e780a169 Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Wed, 21 Aug 2024 11:04:09 -0700 Subject: [PATCH 12/19] Re-activate the metadata-action, go back to stages in matrix. --- .docker/docker-bake.hcl | 4 ++++ .github/workflows/docker.yaml | 36 ++++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.docker/docker-bake.hcl b/.docker/docker-bake.hcl index a3f9e8db..34864353 100644 --- a/.docker/docker-bake.hcl +++ b/.docker/docker-bake.hcl @@ -16,6 +16,9 @@ group "default" { targets = ["ci", "robot", "desktop", "desktop-nvidia"] } +# In Github CI, populated by metadata-action Github action +target "docker-metadata-action" {} + # # All images can pull cache from the images published at Github # or local storage (within the Buildkit image) @@ -23,6 +26,7 @@ group "default" { # ... and push cache to local storage # target "ci" { + inherits = ["docker-metadata-action"] dockerfile = ".docker/Dockerfile" target = "ci" context = ".." diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index e9e29f04..968b1c2e 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -24,6 +24,7 @@ jobs: fail-fast: false matrix: ROS_DISTRO: [rolling] + stage: ["ci", "robot", "desktop", "desktop-nvidia"] runs-on: ubuntu-latest permissions: packages: write @@ -59,19 +60,28 @@ jobs: # tbd: not sure how to update this for buildx # - # - - # 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 }}-${{ matrix.stage }} + # metadata-action can be used with bake: + # https://github.com/docker/metadata-action?tab=readme-ov-file#bake-definition + # + # But not quite sure how to handle multiple targets given we don't iterate + # through the stages at this level (it happens within bake) + # + - + 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 }}-${{ matrix.stage }} - if: github.event_name == 'push' name: Build and push (non PR) uses: docker/bake-action@v5.5.0 + files: | + .docker/docker-bake.hcl + ${{ steps.meta.outputs.bake-file }} env: BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }} BLUE_GITHUB_REPO: ${{ steps.lower-repo.outputs.repository }} @@ -83,15 +93,15 @@ jobs: *.cache-from=type=gha,scope=robot *.cache-from=type=gha,scope=desktop *.cache-from=type=gha,scope=desktop-nvidia - ci.cache-to=type=gha,mode=max,scope=ci - robot.cache-to=type=gha,mode=max,scope=robot - desktop.cache-to=type=gha,mode=max,scope=desktop - desktop-nvidia.cache-to=type=gha,mode=max,scope=desktop-nvidia + ${{ matrix.stage }}.cache-to=type=gha,mode=max,scope=${{ matrix.stage }} # 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.5.0 + files: | + .docker/docker-bake.hcl + ${{ steps.meta.outputs.bake-file }} env: BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }} BLUE_GITHUB_REPO: ${{ steps.lower-repo.outputs.repository }} From 3b3538d00b1ed0f9fb8f4b5680bcd8f875cf09f6 Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Wed, 21 Aug 2024 11:05:22 -0700 Subject: [PATCH 13/19] Add comment on lowercasing. --- .github/workflows/docker.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index e9e29f04..09981e06 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -52,6 +52,10 @@ jobs: 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: lower-repo name: Repository to lowercase run: | From e873d092f873abc508d6a4f17fd39fba01c19de8 Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Wed, 21 Aug 2024 11:14:22 -0700 Subject: [PATCH 14/19] Place files config at correct level. --- .github/workflows/docker.yaml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 968b1c2e..3c7fe489 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -79,14 +79,16 @@ jobs: - if: github.event_name == 'push' name: Build and push (non PR) uses: docker/bake-action@v5.5.0 - files: | - .docker/docker-bake.hcl - ${{ steps.meta.outputs.bake-file }} env: BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }} BLUE_GITHUB_REPO: ${{ steps.lower-repo.outputs.repository }} with: workdir: .docker + files: | + ./docker-bake.hcl + ${{ steps.meta.outputs.bake-file }} + targets: | + ${{ matrix.stage }} push: ${{ env.PUSH }} set: | *.cache-from=type=gha,scope=ci @@ -99,14 +101,14 @@ jobs: - if: github.event_name == 'pull_request' name: Build and push (PR) uses: docker/bake-action@v5.5.0 - files: | - .docker/docker-bake.hcl - ${{ steps.meta.outputs.bake-file }} env: BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }} BLUE_GITHUB_REPO: ${{ steps.lower-repo.outputs.repository }} with: workdir: .docker + files: | + ./docker-bake.hcl + ${{ steps.meta.outputs.bake-file }} targets: | ${{ matrix.stage }} set: | From 5c8197138710970798c72bd2be4f90206dd99abd Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Wed, 21 Aug 2024 11:04:09 -0700 Subject: [PATCH 15/19] Re-activate the metadata-action, go back to stages in matrix. --- .docker/docker-bake.hcl | 4 ++++ .github/workflows/docker.yaml | 36 ++++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.docker/docker-bake.hcl b/.docker/docker-bake.hcl index a3f9e8db..34864353 100644 --- a/.docker/docker-bake.hcl +++ b/.docker/docker-bake.hcl @@ -16,6 +16,9 @@ group "default" { targets = ["ci", "robot", "desktop", "desktop-nvidia"] } +# In Github CI, populated by metadata-action Github action +target "docker-metadata-action" {} + # # All images can pull cache from the images published at Github # or local storage (within the Buildkit image) @@ -23,6 +26,7 @@ group "default" { # ... and push cache to local storage # target "ci" { + inherits = ["docker-metadata-action"] dockerfile = ".docker/Dockerfile" target = "ci" context = ".." diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 09981e06..8bcf6375 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -24,6 +24,7 @@ jobs: fail-fast: false matrix: ROS_DISTRO: [rolling] + stage: ["ci", "robot", "desktop", "desktop-nvidia"] runs-on: ubuntu-latest permissions: packages: write @@ -63,19 +64,28 @@ jobs: # tbd: not sure how to update this for buildx # - # - - # 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 }}-${{ matrix.stage }} + # metadata-action can be used with bake: + # https://github.com/docker/metadata-action?tab=readme-ov-file#bake-definition + # + # But not quite sure how to handle multiple targets given we don't iterate + # through the stages at this level (it happens within bake) + # + - + 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 }}-${{ matrix.stage }} - if: github.event_name == 'push' name: Build and push (non PR) uses: docker/bake-action@v5.5.0 + files: | + .docker/docker-bake.hcl + ${{ steps.meta.outputs.bake-file }} env: BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }} BLUE_GITHUB_REPO: ${{ steps.lower-repo.outputs.repository }} @@ -87,15 +97,15 @@ jobs: *.cache-from=type=gha,scope=robot *.cache-from=type=gha,scope=desktop *.cache-from=type=gha,scope=desktop-nvidia - ci.cache-to=type=gha,mode=max,scope=ci - robot.cache-to=type=gha,mode=max,scope=robot - desktop.cache-to=type=gha,mode=max,scope=desktop - desktop-nvidia.cache-to=type=gha,mode=max,scope=desktop-nvidia + ${{ matrix.stage }}.cache-to=type=gha,mode=max,scope=${{ matrix.stage }} # 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.5.0 + files: | + .docker/docker-bake.hcl + ${{ steps.meta.outputs.bake-file }} env: BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }} BLUE_GITHUB_REPO: ${{ steps.lower-repo.outputs.repository }} From df4809ad6422c27d99ee329a88916521b87e0a77 Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Wed, 21 Aug 2024 11:14:22 -0700 Subject: [PATCH 16/19] Place files config at correct level. --- .github/workflows/docker.yaml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 8bcf6375..f803f13f 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -83,14 +83,16 @@ jobs: - if: github.event_name == 'push' name: Build and push (non PR) uses: docker/bake-action@v5.5.0 - files: | - .docker/docker-bake.hcl - ${{ steps.meta.outputs.bake-file }} env: BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }} BLUE_GITHUB_REPO: ${{ steps.lower-repo.outputs.repository }} with: workdir: .docker + files: | + ./docker-bake.hcl + ${{ steps.meta.outputs.bake-file }} + targets: | + ${{ matrix.stage }} push: ${{ env.PUSH }} set: | *.cache-from=type=gha,scope=ci @@ -103,14 +105,14 @@ jobs: - if: github.event_name == 'pull_request' name: Build and push (PR) uses: docker/bake-action@v5.5.0 - files: | - .docker/docker-bake.hcl - ${{ steps.meta.outputs.bake-file }} env: BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }} BLUE_GITHUB_REPO: ${{ steps.lower-repo.outputs.repository }} with: workdir: .docker + files: | + ./docker-bake.hcl + ${{ steps.meta.outputs.bake-file }} targets: | ${{ matrix.stage }} set: | From 5ffee9d5d780f3ee3b1d8900688a973a5845d9c0 Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Wed, 21 Aug 2024 16:56:48 -0700 Subject: [PATCH 17/19] Switch to registry cache for CI --- .docker/docker-bake.hcl | 26 +++++++----- .github/workflows/docker.yaml | 74 ++++++++++++++++++++++------------- 2 files changed, 62 insertions(+), 38 deletions(-) diff --git a/.docker/docker-bake.hcl b/.docker/docker-bake.hcl index 34864353..6c104206 100644 --- a/.docker/docker-bake.hcl +++ b/.docker/docker-bake.hcl @@ -16,8 +16,14 @@ group "default" { targets = ["ci", "robot", "desktop", "desktop-nvidia"] } -# In Github CI, populated by metadata-action Github action -target "docker-metadata-action" {} +# 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 @@ -26,7 +32,7 @@ target "docker-metadata-action" {} # ... and push cache to local storage # target "ci" { - inherits = ["docker-metadata-action"] + inherits = ["docker-metadata-action-ci"] dockerfile = ".docker/Dockerfile" target = "ci" context = ".." @@ -40,10 +46,10 @@ target "ci" { "org.opencontainers.image.source" = "https://github.com/${BLUE_GITHUB_REPO}" } cache_from =[ - "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-ci", - "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-robot", - "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop", - "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop-nvidia", + "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 = [ @@ -53,7 +59,7 @@ target "ci" { } target "robot" { - inherits = [ "ci" ] + inherits = [ "ci", "docker-metadata-action-robot" ] target = "robot" tags = [ "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-robot" @@ -64,7 +70,7 @@ target "robot" { } target "desktop" { - inherits = [ "ci" ] + inherits = [ "ci", "docker-metadata-action-desktop" ] target = "desktop" tags = [ "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop" @@ -77,7 +83,7 @@ target "desktop" { } target "desktop-nvidia" { - inherits = [ "desktop" ] + inherits = [ "desktop", "docker-metadata-action-desktop-nvidia" ] target = "desktop-nvidia" tags = [ "ghcr.io/${BLUE_GITHUB_REPO}:${BLUE_ROS_DISTRO}-desktop-nvidia" diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index f803f13f..cdbe837a 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -24,14 +24,13 @@ jobs: fail-fast: false matrix: ROS_DISTRO: [rolling] - stage: ["ci", "robot", "desktop", "desktop-nvidia"] runs-on: ubuntu-latest permissions: packages: write contents: read steps: - - name: Checkout repository + name: Checkout uses: actions/checkout@v4 - @@ -62,23 +61,50 @@ jobs: run: | echo "repository=${GITHUB_REPOSITORY@L}" >> $GITHUB_OUTPUT - # tbd: not sure how to update this for buildx - # - # metadata-action can be used with bake: - # https://github.com/docker/metadata-action?tab=readme-ov-file#bake-definition - # - # But not quite sure how to handle multiple targets given we don't iterate - # through the stages at this level (it happens within bake) - # + # 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: 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 }}-${{ matrix.stage }} + type=raw,value=${{ matrix.ROS_DISTRO }}-desktop-nvidia - if: github.event_name == 'push' name: Build and push (non PR) @@ -90,16 +116,14 @@ jobs: workdir: .docker files: | ./docker-bake.hcl - ${{ steps.meta.outputs.bake-file }} - targets: | - ${{ matrix.stage }} + ${{ 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=gha,scope=ci - *.cache-from=type=gha,scope=robot - *.cache-from=type=gha,scope=desktop - *.cache-from=type=gha,scope=desktop-nvidia - ${{ matrix.stage }}.cache-to=type=gha,mode=max,scope=${{ matrix.stage }} + *.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 - if: github.event_name == 'pull_request' @@ -112,13 +136,7 @@ jobs: workdir: .docker files: | ./docker-bake.hcl - ${{ steps.meta.outputs.bake-file }} - targets: | - ${{ matrix.stage }} set: | *.platform=linux/amd64 - *.cache-from=type=gha,scope=ci - *.cache-from=type=gha,scope=robot - *.cache-from=type=gha,scope=desktop - *.cache-from=type=gha,scope=desktop-nvidia + *.cache-from=type=registry,ref=ghcr.io/${{ github.repository }}:cache-${{ matrix.ROS_DISTRO }} *.cache-to= From 042584f18f4d00e3cc3e015300911b2c8041b489 Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Wed, 21 Aug 2024 22:37:22 -0700 Subject: [PATCH 18/19] Removed stage from matrix --- .github/workflows/docker.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index f7746cdb..cdbe837a 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -24,7 +24,6 @@ jobs: fail-fast: false matrix: ROS_DISTRO: [rolling] - stage: ["ci", "robot", "desktop", "desktop-nvidia"] runs-on: ubuntu-latest permissions: packages: write From 2032dd18e6f9c109cca9684e0587de8a62326a78 Mon Sep 17 00:00:00 2001 From: Aaron Marburg Date: Thu, 22 Aug 2024 12:26:42 -0700 Subject: [PATCH 19/19] Update repo URL, fix list formatting. --- .github/workflows/docker.yaml | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 81c01dbb..1d601fa8 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -16,7 +16,7 @@ on: workflow_dispatch: env: - PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'apl-ocean-engineering/blue') }} + PUSH: ${{ (github.event_name != 'pull_request') && (github.repository == 'Robotic-Decision-Making-Lab/blue') }} jobs: docker_build: @@ -29,22 +29,18 @@ jobs: packages: write contents: read steps: - - - name: Checkout + - name: Checkout uses: actions/checkout@v4 - - - # Add support for more platforms with QEMU (optional) + - # 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 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - - if: env.PUSH == 'true' + - if: env.PUSH == 'true' name: Log into registry uses: docker/login-action@v3.3.0 with: @@ -56,14 +52,13 @@ jobs: # This shell ... er, hack, creates a local variable containing # a down-cased version of $GITHUB_REPOSITORY # - - id: lower-repo + - 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" + - name: Set Docker metadata for "ci" if: env.PUSH == 'true' id: meta-ci uses: docker/metadata-action@v5.5.1 @@ -73,8 +68,7 @@ jobs: tags: | type=raw,value=${{ matrix.ROS_DISTRO }}-ci - - - name: Set Docker metadata for "robot" + - name: Set Docker metadata for "robot" if: env.PUSH == 'true' id: meta-robot uses: docker/metadata-action@v5.5.1 @@ -84,8 +78,7 @@ jobs: tags: | type=raw,value=${{ matrix.ROS_DISTRO }}-robot - - - name: Set Docker metadata for "desktop" + - name: Set Docker metadata for "desktop" if: env.PUSH == 'true' id: meta-desktop uses: docker/metadata-action@v5.5.1 @@ -95,8 +88,7 @@ jobs: tags: | type=raw,value=${{ matrix.ROS_DISTRO }}-desktop - - - name: Set Docker metadata for "desktop-nvidia" + - name: Set Docker metadata for "desktop-nvidia" if: env.PUSH == 'true' id: meta-desktop-nvidia uses: docker/metadata-action@v5.5.1 @@ -111,7 +103,7 @@ jobs: uses: docker/bake-action@v5.5.0 env: BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }} - BLUE_GITHUB_REPO: ${{ steps.lower-repo.outputs.repository }} + BLUE_GITHUB_REPO: ${{ steps.lowercase-repo.outputs.repository }} with: workdir: .docker files: | @@ -131,7 +123,7 @@ jobs: uses: docker/bake-action@v5.5.0 env: BLUE_ROS_DISTRO: ${{ matrix.ROS_DISTRO }} - BLUE_GITHUB_REPO: ${{ steps.lower-repo.outputs.repository }} + BLUE_GITHUB_REPO: ${{ steps.lowercase-repo.outputs.repository }} with: workdir: .docker files: |