From bddcc38c054a485de42e24115020a3c34d800003 Mon Sep 17 00:00:00 2001 From: JCNoguera Date: Fri, 26 Jan 2024 13:53:33 +0100 Subject: [PATCH] ci: fix tags and set jobs correctly --- .github/workflows/build-images.reusable.yaml | 51 ++++++++++++++++++++ .github/workflows/release-production.yaml | 37 +++++++------- .github/workflows/release-staging.yaml | 39 ++++++++------- 3 files changed, 91 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/build-images.reusable.yaml diff --git a/.github/workflows/build-images.reusable.yaml b/.github/workflows/build-images.reusable.yaml new file mode 100644 index 000000000..f646dcd16 --- /dev/null +++ b/.github/workflows/build-images.reusable.yaml @@ -0,0 +1,51 @@ +name: Build and Push Images + +on: + workflow_call: + inputs: + api_image_tags: + required: true + type: string + client_image_tags: + required: true + type: string + +jobs: + build-and-push-images: + name: Build and Push Docker Images + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: "16" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.IOTALEDGER_DOCKER_USERNAME }} + password: ${{ secrets.IOTALEDGER_DOCKER_PASSWORD }} + + - name: Build and push API Docker image + uses: docker/build-push-action@v2 + with: + context: ./api + file: ./api/Dockerfile + push: true + tags: ${{ inputs.api_image_tags }} + no-cache: true + + - name: Build and push Client Docker image + uses: docker/build-push-action@v2 + with: + context: ./client + file: ./client/Dockerfile + push: true + tags: ${{ inputs.client_image_tags }} + no-cache: true diff --git a/.github/workflows/release-production.yaml b/.github/workflows/release-production.yaml index 4c2a5d33f..0a9a37ff6 100644 --- a/.github/workflows/release-production.yaml +++ b/.github/workflows/release-production.yaml @@ -3,12 +3,12 @@ name: Release Explorer to Production on: push: tags: - # Only run workflow on tags that match the semantic versioning pattern 'v1.0.0' - - ^v(\d+\.\d+\.\d+)$ + - 'v[0-9]+.[0-9]+.[0-9]+' + - '!v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+' jobs: - deploy-production-images: - name: Deploy Docker Images for Production + set_tags: + name: Set Tags runs-on: ubuntu-latest outputs: version_tag: ${{ steps.set_version_tag.outputs.version_tag }} @@ -18,22 +18,23 @@ jobs: run: | echo "VERSION_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT - - name: Build and push API Docker image - uses: ./.github/workflows/build-and-push-docker-images.yaml - with: - version_tag: ${{ steps.set_version_tag.outputs.version_tag }} - api_image_tags: | - iotaledger/explorer-api:${{ steps.set_version_tag.outputs.VERSION_TAG }} - iotaledger/explorer-api:latest - iotaledger/explorer-api:latest-stable + use-reusable-workflow: + name: Build Images + needs: set_tags + uses: ./.github/workflows/build-images.reusable.yaml + with: + api_image_tags: | + iotaledger/explorer-api:${{ needs.set_tags.outputs.version_tag }} + iotaledger/explorer-api:latest - client_image_tags: | - iotaledger/explorer-client:${{ steps.set_version_tag.outputs.VERSION_TAG }} - iotaledger/explorer-client:latest - iotaledger/explorer-client:latest-stable + client_image_tags: | + iotaledger/explorer-client:${{ needs.set_tags.outputs.version_tag }} + iotaledger/explorer-client:latest + secrets: inherit deploy_to_server: - needs: deploy-production-images + name: Deploy Production to Server + needs: [set_tags, use-reusable-workflow] runs-on: ubuntu-latest strategy: matrix: @@ -46,4 +47,4 @@ jobs: - name: Deploy to Server run: | - ssh -o StrictHostKeyChecking=no updater@${{ secrets.EXPLORER_GATEWAY }} "${{ matrix.environment }} ${{ needs.deploy-production-images.outputs.version_tag }}" + ssh -o StrictHostKeyChecking=no updater@${{ secrets.EXPLORER_GATEWAY }} "${{ matrix.environment }} ${{ needs.set_tags.outputs.version_tag }}" diff --git a/.github/workflows/release-staging.yaml b/.github/workflows/release-staging.yaml index b7c577dc0..8628bf48e 100644 --- a/.github/workflows/release-staging.yaml +++ b/.github/workflows/release-staging.yaml @@ -3,8 +3,7 @@ name: Release Explorer to Staging on: push: tags: - # Only run workflow on tags that match the semantic versioning pattern 'v1.0.0-rc.0' - - ^v(\d+\.\d+\.\d+)-rc\.\d+$ + - 'v[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+' # Versioning pattern 'v1.0.0-rc.0' workflow_dispatch: inputs: tag: @@ -13,15 +12,18 @@ on: default: "v1.0.0-rc.0" jobs: - deploy-staging-images: - name: Deploy Docker Images for Staging + set_tags: + name: Set Tags runs-on: ubuntu-latest outputs: version_tag: ${{ steps.set_version_tag.outputs.version_tag }} steps: + - name: Checkout + uses: actions/checkout@v2 + # If the workflow was triggered by a tag, use the tag as the version. # Otherwise, use the tag from the workflow_dispatch event. - - name: Set up the tag for docker images + - name: Set up the version tag for docker images id: set_version_tag run: | if [ "${{ github.event_name }}" = "push" ]; then @@ -30,19 +32,20 @@ jobs: echo "VERSION_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT fi - - name: Build and push API Docker image - uses: ./.github/workflows/build-and-push-docker-images.yaml - with: - version_tag: ${{ steps.set_version_tag.outputs.version_tag }} - api_image_tags: | - iotaledger/explorer-api:${{ steps.set_version_tag.outputs.VERSION_TAG }} - iotaledger/explorer-api:latest - client_image_tags: | - iotaledger/explorer-client:${{ steps.set_version_tag.outputs.VERSION_TAG }} - iotaledger/explorer-client:latest + use-reusable-workflow: + name: Build Images + needs: set_tags + uses: ./.github/workflows/build-images.reusable.yaml + with: + api_image_tags: | + iotaledger/explorer-api:${{ needs.set_tags.outputs.version_tag }} + client_image_tags: | + iotaledger/explorer-client:${{ needs.set_tags.outputs.version_tag }} + secrets: inherit - deploy: - needs: deploy-staging-images + deploy_to_server: + name: Deploy Staging to Server + needs: [set_tags, use-reusable-workflow] runs-on: ubuntu-latest strategy: matrix: @@ -55,4 +58,4 @@ jobs: - name: Deploy to Server run: | - ssh -o StrictHostKeyChecking=no updater@${{ secrets.EXPLORER_GATEWAY }} "${{ matrix.environment }} ${{ needs.deploy-staging-images.outputs.version_tag }}" + ssh -o StrictHostKeyChecking=no updater@${{ secrets.EXPLORER_GATEWAY }} "${{ matrix.environment }} ${{ needs.set_tags.outputs.version_tag }}"