-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (79 loc) · 2.91 KB
/
docker-ci.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Docker Application CI
on:
workflow_call:
inputs:
environment:
required: false
description: Environment to run CI checks in
type: string
default: development
healthCheckPath:
required: false
description: Path to health check endpoint
type: string
default: ${{ vars.APPLICATION_CI_HEALTHCHECK_PATH || '/' }}
secrets:
azureCredentials:
required: false
jobs:
build:
name: Build app
if: ${{ github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Check if azureCredentials is set
run: |
if [ -z "${{ secrets.azureCredentials }}" ]; then
echo "Azure Credentials not set. Skipping Azure Key Vault retrieval."
echo "AZURE_CREDENTIALS_SET=false" >> $GITHUB_ENV
fi
- name: Generate .env file from Azure Key Vaults
if: ${{ env.AZURE_CREDENTIALS_SET != 'false' }}
id: get-envs
uses: Andrews-McMeel-Universal/get-envs@v1
with:
azurecredentials: ${{ secrets.azureCredentials }}
environment: ${{ inputs.environment }}
contentTypes: BuildArg Env
buildArgPredicate: ";"
- name: Insert new line after build arguments
id: insert-new-line
run: |
buildArguments=$(echo "${{ steps.get-envs.outputs.buildArguments }}" | sed 's/^ ; //g' | sed 's/; /\n/g')
echo 'buildArguments<<EOF' >> $GITHUB_ENV
echo "$buildArguments" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Docker Build
uses: docker/build-push-action@v5
with:
tags: docker-ci:latest
push: false
load: true
build-args: |
${{ env.buildArguments }}
- name: Get Docker variables from image
run: |
dockerContainerPort=$(docker image inspect docker-ci:latest -f "{{json .Config.ExposedPorts }}" | tr -d '{}":/tcp')
dockerCmd=$(docker image inspect docker-ci:latest -f "{{json .Config.Cmd }}" | tr -d '][' | tr "," " ")
echo "dockerContainerPort=$dockerContainerPort" >> $GITHUB_ENV
echo "dockerCmd=$dockerCmd" >> $GITHUB_ENV
- name: Run tests in Docker Container
uses: addnab/docker-run-action@v3
with:
image: docker-ci:latest
run: |
${{ env.dockerCmd }} &
sleep 15
RESULT=$?
if [ $RESULT -eq 0 ]; then
wget -O - -q "http://localhost:${{ env.dockerContainerPort }}${{ inputs.healthCheckPath }}" ||
curl "http://localhost:${{ env.dockerContainerPort }}${{ inputs.healthCheckPath }}"
else
exit 1
fi