From 1fbd80e28fe4140c326a089c27e990bab5bd3076 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Fri, 2 Dec 2022 22:59:51 -0500 Subject: [PATCH 1/5] Workflow to retag docker images with CalVer string More human readable Calendar Version (CalVer) tags for docker images published on the docker registry! When there is a new tag made on the git repo, this Continuous Integration workflow will pull down the built docker image, tag it with a string in YYYY.MM.DD format, and push things back to the docker registry. Modified from https://github.com/pangeo-data/pangeo-docker-images/blob/2022.12.01/.github/workflows/Publish.yml --- .github/workflows/README.md | 1 + .github/workflows/retag.yml | 58 +++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 .github/workflows/retag.yml diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 2b74c94..9cf40d3 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -3,5 +3,6 @@ - binder.yaml - Adds a Binder badge to Pull Requests that are newly opened - build.yaml - Build and push docker container images to a docker registry - conda-lock-command.yml - Refresh conda-lock files by writing `/condalock` in a Pull Request comment +- retag.yml - Republish docker images originally tagged with a short hash using a new CalVer string - slash-command-dispatch.yml - ChatOps that looks for slash commands in Pull Requests to trigger automated scripts - test.yaml - Test building docker container images in a Pull Request diff --git a/.github/workflows/retag.yml b/.github/workflows/retag.yml new file mode 100644 index 0000000..c3993fc --- /dev/null +++ b/.github/workflows/retag.yml @@ -0,0 +1,58 @@ +# Re-tag staging SHA-tagged image with git tag and 'latest' +# tags can be anything, but typically calver string (2022.12.02) +name: Retag +on: + push: + tags: + - '*' + +env: + GITHUB_SHA: ${{ github.sha }} + GITHUB_REF: ${{ github.ref }} + +permissions: # added using https://github.com/step-security/secure-workflows + contents: read + +jobs: + retag-using-calver: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + # https://github.com/actions/runner-images/issues/2840#issuecomment-790492173 + - name: Free up disk space + run: | + sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc + df -h + + - name: Set Job Environment Variables + run: | + SHA12="${GITHUB_SHA::12}" + TAG="${GITHUB_REF##*/}" + echo "SHA12=${SHA12}" >> $GITHUB_ENV + echo "TAG=${TAG}" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Quay.io + uses: docker/login-action@v2 + with: + registry: quay.io + username: ${{ secrets.QUAY_USERNAME }} + password: ${{ secrets.QUAY_PASSWORD }} + + - name: Pull Image for Corresponding GitHub Commit + run: | + docker pull quay.io/cryointhecloud/cryo-hub-image:${SHA12} + + - name: Retag Images + run: | + docker tag cryointhecloud/cryo-hub-image:${SHA12} quay.io/cryointhecloud/cryo-hub-image:latest + docker tag cryointhecloud/cryo-hub-image:${SHA12} quay.io/cryointhecloud/cryo-hub-image:${TAG} + + - name: Push Tags To Quay.io + run: | + docker push quay.io/cryointhecloud/cryo-hub-image:latest + docker push quay.io/cryointhecloud/cryo-hub-image:${TAG} From e35c33d2393607b61311fa5786c00029e2f09f92 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 4 Dec 2022 21:50:48 -0500 Subject: [PATCH 2/5] Remove free up disk space step The `cryo-hub-image` docker image is currently <2.0GB, so shouldn't be at the limits of GitHub Actions runner yet which is ~14GB. --- .github/workflows/retag.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/retag.yml b/.github/workflows/retag.yml index c3993fc..ea0bd3a 100644 --- a/.github/workflows/retag.yml +++ b/.github/workflows/retag.yml @@ -20,12 +20,6 @@ jobs: - name: Checkout Repository uses: actions/checkout@v3 - # https://github.com/actions/runner-images/issues/2840#issuecomment-790492173 - - name: Free up disk space - run: | - sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc - df -h - - name: Set Job Environment Variables run: | SHA12="${GITHUB_SHA::12}" From 5b276e7403c16929ca17e791fb754e3d35d75234 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 4 Dec 2022 21:51:54 -0500 Subject: [PATCH 3/5] Remove set up docker buildx step We're not building any docker images, just pulling, retagging and pushing, so shouldn't need `docker-buildx`. --- .github/workflows/retag.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/retag.yml b/.github/workflows/retag.yml index ea0bd3a..964cf57 100644 --- a/.github/workflows/retag.yml +++ b/.github/workflows/retag.yml @@ -27,9 +27,6 @@ jobs: echo "SHA12=${SHA12}" >> $GITHUB_ENV echo "TAG=${TAG}" >> $GITHUB_ENV - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Login to Quay.io uses: docker/login-action@v2 with: From 014714bb46d043940bc460e8674e54dce14d1644 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 4 Dec 2022 21:50:48 -0500 Subject: [PATCH 4/5] Revert "Remove free up disk space step" This reverts commit e35c33d2393607b61311fa5786c00029e2f09f92. --- .github/workflows/retag.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/retag.yml b/.github/workflows/retag.yml index 964cf57..724c875 100644 --- a/.github/workflows/retag.yml +++ b/.github/workflows/retag.yml @@ -20,6 +20,12 @@ jobs: - name: Checkout Repository uses: actions/checkout@v3 + # https://github.com/actions/runner-images/issues/2840#issuecomment-790492173 + - name: Free up disk space + run: | + sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc + df -h + - name: Set Job Environment Variables run: | SHA12="${GITHUB_SHA::12}" From f58fac1f5a53c1d0d07f6447e8a012f4d4c9341a Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 4 Dec 2022 22:51:18 -0500 Subject: [PATCH 5/5] Don't retag with latest label Co-Authored-By: Yuvi Panda --- .github/workflows/retag.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/retag.yml b/.github/workflows/retag.yml index 724c875..8ad5ff6 100644 --- a/.github/workflows/retag.yml +++ b/.github/workflows/retag.yml @@ -41,15 +41,10 @@ jobs: password: ${{ secrets.QUAY_PASSWORD }} - name: Pull Image for Corresponding GitHub Commit - run: | - docker pull quay.io/cryointhecloud/cryo-hub-image:${SHA12} + run: docker pull quay.io/cryointhecloud/cryo-hub-image:${SHA12} - name: Retag Images - run: | - docker tag cryointhecloud/cryo-hub-image:${SHA12} quay.io/cryointhecloud/cryo-hub-image:latest - docker tag cryointhecloud/cryo-hub-image:${SHA12} quay.io/cryointhecloud/cryo-hub-image:${TAG} + run: docker tag cryointhecloud/cryo-hub-image:${SHA12} quay.io/cryointhecloud/cryo-hub-image:${TAG} - name: Push Tags To Quay.io - run: | - docker push quay.io/cryointhecloud/cryo-hub-image:latest - docker push quay.io/cryointhecloud/cryo-hub-image:${TAG} + run: docker push quay.io/cryointhecloud/cryo-hub-image:${TAG}