-
Notifications
You must be signed in to change notification settings - Fork 3
129 lines (113 loc) · 3.73 KB
/
build-app-image.yml
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Build App Image
on:
push:
branches: [ master ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ master ]
workflow_dispatch:
inputs:
push:
description: 'Push Image (true or false)'
required: true
default: 'true'
run_tests:
description: 'Run unit tests (true or false)'
required: true
default: 'true'
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
# Unit test
DB_DATABASE: mydb
DB_USERNAME: root
DB_PASSWORD: mysqlp455w0rd
permissions:
contents: read
packages: write
jobs:
build_backend_app:
runs-on: ubuntu-latest
services:
mysql-container:
image: mysql:8.0
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: ${{ env.DB_PASSWORD }}
MYSQL_DATABASE: ${{ env.DB_DATABASE }}
ports:
- 3306/tcp
options: --name mysql --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Login against a Docker registry to pull the GHCR image
# https://github.com/docker/login-action
- name: Log into registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Build image locally to enable to run the test
# https://github.com/docker/build-push-action
- name: Build Docker image
uses: docker/build-push-action@v4
with:
context: .
file: docker/Dockerfile
push: false
platforms: linux/amd64 #,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
load: true
- name: Inspect
run: |
for tag in $(echo "${{ steps.meta.outputs.tags }}"); do
docker image inspect $tag
done
- name: Test with phpunit
if: ${{ github.event.inputs.run_tests != 'false' }}
run: |
for tag in $(echo "${{ steps.meta.outputs.tags }}"); do
docker run \
-e APP_ENV=test \
-p 80:80 \
--name tester \
--rm -d \
--network ${{ job.container.network }} \
$tag tail -f /dev/null
docker cp tests/ tester:/srv
docker exec tester composer run migrate -- reset --yes
docker exec tester composer install --dev --no-interaction --no-progress
docker exec tester composer run test
docker stop tester
break
done
# PUSH the image (if isn't PR)
- name: Push Docker image
if: ${{ github.event_name != 'pull_request' || github.event.inputs.push == 'true' }}
run: |
for tag in $(echo "${{ steps.meta.outputs.tags }}"); do
docker push $tag
done
- name: Job Summary
run: |
for tag in $(echo "${{ steps.meta.outputs.tags }}"); do
echo Docker Image: $tag
done
echo Push Image: ${{ github.event_name != 'pull_request' || github.event.inputs.push == 'true' }}