From 11a686f1c13df1b91129937feae74e89379c78de Mon Sep 17 00:00:00 2001 From: Erik Holum Date: Mon, 26 Aug 2024 20:49:30 -0500 Subject: [PATCH 1/5] Add additional target for pushing images to container registries (issue #193) --- Earthfile | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Earthfile b/Earthfile index a20d469a..64f2b809 100644 --- a/Earthfile +++ b/Earthfile @@ -257,7 +257,7 @@ build-testing: image: FROM +rosdep ARG VCS_REF - ARG tag='latest' + ARG VERSION="latest" # Specify the docker image metadata LABEL org.label-schema.schema-version="1.0" @@ -276,4 +276,13 @@ image: COPY docker/entrypoint.sh /ros_entrypoint.sh ENTRYPOINT ["/ros_entrypoint.sh"] CMD ["bash"] - SAVE IMAGE --push osrf/space-ros:latest osrf/space-ros:$tag + SAVE IMAGE osrf/space-ros:${VERSION} + +# Target for prepping image(s) to be pushed to remote registries. +push-image: + FROM +image + + # This can be overridden with a blank string to prevent pushing to the registry. + ARG LATEST="osrf/space-ros:latest" + ARG TAG + SAVE IMAGE --push ${LATEST} ${TAG} From f44c6532c277ebfacdacd75c4285e4ee047baf48 Mon Sep 17 00:00:00 2001 From: Erik Holum Date: Mon, 26 Aug 2024 20:52:02 -0500 Subject: [PATCH 2/5] Modify CI builds to push/cache branch images to GHCR for testing (issue #193) --- .github/workflows/earthly-build.yaml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/earthly-build.yaml b/.github/workflows/earthly-build.yaml index bcc57d8a..26669a07 100644 --- a/.github/workflows/earthly-build.yaml +++ b/.github/workflows/earthly-build.yaml @@ -38,14 +38,21 @@ jobs: run: | sudo wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly sudo chmod 755 /usr/local/bin/earthly + # TODO: Set cache source to main before merging - name: Build spaceros image run: | earthly --ci --output +sources - earthly --ci +image - - name: Push spaceros image + earthly --ci --remote-cache=ghcr.io/space-ros/space-ros:push-main-image +image + - name: Push tagged spaceros images to Dockerhub env: DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_RW_TOKEN }} if: ${{ github.ref_type == 'tag' }} run: | echo $DOCKER_HUB_TOKEN | docker login --username osrfbot --password-stdin - earthly --ci --push +image --tag=${{ github.ref_name }} + earthly --ci --push +push-image --TAG="osrf/space-ros:${{ github.ref_name }}" --LATEST="osrf/space-ros:latest" + # TODO: Set branch names to main before merging + - name: Push the main spaceros image to GHCR + if: ${{ github.ref_name == '212/merge' }} + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + earthly --ci --push +push-image --TAGS="ghcr.io/space-ros/space-ros:push-main-image" --LATEST="" From 5e4b88cdd550d7c47aa5260f074d3dafc3da3dcc Mon Sep 17 00:00:00 2001 From: Erik Holum Date: Mon, 26 Aug 2024 20:52:44 -0500 Subject: [PATCH 3/5] Save locally built images with the branch name, if available (issue #193) --- .github/workflows/earthly-build.yaml | 2 +- build.sh | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/earthly-build.yaml b/.github/workflows/earthly-build.yaml index 26669a07..3130ab85 100644 --- a/.github/workflows/earthly-build.yaml +++ b/.github/workflows/earthly-build.yaml @@ -55,4 +55,4 @@ jobs: if: ${{ github.ref_name == '212/merge' }} run: | echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - earthly --ci --push +push-image --TAGS="ghcr.io/space-ros/space-ros:push-main-image" --LATEST="" + earthly --ci --push +push-image --TAG="ghcr.io/space-ros/space-ros:push-main-image" --LATEST="" diff --git a/build.sh b/build.sh index fa877b1d..e0f67733 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash VCS_REF="$(git rev-parse HEAD)" -VERSION=preview +VERSION="$(git rev-parse --abbrev-ref HEAD)" # Exit script with failure if build fails set -eo pipefail @@ -13,7 +13,8 @@ echo "" rm -rf src earthly +sources earthly +image \ - --VCS_REF="$VCS_REF" + --VCS_REF="${VCS_REF}" \ + --VERSION="${VERSION}" echo "" echo "##### Done! #####" From 10320d53cf2d7be66a168ac97a4b655e56f83165 Mon Sep 17 00:00:00 2001 From: Erik Holum Date: Thu, 12 Sep 2024 09:58:44 -0400 Subject: [PATCH 4/5] Use actions to login to GHCR (issue #193) --- .github/workflows/earthly-build.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/earthly-build.yaml b/.github/workflows/earthly-build.yaml index 3130ab85..3d1f18a2 100644 --- a/.github/workflows/earthly-build.yaml +++ b/.github/workflows/earthly-build.yaml @@ -34,6 +34,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + - name: Login to ghcr + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Set up earthly run: | sudo wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly @@ -54,5 +60,4 @@ jobs: - name: Push the main spaceros image to GHCR if: ${{ github.ref_name == '212/merge' }} run: | - echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin earthly --ci --push +push-image --TAG="ghcr.io/space-ros/space-ros:push-main-image" --LATEST="" From ea160e4ec2ecf606ca8835d76e50310f61322343 Mon Sep 17 00:00:00 2001 From: Erik Holum Date: Thu, 12 Sep 2024 10:46:34 -0400 Subject: [PATCH 5/5] Reset target branch to main and do not cache for now (issue #193) --- .github/workflows/earthly-build.yaml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/earthly-build.yaml b/.github/workflows/earthly-build.yaml index 3d1f18a2..ececd511 100644 --- a/.github/workflows/earthly-build.yaml +++ b/.github/workflows/earthly-build.yaml @@ -44,11 +44,10 @@ jobs: run: | sudo wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly sudo chmod 755 /usr/local/bin/earthly - # TODO: Set cache source to main before merging - name: Build spaceros image run: | earthly --ci --output +sources - earthly --ci --remote-cache=ghcr.io/space-ros/space-ros:push-main-image +image + earthly --ci +image - name: Push tagged spaceros images to Dockerhub env: DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_RW_TOKEN }} @@ -56,8 +55,7 @@ jobs: run: | echo $DOCKER_HUB_TOKEN | docker login --username osrfbot --password-stdin earthly --ci --push +push-image --TAG="osrf/space-ros:${{ github.ref_name }}" --LATEST="osrf/space-ros:latest" - # TODO: Set branch names to main before merging - name: Push the main spaceros image to GHCR - if: ${{ github.ref_name == '212/merge' }} + if: ${{ github.ref_name == 'main' }} run: | - earthly --ci --push +push-image --TAG="ghcr.io/space-ros/space-ros:push-main-image" --LATEST="" + earthly --ci --push +push-image --TAG="ghcr.io/space-ros/space-ros:main" --LATEST=""