From 0c31d08a8163ae948352cab92f3767f29f71e2a8 Mon Sep 17 00:00:00 2001 From: "Sean T. Allen" Date: Wed, 30 Aug 2023 13:16:08 +0000 Subject: [PATCH] Push images to GitHub Container Registry in addition to DockerHub --- .../build-docker-images-on-release.bash | 22 ++++++++- .../release/build-latest-docker-images.bash | 11 ++++- .github/workflows/latest-docker-image.yml | 47 ++++++++++++++++++- .github/workflows/release.yml | 9 +++- 4 files changed, 84 insertions(+), 5 deletions(-) diff --git a/.ci-scripts/release/build-docker-images-on-release.bash b/.ci-scripts/release/build-docker-images-on-release.bash index 8a4c193..80044a9 100644 --- a/.ci-scripts/release/build-docker-images-on-release.bash +++ b/.ci-scripts/release/build-docker-images-on-release.bash @@ -52,12 +52,30 @@ set -o nounset # Version: "1.0.0" VERSION="${GITHUB_REF/refs\/tags\//}" +## DockerHub + +NAME="${GITHUB_REPOSITORY}" + +# Build and push :VERSION tag e.g. ponylang/ponyup:0.32.1 +DOCKER_TAG="${NAME}:${VERSION}" +docker build --pull -t "${DOCKER_TAG}" . +docker push "${DOCKER_TAG}" + +# Build and push "release" tag e.g. ponylang/ponyup:release +DOCKER_TAG="${NAME}:release" +docker build --pull -t "${DOCKER_TAG}" . +docker push "${DOCKER_TAG}" + +## GitHub Container Registry + +NAME="ghcr.io/${GITHUB_REPOSITORY}" + # Build and push :VERSION tag e.g. ponylang/ponyup:0.32.1 -DOCKER_TAG=${GITHUB_REPOSITORY}:"${VERSION}" +DOCKER_TAG="${NAME}:${VERSION}" docker build --pull -t "${DOCKER_TAG}" . docker push "${DOCKER_TAG}" # Build and push "release" tag e.g. ponylang/ponyup:release -DOCKER_TAG=${GITHUB_REPOSITORY}:release +DOCKER_TAG="${NAME}:release" docker build --pull -t "${DOCKER_TAG}" . docker push "${DOCKER_TAG}" diff --git a/.ci-scripts/release/build-latest-docker-images.bash b/.ci-scripts/release/build-latest-docker-images.bash index 9c3f1a2..911e009 100644 --- a/.ci-scripts/release/build-latest-docker-images.bash +++ b/.ci-scripts/release/build-latest-docker-images.bash @@ -33,7 +33,16 @@ fi # allow above so we can display nice error messages for expected unset variables set -o nounset +## DockerHub + +# Build and push "latest" tag e.g. ponylang/ponyup:latest +DOCKER_TAG="${GITHUB_REPOSITORY}:latest" +docker build --pull -t "${DOCKER_TAG}" . +docker push "${DOCKER_TAG}" + +## GitHub Container Registry + # Build and push "latest" tag e.g. ponylang/ponyup:latest -DOCKER_TAG=${GITHUB_REPOSITORY}:latest +DOCKER_TAG="ghcr.io/${GITHUB_REPOSITORY}:latest" docker build --pull -t "${DOCKER_TAG}" . docker push "${DOCKER_TAG}" diff --git a/.github/workflows/latest-docker-image.yml b/.github/workflows/latest-docker-image.yml index 0eeb4e4..f79ca3a 100644 --- a/.github/workflows/latest-docker-image.yml +++ b/.github/workflows/latest-docker-image.yml @@ -11,10 +11,55 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Docker login + - name: Login to DockerHub run: docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" env: DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + - name: Login to GitHub Container Registry + # v2.2.0 + uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push run: bash .ci-scripts/release/build-latest-docker-images.bash + - name: Send alert on failure + if: ${{ failure() }} + uses: zulip/github-actions-zulip/send-message@b62d5a0e48a4d984ea4fce5dd65ba691963d4db4 + with: + api-key: ${{ secrets.ZULIP_SCHEDULED_JOB_FAILURE_API_KEY }} + email: ${{ secrets.ZULIP_SCHEDULED_JOB_FAILURE_EMAIL }} + organization-url: 'https://ponylang.zulipchat.com/' + to: notifications + type: stream + topic: ${{ github.repository }} scheduled job failure + content: ${{ github.server_url}}/${{ github.repository }}/actions/runs/${{ github.run_id }} failed. + + prune-untagged-images: + needs: + - build-latest-docker-image + + name: Prune untagged images + runs-on: ubuntu-latest + steps: + - name: Prune + # v4.1.1 + uses: actions/delete-package-versions@0d39a63126868f5eefaa47169615edd3c0f61e20 + with: + package-name: 'ponydoc' + package-type: 'container' + min-versions-to-keep: 1 + delete-only-untagged-versions: 'true' + - name: Send alert on failure + if: ${{ failure() }} + uses: zulip/github-actions-zulip/send-message@b62d5a0e48a4d984ea4fce5dd65ba691963d4db4 + with: + api-key: ${{ secrets.ZULIP_SCHEDULED_JOB_FAILURE_API_KEY }} + email: ${{ secrets.ZULIP_SCHEDULED_JOB_FAILURE_EMAIL }} + organization-url: 'https://ponylang.zulipchat.com/' + to: notifications + type: stream + topic: ${{ github.repository }} scheduled job failure + content: ${{ github.server_url}}/${{ github.repository }}/actions/runs/${{ github.run_id }} failed. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b3e5799..358ef4c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,11 +23,18 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Docker login + - name: Login to DockerHub run: docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD" env: DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + - name: Login to GitHub Container Registry + # v2.2.0 + uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Build and push run: bash .ci-scripts/release/build-docker-images-on-release.bash