Merge pull request #717 from Klantinteractie-Servicesysteem/DIM@6002_… #1923
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker CI | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
build-node: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Get date | |
id: date | |
run: | | |
echo "DATE=$(date +'%Y%m%d%H%M%S')-$(echo $GITHUB_SHA | head -c 7)" >> $GITHUB_ENV | |
- name: Get branch name | |
id: branch | |
run: | | |
BRANCH_NAME="${{ github.head_ref }}" | |
if [[ -z "$BRANCH_NAME" ]]; then | |
BRANCH_NAME="${{ github.ref }}" | |
BRANCH_NAME="${BRANCH_NAME#refs/heads/}" | |
fi | |
BRANCH_NAME=$(echo $BRANCH_NAME | tr / -) | |
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | |
- name: Set release code | |
if: (success() || failure()) | |
id: releasecode | |
run: | | |
VERSION=$(grep APP_VERSION= .env | cut -d '=' -f2) | |
RELEASE=$BRANCH_NAME-$DATE | |
echo "RELEASE=$RELEASE" >> $GITHUB_ENV | |
echo "APP_ENV=prod">> $GITHUB_ENV | |
echo "APP_BUILD=latest">> $GITHUB_ENV | |
echo "set APP_ENV to $APP_ENV" | |
- name: Setting CONTAINER_PROJECT_NAME | |
run: | | |
NAME=$(grep CONTAINER_PROJECT_NAME= .env | cut -d '=' -f2) | |
echo "CONTAINER_PROJECT_NAME=$NAME" >> $GITHUB_ENV | |
- name: Setting CONTAINER_REGISTRY_BASE | |
run: | | |
NAME=$(grep CONTAINER_REGISTRY_BASE= .env | cut -d '=' -f2) | |
echo "CONTAINER_REGISTRY_BASE=$NAME" >> $GITHUB_ENV | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
if: github.event_name != 'pull_request' | |
- name: Build containers | |
uses: docker/bake-action@v3 | |
with: | |
push: false | |
load: true | |
files: docker-compose.deploy.yaml | |
set: | | |
*.cache-from=type=gha | |
*.cache-to=type=gha,mode=max | |
- name: copy testresults | |
uses: docker/build-push-action@v4 | |
with: | |
push: false | |
load: false | |
context: . | |
file: Kiss.Bff/Dockerfile | |
target: test | |
outputs: testresults | |
- name: dotnet test report | |
uses: dorny/test-reporter@v1 | |
if: success() || failure() # run this step even if previous step failed | |
with: | |
name: dotnet tests # Name of the check run which will be created | |
path: testresults/*.trx # Path to test results | |
reporter: dotnet-trx # Format of test results | |
- name: npm test report | |
uses: dorny/test-reporter@v1 | |
if: success() || failure() # run this step even if previous step failed | |
with: | |
name: npm tests # Name of the check run which will be created | |
path: testresults/*.xml # Path to test results | |
reporter: jest-junit # Format of test results | |
- name: push image | |
uses: docker/build-push-action@v4 | |
if: github.event_name != 'pull_request' | |
with: | |
context: . | |
file: Kiss.Bff/Dockerfile | |
push: true | |
tags: ${{ env.CONTAINER_REGISTRY_BASE }}/${{ env.CONTAINER_PROJECT_NAME }}:${{ env.RELEASE}},${{ env.CONTAINER_REGISTRY_BASE }}/${{ env.CONTAINER_PROJECT_NAME }}:latest | |
target: final |