From 85748cc8cfe6304bbd5c874f2721f7dbf5200a9a Mon Sep 17 00:00:00 2001 From: Giovanni Gargiulo Date: Tue, 22 Aug 2023 09:30:54 +0100 Subject: [PATCH] chore: updated docekr workflow --- .../{voting-app-publish.yaml => publish.yaml} | 68 +++++++-------- .github/workflows/ui-publish.yaml | 72 --------------- .../voting-verification-app-publish.yaml | 87 ------------------- 3 files changed, 34 insertions(+), 193 deletions(-) rename .github/workflows/{voting-app-publish.yaml => publish.yaml} (72%) delete mode 100644 .github/workflows/ui-publish.yaml delete mode 100644 .github/workflows/voting-verification-app-publish.yaml diff --git a/.github/workflows/voting-app-publish.yaml b/.github/workflows/publish.yaml similarity index 72% rename from .github/workflows/voting-app-publish.yaml rename to .github/workflows/publish.yaml index bec69ac08..98010f90c 100644 --- a/.github/workflows/voting-app-publish.yaml +++ b/.github/workflows/publish.yaml @@ -1,4 +1,4 @@ -name: Publish voting-app docker image +name: Build and Publish Docker images on: push: @@ -9,35 +9,21 @@ on: workflow_dispatch: env: - APP_NAME: voting-app PRIVATE_DOCKER_REGISTRY_URL: ${{ secrets.GITLAB_DOCKER_REGISTRY_URL }} PRIVATE_DOCKER_REGISTRY_USER: Deploy-Token PRIVATE_DOCKER_REGISTRY_PASS: ${{ secrets.GITLAB_PKG_REGISTRY_TOKEN }} jobs: - publish: - permissions: - contents: read - packages: write + + build-version: runs-on: ubuntu-latest + outputs: + ARTIFACT_VERSION: ${{ steps.metadata.outputs.ARTIFACT_VERSION }} steps: - name: Checkout uses: actions/checkout@v3 - with: - submodules: 'true' - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: '17' - - name: Setup Gradle - uses: gradle/gradle-build-action@v2 - - - name: Execute Gradle build - working-directory: backend-services/voting-app - run: ./gradlew bootJar - - name: Setup depends + - name: Setup dependencies run: | pip install yq @@ -45,27 +31,42 @@ jobs: id: metadata run: | CURRENT_VERSION=$(cat version.txt) - echo "DOCKER_IMAGE_NAME=${{ env.APP_NAME }}" >> "$GITHUB_ENV" - + if [ ${{github.event_name}} == "pull_request" ] then PR_NUMBER=$(echo $GITHUB_REF | awk -F/ '{ print $3 }') - echo "ARTIFACT_VERSION=${CURRENT_VERSION}-PR${PR_NUMBER}" >> "$GITHUB_ENV" - echo "DOCKER_LATEST_IMAGE_TAG=" >> "$GITHUB_ENV" + echo "ARTIFACT_VERSION=${CURRENT_VERSION}-PR${PR_NUMBER}" >> "$GITHUB_OUTPUT" else - # Make sure develop branch artifacts include SNAPSHOT BRANCH=${GITHUB_REF##*/} echo "BRANCH=${GITHUB_REF##*/}" >> "$GITHUB_OUTPUT" - if [[ "${BRANCH}" == "develop" ]] && [[ "${CURRENT_VERSION}" =~ .*-SNAPSHOT$ ]] - then - echo "DEVELOP_SNAPSHOT_OK=true" >> "$GITHUB_OUTPUT" - fi - - echo "ARTIFACT_VERSION=${CURRENT_VERSION}" >> "$GITHUB_ENV" - echo "DOCKER_LATEST_IMAGE_TAG=${{ env.PRIVATE_DOCKER_REGISTRY_URL }}/${{ env.APP_NAME }}:latest" >> "$GITHUB_ENV" - + echo "ARTIFACT_VERSION=${CURRENT_VERSION}" >> "$GITHUB_OUTPUT" fi + + publish-voting-app: + runs-on: ubuntu-latest + env: + APP_NAME: voting-app + needs: build-version + steps: + - env: + ARTIFACT_VERSION: ${{needs.build-version.outputs.ARTIFACT_VERSION}} + run: echo "Artifact Version = $ARTIFACT_VERSION" + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: 'true' + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + + - name: Execute Gradle build + working-directory: backend-services/voting-app + run: ./gradlew bootJar - name: Docker Login uses: docker/login-action@v2 @@ -83,5 +84,4 @@ jobs: context: backend-services/${{ env.APP_NAME }} push: true tags: | - ${{ env.DOCKER_LATEST_IMAGE_TAG }} ${{ env.PRIVATE_DOCKER_REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:${{ env.ARTIFACT_VERSION }} diff --git a/.github/workflows/ui-publish.yaml b/.github/workflows/ui-publish.yaml deleted file mode 100644 index a9dcc9eb9..000000000 --- a/.github/workflows/ui-publish.yaml +++ /dev/null @@ -1,72 +0,0 @@ -name: Publish ui docker image - -on: - push: - branches: - - main - pull_request: - types: [ opened, synchronize ] - workflow_dispatch: - -env: - APP_NAME: voting-app-ui - PRIVATE_DOCKER_REGISTRY_URL: ${{ secrets.GITLAB_DOCKER_REGISTRY_URL }} - PRIVATE_DOCKER_REGISTRY_USER: Deploy-Token - PRIVATE_DOCKER_REGISTRY_PASS: ${{ secrets.GITLAB_PKG_REGISTRY_TOKEN }} - -jobs: - publish: - permissions: - contents: read - packages: write - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - submodules: 'true' - - - name: Set extra environment and metadata - id: metadata - run: | - CURRENT_VERSION=$(cat version.txt) - echo "DOCKER_IMAGE_NAME=${{ env.APP_NAME }}" >> "$GITHUB_ENV" - - if [ ${{github.event_name}} == "pull_request" ] - then - PR_NUMBER=$(echo $GITHUB_REF | awk -F/ '{ print $3 }') - echo "ARTIFACT_VERSION=${CURRENT_VERSION}-PR${PR_NUMBER}" >> "$GITHUB_ENV" - echo "DOCKER_LATEST_IMAGE_TAG=" >> "$GITHUB_ENV" - else - # Make sure develop branch artifacts include SNAPSHOT - BRANCH=${GITHUB_REF##*/} - echo "BRANCH=${GITHUB_REF##*/}" >> "$GITHUB_OUTPUT" - if [[ "${BRANCH}" == "develop" ]] && [[ "${CURRENT_VERSION}" =~ .*-SNAPSHOT$ ]] - then - echo "DEVELOP_SNAPSHOT_OK=true" >> "$GITHUB_OUTPUT" - fi - - echo "ARTIFACT_VERSION=${CURRENT_VERSION}" >> "$GITHUB_ENV" - echo "DOCKER_LATEST_IMAGE_TAG=${{ env.PRIVATE_DOCKER_REGISTRY_URL }}/${{ env.APP_NAME }}:latest" >> "$GITHUB_ENV" - - fi - - - - name: Docker Login - uses: docker/login-action@v2 - with: - registry: ${{ env.PRIVATE_DOCKER_REGISTRY_URL }} - username: ${{ env.PRIVATE_DOCKER_REGISTRY_USER }} - password: ${{ env.PRIVATE_DOCKER_REGISTRY_PASS }} - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Build and Push docker image - uses: docker/build-push-action@v4 - with: - context: ui/cip-1694 - push: true - tags: | - ${{ env.DOCKER_LATEST_IMAGE_TAG }} - ${{ env.PRIVATE_DOCKER_REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:${{ env.ARTIFACT_VERSION }} diff --git a/.github/workflows/voting-verification-app-publish.yaml b/.github/workflows/voting-verification-app-publish.yaml deleted file mode 100644 index d28af4873..000000000 --- a/.github/workflows/voting-verification-app-publish.yaml +++ /dev/null @@ -1,87 +0,0 @@ -name: Publish voting-verification-app docker image - -on: - push: - branches: - - main - pull_request: - types: [ opened, synchronize ] - workflow_dispatch: - -env: - APP_NAME: voting-verification-app - PRIVATE_DOCKER_REGISTRY_URL: ${{ secrets.GITLAB_DOCKER_REGISTRY_URL }} - PRIVATE_DOCKER_REGISTRY_USER: Deploy-Token - PRIVATE_DOCKER_REGISTRY_PASS: ${{ secrets.GITLAB_PKG_REGISTRY_TOKEN }} - -jobs: - publish: - permissions: - contents: read - packages: write - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - submodules: 'true' - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: '17' - - name: Setup Gradle - uses: gradle/gradle-build-action@v2 - - - name: Execute Gradle build - working-directory: backend-services/voting-verification-app - run: ./gradlew bootJar - - - name: Setup depends - run: | - pip install yq - - - name: Set extra environment and metadata - id: metadata - run: | - CURRENT_VERSION=$(cat version.txt) - echo "DOCKER_IMAGE_NAME=${{ env.APP_NAME }}" >> "$GITHUB_ENV" - - if [ ${{github.event_name}} == "pull_request" ] - then - PR_NUMBER=$(echo $GITHUB_REF | awk -F/ '{ print $3 }') - echo "ARTIFACT_VERSION=${CURRENT_VERSION}-PR${PR_NUMBER}" >> "$GITHUB_ENV" - echo "DOCKER_LATEST_IMAGE_TAG=" >> "$GITHUB_ENV" - else - # Make sure develop branch artifacts include SNAPSHOT - BRANCH=${GITHUB_REF##*/} - echo "BRANCH=${GITHUB_REF##*/}" >> "$GITHUB_OUTPUT" - if [[ "${BRANCH}" == "develop" ]] && [[ "${CURRENT_VERSION}" =~ .*-SNAPSHOT$ ]] - then - echo "DEVELOP_SNAPSHOT_OK=true" >> "$GITHUB_OUTPUT" - fi - - echo "ARTIFACT_VERSION=${CURRENT_VERSION}" >> "$GITHUB_ENV" - echo "DOCKER_LATEST_IMAGE_TAG=${{ env.PRIVATE_DOCKER_REGISTRY_URL }}/${{ env.APP_NAME }}:latest" >> "$GITHUB_ENV" - - fi - - - - name: Docker Login - uses: docker/login-action@v2 - with: - registry: ${{ env.PRIVATE_DOCKER_REGISTRY_URL }} - username: ${{ env.PRIVATE_DOCKER_REGISTRY_USER }} - password: ${{ env.PRIVATE_DOCKER_REGISTRY_PASS }} - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Build and Push docker image - uses: docker/build-push-action@v4 - with: - context: backend-services/${{ env.APP_NAME }} - push: true - tags: | - ${{ env.DOCKER_LATEST_IMAGE_TAG }} - ${{ env.PRIVATE_DOCKER_REGISTRY_URL }}/${{ env.DOCKER_IMAGE_NAME }}:${{ env.ARTIFACT_VERSION }}