From 0cc493e618b13365be0699753ff760801a67fe6e Mon Sep 17 00:00:00 2001 From: Anton Lee Date: Sun, 4 Aug 2024 17:05:27 +1200 Subject: [PATCH] ci: fix automated docker versioning --- .github/workflows/all_targets.yml | 10 ----- .github/workflows/docker.yml | 61 ++++++------------------------- 2 files changed, 12 insertions(+), 59 deletions(-) diff --git a/.github/workflows/all_targets.yml b/.github/workflows/all_targets.yml index fdcd300..ef00412 100644 --- a/.github/workflows/all_targets.yml +++ b/.github/workflows/all_targets.yml @@ -118,13 +118,3 @@ jobs: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 - - docker: - name: "Trigger Docker Build" - if: github.ref == 'refs/heads/main' && needs.release.outputs.released == 'true' - needs: [release] - uses: ./.github/workflows/docker.yml - secrets: "inherit" - with: - tag: ${{ needs.release.outputs.tag }} - is_latest: true diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index ec814d6..3599651 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,64 +1,25 @@ name: Docker on: - workflow_dispatch: - inputs: - tag: - description: "The tag of the repository to build" - required: true - default: "refs/heads/main" - is_latest: - type: boolean - description: "Whether to tag the image as latest" - required: false - default: false - workflow_call: - inputs: - tag: - type: string - description: "The tag of the repository to build" - required: true - is_latest: - type: boolean - description: "Whether to tag the image as latest" - required: false - default: false + # Trigger the workflow on push that contains a new version tag + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + branches: + - main jobs: buildx: - name: Build & Publish + name: Docker Build and Push environment: release runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - with: - ref: ${{ github.event.inputs.tag }} + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - # Load docker/.env file. The weird syntax is because we need to append the - # CAPYMOA_VERSION to the GITHUB_ENV and we need to strip quotes from the - # value - - - name: Load .env - run: | - source docker/.env && - echo CAPYMOA_VERSION=$CAPYMOA_VERSION >> $GITHUB_ENV - - - name: Name Image - id: image_names - run: | - image_names="${{ secrets.DOCKERHUB_USERNAME }}/jupyter-capymoa:${{ env.CAPYMOA_VERSION }}" - - # If we were asked to tag as latest, add the latest tag - if [ "${{ github.event.inputs.is_latest }}" = "true" ]; then - image_names="$image_names,${{ secrets.DOCKERHUB_USERNAME }}/jupyter-capymoa:latest" - fi - echo "$image_names" - echo "image_names=$image_names" >> $GITHUB_OUTPUT - shell: sh - - name: Login to Docker Hub uses: docker/login-action@v3 @@ -73,6 +34,8 @@ jobs: push: true platforms: linux/amd64,linux/arm64 file: docker/dockerfile - tags: ${{ steps.image_names.outputs.image_names }} - build-args: CAPYMOA_VERSION=${{ env.CAPYMOA_VERSION }} + tags: >- + ${{ secrets.DOCKERHUB_USERNAME }}/jupyter-capymoa:${{ github.ref_name }}", + ${{ secrets.DOCKERHUB_USERNAME }}/jupyter-capymoa:latest + build-args: CAPYMOA_VERSION=${{ github.ref_name }}"