diff --git a/.githooks/pre-commit b/.githooks/pre-commit index c3136e3..6119932 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -2,3 +2,6 @@ # Lint YAML Files yamllint . + +# Dry-run docker compose +docker compose --project-directory deploy/docker-compose create --dry-run diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fe307f3..11badba 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,10 +28,6 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true -# Set Workflow-level environment variables -env: - PROJECT: demoapp-backend - jobs: build: # Run job when not triggered by a merge @@ -69,21 +65,13 @@ jobs: ports: - 3306:3306 # Opens tcp port 3306 on the host and service container steps: - # Workaround for the absence of github.branch_name - # Setting an environment variable: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable - - name: Set VERSION - if: github.head_ref != '' - run: | - echo "VERSION=${{ github.head_ref }}" >> $GITHUB_ENV - - name: Set VERSION - if: github.head_ref == '' - run: | - echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + # Workaround for the absence of github.branch_name, use github-env-vars-action to define useful environment variables not available by default + - uses: FranzDiebold/github-env-vars-action@v2 # https://github.com/marketplace/actions/github-environment-variables-action # Set Complete Container Image URL - name: Set CONTAINER_IMAGE_URL run: | - echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.PROJECT }}:${{ env.VERSION }}" >> $GITHUB_ENV + echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }}" >> $GITHUB_ENV # Fail job when invalid builder is selected - name: Check BUILDER environment variable @@ -139,7 +127,7 @@ jobs: # Use `vars` context when using repository environment variables: https://docs.github.com/en/actions/learn-github-actions/contexts#vars-context run: | mvn package -Ddockerfile.skip=true \ - -Drevision=${{ env.VERSION }} \ + -Drevision=${{ env.CI_ACTION_REF_NAME }} \ -DDOCKER_REGISTRY_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/ - name: Docker Build and Push @@ -150,7 +138,7 @@ jobs: file: Containerfile # build-args syntax clarification: https://github.com/docker/build-push-action/issues/557#issuecomment-1030412477 build-args: | - "JAR_FILE=${{ env.PROJECT }}-${{ env.VERSION }}.jar" + "JAR_FILE=${{ env.CI_REPOSITORY_NAME }}-${{ env.CI_ACTION_REF_NAME }}.jar" push: true tags: ${{ env.CONTAINER_IMAGE_URL }} # CONTAINER_IMAGE_URL is defined in GITHUB_ENV cache-from: type=gha @@ -171,21 +159,13 @@ jobs: runs-on: ubuntu-latest environment: docker-hub # Use `docker-hub` repository environment steps: - # Workaround for the absence of github.branch_name - # Setting an environment variable: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable - - name: Set VERSION - if: github.head_ref != '' - run: | - echo "VERSION=${{ github.head_ref }}" >> $GITHUB_ENV - - name: Set VERSION - if: github.head_ref == '' - run: | - echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + # Workaround for the absence of github.branch_name, use github-env-vars-action to define useful environment variables not available by default + - uses: FranzDiebold/github-env-vars-action@v2 # https://github.com/marketplace/actions/github-environment-variables-action # Set Complete Container Image URL - name: Set CONTAINER_IMAGE_URL run: | - echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.PROJECT }}:${{ env.VERSION }}" >> $GITHUB_ENV + echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }}" >> $GITHUB_ENV - name: Login to DockerHub uses: docker/login-action@v3 # https://github.com/marketplace/actions/docker-login @@ -217,21 +197,13 @@ jobs: env: TRIVY_CACHE_DIR: /tmp/trivy/ steps: - # Workaround for the absence of github.branch_name - # Setting an environment variable: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable - - name: Set VERSION - if: github.head_ref != '' - run: | - echo "VERSION=${{ github.head_ref }}" >> $GITHUB_ENV - - name: Set VERSION - if: github.head_ref == '' - run: | - echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + # Workaround for the absence of github.branch_name, use github-env-vars-action to define useful environment variables not available by default + - uses: FranzDiebold/github-env-vars-action@v2 # https://github.com/marketplace/actions/github-environment-variables-action # Set Complete Container Image URL - name: Set CONTAINER_IMAGE_URL run: | - echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.PROJECT }}:${{ env.VERSION }}" >> $GITHUB_ENV + echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }}" >> $GITHUB_ENV - name: Checkout repository uses: actions/checkout@v4 # https://github.com/marketplace/actions/checkout diff --git a/.github/workflows/code-scan-sonarcloud.yml b/.github/workflows/code-scan-sonarcloud.yml index 392ab90..c8cc800 100644 --- a/.github/workflows/code-scan-sonarcloud.yml +++ b/.github/workflows/code-scan-sonarcloud.yml @@ -33,16 +33,8 @@ jobs: pull-requests: read # Allow SonarCloud to get pull request details environment: sonarcloud # Use `sonarcloud` repository environment steps: - # Workaround for the absence of github.branch_name - # Setting an environment variable: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable - - name: Set VERSION - if: github.head_ref != '' - run: | - echo "VERSION=${{ github.head_ref }}" >> $GITHUB_ENV - - name: Set VERSION - if: github.head_ref == '' - run: | - echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + # Workaround for the absence of github.branch_name, use github-env-vars-action to define useful environment variables not available by default + - uses: FranzDiebold/github-env-vars-action@v2 # https://github.com/marketplace/actions/github-environment-variables-action - name: Checkout repository uses: actions/checkout@v4 # https://github.com/marketplace/actions/checkout @@ -99,9 +91,9 @@ jobs: run: | mvn -B verify \ org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \ - -Drevision=${{ env.VERSION }} \ - -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} \ - -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }} \ + -Drevision=${{ env.CI_ACTION_REF_NAME }} \ + -Dsonar.organization=${{ env.CI_REPOSITORY_OWNER }} \ + -Dsonar.projectKey=${{ env.CI_REPOSITORY_OWNER }}_${{ env.CI_REPOSITORY_NAME }} \ -Dmaven.test.skip=true \ -Ddockerfile.skip=true env: @@ -119,9 +111,9 @@ jobs: run: | mvn -B verify \ org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \ - -Drevision=${{ env.VERSION }} \ - -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} \ - -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }} \ + -Drevision=${{ env.CI_ACTION_REF_NAME }} \ + -Dsonar.organization=${{ env.CI_REPOSITORY_OWNER }} \ + -Dsonar.projectKey=${{ env.CI_REPOSITORY_OWNER }}_${{ env.CI_REPOSITORY_NAME }} \ -Dsonar.pullrequest.provider=GitHub \ -Dsonar.pullrequest.github.repository=${{ github.repository }} \ -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \ diff --git a/.github/workflows/merge-cleanup.yml b/.github/workflows/merge-cleanup.yml index 336239d..e7fcfc1 100644 --- a/.github/workflows/merge-cleanup.yml +++ b/.github/workflows/merge-cleanup.yml @@ -20,10 +20,6 @@ on: # Set Workflow-level permissions: https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs permissions: {} # This Workflow does not require any permission -# Set Workflow-level environment variables -env: - PROJECT: demoapp-backend - jobs: output-information: runs-on: ubuntu-latest @@ -45,23 +41,15 @@ jobs: # - name: Skopeo Delete Image # id: skopeo-delete # run: | - # skopeo delete docker://${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.PROJECT }}:${{ env.VERSION }} + # skopeo delete docker://${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }} # Regctl allows image tag deletion which is allowed by Docker Hub docker-hub-regctl: runs-on: ubuntu-latest environment: docker-hub steps: - # Workaround for the absence of github.branch_name - # Setting an environment variable: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable - - name: Set VERSION - if: github.head_ref != '' - run: | - echo "VERSION=${{ github.head_ref }}" >> $GITHUB_ENV - - name: Set VERSION - if: github.head_ref == '' - run: | - echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV + # Workaround for the absence of github.branch_name, use github-env-vars-action to define useful environment variables not available by default + - uses: FranzDiebold/github-env-vars-action@v2 # https://github.com/marketplace/actions/github-environment-variables-action # Install regctl: https://github.com/regclient/regclient - name: Install regctl @@ -75,4 +63,4 @@ jobs: --pass ${{ secrets.DOCKER_REGISTRY_PASSWORD }} \ - name: regctl Delete Image Tag run: | - ./regctl tag delete ${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.PROJECT }}:${{ env.VERSION }} + ./regctl tag delete ${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 259aedc..0ca9904 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,10 +12,6 @@ on: tags: - 'v*' # When a tag starting with `v` is created e.g. v1.0.0 -# Set Workflow-level environment variables -env: - PROJECT: demoapp-backend - jobs: push_to_registries: name: Push Container image to multiple registries