From 946e3cd40ebc189197166f0358c64a9a32501776 Mon Sep 17 00:00:00 2001 From: ndc-dxc <162444006+ndc-dxc@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:52:47 +0200 Subject: [PATCH] Update docker-image.yml --- .github/workflows/docker-image.yml | 39 +++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index e4e10de..2a43a6c 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -14,13 +14,29 @@ env: jobs: build: runs-on: ubuntu-latest + if: github.event_name != 'pull_request' + permissions: + contents: read + packages: write steps: - - uses: actions/checkout@v4 - - name: Build the Docker image - run: | - IMAGE="$REGISTRY/$IMAGE_NAME" - TAG="$(date +'%Y%m%d')-${{github.run_number}}-$(git rev-parse --short HEAD)" - docker build . --file Dockerfile --tag ${IMAGE}:${TAG} + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Log in to the GitHub Container registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build the Docker image + run: | + IMAGE="$REGISTRY/$IMAGE_NAME" + TAG="$(date +'%Y%m%d')-${{github.run_number}}-$(git rev-parse --short HEAD)" + docker build . --file Dockerfile --tag ${IMAGE}:${TAG} + docker push ${IMAGE}:${TAG} + docker tag ${IMAGE}:${TAG} ${IMAGE}:latest + docker push ${IMAGE}:latest publish: runs-on: ubuntu-latest @@ -50,10 +66,6 @@ jobs: docker tag ${IMAGE}:${TAG} ${IMAGE}:latest docker push ${IMAGE}:latest - - name: Output image name - id: extractImage - run: echo "imageName=${IMAGE}:${TAG}" >> $GITHUB_ENV - deploy: runs-on: ubuntu-latest if: github.event_name != 'pull_request' @@ -67,8 +79,11 @@ jobs: uses: actions/checkout@v2 - name: Deploy using extracted image + id: extractImage run: | - echo "Deploying image: ${{ env.imageName }}" + IMAGE="$REGISTRY/$IMAGE_NAME" + TAG="$(date +'%Y%m%d')-${{github.run_number}}-$(git rev-parse --short HEAD)" + echo "##[set-output name=imageName;]${IMAGE}:${TAG}" - uses: convictional/trigger-workflow-and-wait@v1.3.0 with: owner: teamdigitale @@ -77,4 +92,4 @@ jobs: workflow_file_name: update-config.yaml ref: dev wait_interval: 20 - inputs: '{"serviceName": "dati-semantic-wordpress", "imageWithNewTag": "${{ env.imageName }}"}' + inputs: '{"serviceName": "dati-semantic-wordpress", "imageWithNewTag": "${{ steps.extractImage.outputs.imageName }}"}'