Skip to content

Feat: deployments and build #8

Feat: deployments and build

Feat: deployments and build #8

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 }}