Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use github-env-vars-action github action for workflows and add docker compose dry run to pre-commit hook #37

Merged
merged 3 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

# Lint YAML Files
yamllint .

# Dry-run docker compose
docker compose --project-directory deploy/docker-compose create --dry-run
50 changes: 11 additions & 39 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 8 additions & 16 deletions .github/workflows/code-scan-sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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 }} \
Expand Down
20 changes: 4 additions & 16 deletions .github/workflows/merge-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }}
4 changes: 0 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading