forked from LibreBooking/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (139 loc) · 4.75 KB
/
build_pull_request.yml
File metadata and controls
152 lines (139 loc) · 4.75 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Check the Docker image builds for a PR
on:
workflow_dispatch:
pull_request:
jobs:
lint_dockerfile:
name: Lint Dockerfile
runs-on: ubuntu-latest
steps:
-
name: Checkout github repository
uses: actions/checkout@v6
-
name: Lint Dockerfile with hadolint
uses: hadolint/hadolint-action@v3.3.0
with:
dockerfile: Dockerfile
lint_shell_scripts:
name: Lint shell scripts
runs-on: ubuntu-latest
steps:
-
name: Checkout github repository
uses: actions/checkout@v6
-
name: Install shell lint tools
run: |
sudo apt-get update
sudo apt-get install -y shellcheck shfmt
-
name: Run shellcheck
run: |
set -euo pipefail
mapfile -t scripts < <(git ls-files '*.sh')
shellcheck --severity style "${scripts[@]}"
-
name: Run shfmt
run: |
set -euo pipefail
mapfile -t scripts < <(git ls-files '*.sh')
shfmt -d -i 2 -ci "${scripts[@]}"
check_build:
runs-on: ubuntu-latest
env:
APP_GH_REF: develop
APP_GH_ADD_SHA: "true"
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: librebooking
MYSQL_USER: librebooking
MYSQL_PASSWORD: librebooking
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1 -proot"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
-
name: Checkout github repository
uses: actions/checkout@v6
-
name: Setup Docker buildx
uses: docker/setup-buildx-action@v4
-
name: Build Docker image
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64
build-args: |
VERSION_PHP=8.4
VERSION_COMPOSER=lts
APP_GH_REF=${{ env.APP_GH_REF }}
APP_GH_ADD_SHA=${{ env.APP_GH_ADD_SHA }}
tags: librebooking-pr:${{ github.sha }}
load: true
push: false
-
name: Smoke test image
run: |
set -euo pipefail
lb_image_tag="librebooking-pr:${GITHUB_SHA}"
mysql_service_id="${{ job.services.mysql.id }}"
docker create --name librebooking-smoke-src "${lb_image_tag}" >/dev/null
docker cp librebooking-smoke-src:/var/www/html/database_schema /tmp/librebooking-database_schema
docker rm librebooking-smoke-src
cat \
/tmp/librebooking-database_schema/create-db.sql \
/tmp/librebooking-database_schema/create-schema.sql \
| docker exec --interactive "${mysql_service_id}" mysql --user root --password=root
docker run --rm \
--add-host host.docker.internal:host-gateway \
"${lb_image_tag}" \
php /var/www/html/phing-tasks/UpgradeDbTask.php \
librebooking \
librebooking \
host.docker.internal \
librebooking \
/var/www/html/database_schema
docker run --detach \
--name librebooking-smoke \
--add-host host.docker.internal:host-gateway \
--publish 18080:8080 \
--env LB_DATABASE_HOSTSPEC=host.docker.internal \
--env LB_DATABASE_NAME=librebooking \
--env LB_DATABASE_USER=librebooking \
--env LB_DATABASE_PASSWORD=librebooking \
"${lb_image_tag}"
for attempt in $(seq 1 30); do
if curl --silent --show-error --fail --max-time 2 http://127.0.0.1:18080/Web/; then
echo "Connected to docker image successfully"
break
fi
if [ "${attempt}" = "30" ]; then
echo "Smoke test failed: HTTP endpoint did not become ready" >&2
docker logs librebooking-smoke || true
docker logs "${{ job.services.mysql.id }}" || true
exit 1
fi
sleep 2
done
modules_count=$(docker exec librebooking-smoke php -m | grep -Ec '^(gd|ldap|mysqli|timezonedb)$' || true)
if [ "${modules_count}" -ne 4 ]; then
echo "Smoke test failed: expected 4 required PHP modules (gd, ldap, mysqli, timezonedb), but found ${modules_count}"
docker exec librebooking-smoke php -m || true
exit 1
fi
-
name: Cleanup smoke container
if: always()
run: |
docker rm --force librebooking-smoke >/dev/null 2>&1 || true
docker rm --force librebooking-smoke-src >/dev/null 2>&1 || true
rm -rf /tmp/librebooking-database_schema