From c40233475f5af6fba7d740cea54e926f1a183e52 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sat, 10 Apr 2021 20:37:42 +0100 Subject: [PATCH 1/6] Github workflow: Build and push docker image for amd64 arm64 --- .github/workflows/npm-publish.yml | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index d43a431f..0c95cf7a 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -5,6 +5,7 @@ name: Publish to npm on: push: + pull_request: tags: ["[0-9]+.[0-9]+.[0-9]+*"] jobs: @@ -20,3 +21,42 @@ jobs: - run: npm publish env: NODE_AUTH_TOKEN: ${{ secrets.npm_token }} + + publish-docker: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + # https://github.com/docker/login-action/tree/v1.8.0#docker-hub + - name: Login to Docker Hub + uses: docker/login-action@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # https://github.com/manics/action-major-minor-tag-calculator-test + - name: Get list of tags + id: gettags + # TODO: Move to org? + uses: manics/action-major-minor-tag-calculator@main + with: + githubToken: ${{ secrets.GITHUB_TOKEN }} + prefix: "manics/action-major-minor-tag-calculator-test:" + + - name: Display tags + run: echo "Docker tags ${{ steps.gettags.outputs.tags }}" + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: images/${{ matrix.image }} + platforms: linux/amd64,linux/arm64 + push: ${{ startsWith(github.ref, 'refs/tags/') }} + tags: ${{ join(fromJson(steps.gettags.outputs.tags)) }} From b2bcf1c36263eadb038af4c165ba258ed2d3405e Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sat, 10 Apr 2021 20:38:45 +0100 Subject: [PATCH 2/6] Rename publish workflow, always run --- .github/workflows/{npm-publish.yml => publish.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{npm-publish.yml => publish.yml} (97%) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/publish.yml similarity index 97% rename from .github/workflows/npm-publish.yml rename to .github/workflows/publish.yml index 0c95cf7a..9c802d42 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/publish.yml @@ -6,7 +6,6 @@ name: Publish to npm on: push: pull_request: - tags: ["[0-9]+.[0-9]+.[0-9]+*"] jobs: publish-npm: @@ -19,6 +18,7 @@ jobs: registry-url: https://registry.npmjs.org/ - run: npm ci - run: npm publish + if: startsWith(github.ref, 'refs/tags/') env: NODE_AUTH_TOKEN: ${{ secrets.npm_token }} From 89652997301829a690f16399815bbe3b5562fa63 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sat, 10 Apr 2021 20:57:06 +0100 Subject: [PATCH 3/6] Remove accidental context in docker build --- .github/workflows/publish.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9c802d42..7076a406 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -56,7 +56,6 @@ jobs: - name: Build and push uses: docker/build-push-action@v2 with: - context: images/${{ matrix.image }} platforms: linux/amd64,linux/arm64 push: ${{ startsWith(github.ref, 'refs/tags/') }} tags: ${{ join(fromJson(steps.gettags.outputs.tags)) }} From 37c79c1d894c60519bbbd22bf2632bc1339412f3 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sat, 10 Apr 2021 21:13:17 +0100 Subject: [PATCH 4/6] Update names and comments in publish.yml --- .github/workflows/publish.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7076a406..c2174034 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,13 +1,14 @@ -# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created -# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages - -name: Publish to npm +# Publish NPM package and Docker image +name: Release on: push: pull_request: jobs: + # Run tests using node, publish a package when tagged + # https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages + publish-npm: runs-on: ubuntu-20.04 steps: From 0e184cf1283187845e78d8be64a076b835cc5e61 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sat, 10 Apr 2021 22:24:19 +0100 Subject: [PATCH 5/6] Improve documention in publish.yml, fix docker image tag names --- .github/workflows/publish.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c2174034..069ee3ac 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -28,6 +28,11 @@ jobs: steps: - uses: actions/checkout@v2 + # Setup docker to build for multiple platforms (requires qemu). + # See: + # https://github.com/docker/build-push-action/tree/v2.3.0#usage + # https://github.com/docker/build-push-action/blob/v2.3.0/docs/advanced/multi-platform.md + - name: Set up QEMU uses: docker/setup-qemu-action@v1 @@ -43,13 +48,19 @@ jobs: password: ${{ secrets.DOCKERHUB_TOKEN }} # https://github.com/manics/action-major-minor-tag-calculator-test + # If this is a tagged build this will return additional parent tags. + # E.g. 1.2.3 is expanded to Docker tags + # [{prefix}:1.2.3, {prefix}:1.2, {prefix}:1, {prefix}:latest] unless + # this is a backported tag in which case the newer tags aren't updated. + # For branches this will return the branch name. + # If GITHUB_TOKEN isn't available (e.g. in PRs) returns no tags []. - name: Get list of tags id: gettags # TODO: Move to org? uses: manics/action-major-minor-tag-calculator@main with: githubToken: ${{ secrets.GITHUB_TOKEN }} - prefix: "manics/action-major-minor-tag-calculator-test:" + prefix: "jupyterhub/configurable-http-proxy:" - name: Display tags run: echo "Docker tags ${{ steps.gettags.outputs.tags }}" @@ -59,4 +70,6 @@ jobs: with: platforms: linux/amd64,linux/arm64 push: ${{ startsWith(github.ref, 'refs/tags/') }} + # tags parameter must be a string input so convert `gettags` JSON + # array into a comma separated list of tags tags: ${{ join(fromJson(steps.gettags.outputs.tags)) }} From 7e4a70b077793e9d23d03cfb566a428cf40bb52e Mon Sep 17 00:00:00 2001 From: Simon Li Date: Mon, 12 Apr 2021 12:11:06 +0100 Subject: [PATCH 6/6] Switch to https://github.com/jupyterhub/action-major-minor-tag-calculator --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 069ee3ac..1a7def95 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -47,7 +47,7 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - # https://github.com/manics/action-major-minor-tag-calculator-test + # https://github.com/jupyterhub/action-major-minor-tag-calculator # If this is a tagged build this will return additional parent tags. # E.g. 1.2.3 is expanded to Docker tags # [{prefix}:1.2.3, {prefix}:1.2, {prefix}:1, {prefix}:latest] unless @@ -57,7 +57,7 @@ jobs: - name: Get list of tags id: gettags # TODO: Move to org? - uses: manics/action-major-minor-tag-calculator@main + uses: jupyterhub/action-major-minor-tag-calculator@main with: githubToken: ${{ secrets.GITHUB_TOKEN }} prefix: "jupyterhub/configurable-http-proxy:"