From 282b038713fd99bfd12e127b95ec8467f409b0ac Mon Sep 17 00:00:00 2001 From: Sven Pfleiderer Date: Wed, 26 May 2021 10:41:53 -0700 Subject: [PATCH 1/8] Update push docker container to support container registry Also simplify the existing workflow by replacing shell code with actions --- ci/docker-publish.yml | 69 ++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/ci/docker-publish.yml b/ci/docker-publish.yml index ba69744..6152fde 100644 --- a/ci/docker-publish.yml +++ b/ci/docker-publish.yml @@ -2,20 +2,22 @@ name: Docker on: push: - # Publish `$default-branch` as Docker `latest` image. - branches: - - $default-branch - + branches: [ $default-branch ] # Publish `v1.2.3` tags as releases. - tags: - - v* + tags: [ 'v*.*.*' ] + pull_request_target: + branches: [ $default-branch ] # Run tests for any PRs. pull_request: env: - # TODO: Change variable to your image's name. - IMAGE_NAME: image + # TODO: Creates container named ACCOUNT/REPO + # Append /IMAGE-NAME to create a container named ACCOUNT/REPO/IMAGE-NAME + IMAGE_NAME: ${{ github.repository }} + + # Registry. Use docker.io for DockerHub + REGISTRY: ghcr.io jobs: # Run tests. @@ -49,32 +51,31 @@ jobs: packages: write steps: - - uses: actions/checkout@v2 + - name: Checkout repository + uses: actions/checkout@v2 - - name: Build image - run: docker build . --file Dockerfile --tag $IMAGE_NAME + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Log into registry - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} - - name: Push image - run: | - IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - - # Strip git ref prefix from version - VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - - # Strip "v" prefix from tag name - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') - - # Use Docker `latest` tag convention - [ "$VERSION" == "$default-branch" ] && VERSION=latest - - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + # Don't push on pull requests + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} From b574e6db5060fafbf91fafb5c1e2e824fe5e11db Mon Sep 17 00:00:00 2001 From: Sven Pfleiderer Date: Wed, 26 May 2021 10:55:50 -0700 Subject: [PATCH 2/8] Add notice about third party actions --- ci/docker-publish.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ci/docker-publish.yml b/ci/docker-publish.yml index 6152fde..63b02f2 100644 --- a/ci/docker-publish.yml +++ b/ci/docker-publish.yml @@ -1,5 +1,10 @@ name: Docker +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + on: push: branches: [ $default-branch ] From 41a66c656e20c398aa7143b649d3678dae503afc Mon Sep 17 00:00:00 2001 From: Sven Pfleiderer Date: Wed, 26 May 2021 13:46:54 -0700 Subject: [PATCH 3/8] Use git shas rather than version tags --- ci/docker-publish.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/docker-publish.yml b/ci/docker-publish.yml index 63b02f2..26a5f89 100644 --- a/ci/docker-publish.yml +++ b/ci/docker-publish.yml @@ -60,7 +60,7 @@ jobs: uses: actions/checkout@v2 - name: Log into registry ${{ env.REGISTRY }} - uses: docker/login-action@v1 + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c with: registry: ${{ env.REGISTRY }} username: ${{ github.repository_owner }} @@ -68,7 +68,7 @@ jobs: - name: Extract Docker metadata id: meta - uses: docker/metadata-action@v3 + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | @@ -77,7 +77,7 @@ jobs: type=semver,pattern={{version}} - name: Build and push Docker image - uses: docker/build-push-action@v2 + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: context: . # Don't push on pull requests From aa30f1448e6f181d695a784d284dbeaefc12a208 Mon Sep 17 00:00:00 2001 From: Sven Pfleiderer Date: Wed, 26 May 2021 14:07:29 -0700 Subject: [PATCH 4/8] Update ci/docker-publish.yml Co-authored-by: Bryan Clark --- ci/docker-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/docker-publish.yml b/ci/docker-publish.yml index 26a5f89..d2672ab 100644 --- a/ci/docker-publish.yml +++ b/ci/docker-publish.yml @@ -63,7 +63,7 @@ jobs: uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c with: registry: ${{ env.REGISTRY }} - username: ${{ github.repository_owner }} + username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract Docker metadata From 6fe53a9ebd963520a1da2b470d71380c14c284fb Mon Sep 17 00:00:00 2001 From: Sven Pfleiderer Date: Wed, 26 May 2021 15:03:41 -0700 Subject: [PATCH 5/8] Remove context configuration since it's already the default --- ci/docker-publish.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/docker-publish.yml b/ci/docker-publish.yml index 26a5f89..c820f91 100644 --- a/ci/docker-publish.yml +++ b/ci/docker-publish.yml @@ -79,7 +79,6 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: - context: . # Don't push on pull requests push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} From 9317366c912201db28a76971bf16ffcb807f2087 Mon Sep 17 00:00:00 2001 From: Sven Pfleiderer Date: Wed, 2 Jun 2021 14:21:03 -0700 Subject: [PATCH 6/8] Remove docker tags section to simplify configuration --- ci/docker-publish.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ci/docker-publish.yml b/ci/docker-publish.yml index e676dea..3a5a084 100644 --- a/ci/docker-publish.yml +++ b/ci/docker-publish.yml @@ -71,10 +71,6 @@ jobs: uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - name: Build and push Docker image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc From 9d73235e0373a25865567ea98cba64564503fe68 Mon Sep 17 00:00:00 2001 From: Sven Pfleiderer Date: Wed, 2 Jun 2021 15:41:23 -0700 Subject: [PATCH 7/8] Remove pull request condition --- ci/docker-publish.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/ci/docker-publish.yml b/ci/docker-publish.yml index 3a5a084..84c07c5 100644 --- a/ci/docker-publish.yml +++ b/ci/docker-publish.yml @@ -75,7 +75,5 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: - # Don't push on pull requests - push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} From 7b6d03675b1fac8ce90a9273c862548d5324ab24 Mon Sep 17 00:00:00 2001 From: Sven Pfleiderer Date: Wed, 2 Jun 2021 15:58:44 -0700 Subject: [PATCH 8/8] Revert "Remove pull request condition" This reverts commit 9d73235e0373a25865567ea98cba64564503fe68. --- ci/docker-publish.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/docker-publish.yml b/ci/docker-publish.yml index 84c07c5..3a5a084 100644 --- a/ci/docker-publish.yml +++ b/ci/docker-publish.yml @@ -75,5 +75,7 @@ jobs: - name: Build and push Docker image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: + # Don't push on pull requests + push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}