Skip to content

Commit 9552888

Browse files
authored
[Chore] CI and Docker build improvements (#240)
1 parent 9343f05 commit 9552888

File tree

5 files changed

+444
-229
lines changed

5 files changed

+444
-229
lines changed

.github/workflows/ci.yml

Lines changed: 291 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -2,90 +2,300 @@ name: CI
22

33
on:
44
push:
5-
paths-ignore:
6-
- 'docker/**'
5+
branches:
6+
- main # Only run on pushes to main
77
pull_request:
8-
paths-ignore:
9-
- 'docker/**'
8+
# Run on all PRs (no path restrictions)
109

1110
env:
12-
COMPOSER_ALLOW_SUPERUSER: '1'
13-
SYMFONY_DEPRECATIONS_HELPER: max[self]=0
14-
ADMIN_LOGIN: admin
15-
ADMIN_PASSWORD: test
16-
DATABASE_URL: mysql://davis:davis@mysql:3306/davis_test
11+
COMPOSER_ALLOW_SUPERUSER: '1'
12+
SYMFONY_DEPRECATIONS_HELPER: max[self]=0
13+
ADMIN_LOGIN: admin
14+
ADMIN_PASSWORD: test
1715

1816
jobs:
19-
analyze:
20-
name: Analyze
21-
runs-on: ubuntu-latest
22-
container:
23-
image: php:8.3-alpine
24-
options: >-
25-
--tmpfs /tmp:exec
26-
--tmpfs /var/tmp:exec
27-
steps:
28-
- name: Checkout
29-
uses: actions/checkout@v4
30-
- name: Install GD / ZIP PHP extension
31-
run: |
32-
apk add $PHPIZE_DEPS libpng-dev libzip-dev
33-
docker-php-ext-configure gd
34-
docker-php-ext-configure zip
35-
docker-php-ext-install gd zip
36-
- name: Install Composer
37-
run: wget -qO - https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet
38-
- name: Validate Composer
39-
run: composer validate
40-
- name: Update to highest dependencies with Composer
41-
run: composer update --no-interaction --no-progress --ansi
42-
- name: Analyze
43-
run: PHP_CS_FIXER_IGNORE_ENV=True vendor/bin/php-cs-fixer fix --ansi
17+
dockerfile-checks:
18+
name: Dockerfile Checks
19+
runs-on: ubuntu-latest
20+
strategy:
21+
matrix:
22+
dockerfile:
23+
- docker/Dockerfile
24+
- docker/Dockerfile-standalone
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Lint with Hadolint
30+
uses: hadolint/[email protected]
31+
with:
32+
dockerfile: ${{ matrix.dockerfile }}
33+
failure-threshold: warning
34+
35+
- name: Set up Docker Buildx
36+
uses: docker/setup-buildx-action@v3
37+
38+
- name: Validate Dockerfile syntax
39+
run: |
40+
docker buildx build \
41+
--file ${{ matrix.dockerfile }} \
42+
--platform linux/amd64 \
43+
--check \
44+
.
4445
45-
phpunit:
46-
name: PHPUnit (PHP ${{ matrix.php }})
47-
runs-on: ubuntu-latest
48-
container:
49-
image: php:${{ matrix.php }}-alpine
50-
options: >-
51-
--tmpfs /tmp:exec
52-
--tmpfs /var/tmp:exec
53-
services:
54-
mysql:
55-
image: mariadb:10.11
56-
env:
57-
# Corresponds to what is in .env.test
58-
MYSQL_DATABASE: davis_test
59-
MYSQL_USER: davis
60-
MYSQL_PASSWORD: davis
61-
MYSQL_ROOT_PASSWORD: root
62-
options: >-
63-
--health-cmd "mysqladmin ping"
64-
--health-interval 10s
65-
--health-timeout 5s
66-
--health-retries 5
67-
ports:
68-
- 3306:3306
69-
strategy:
70-
matrix:
71-
php:
72-
- '8.2'
73-
- '8.3'
74-
- '8.4'
75-
fail-fast: false
76-
steps:
77-
- name: Checkout
78-
uses: actions/checkout@v4
79-
- name: Install MySQL / GD / ZIP PHP extensions
80-
run: |
81-
apk add $PHPIZE_DEPS icu-libs icu-dev libpng-dev libzip-dev
82-
docker-php-ext-configure intl
83-
docker-php-ext-configure gd
84-
docker-php-ext-configure zip
85-
docker-php-ext-install pdo pdo_mysql intl gd zip
86-
- name: Install Composer
87-
run: wget -qO - https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet
88-
- name: Install dependencies with Composer
89-
run: composer install --no-progress --no-interaction --ansi
90-
- name: Run tests with PHPUnit
91-
run: vendor/bin/phpunit --process-isolation --colors=always
46+
analyze:
47+
name: Analyze
48+
runs-on: ubuntu-latest
49+
container:
50+
image: php:8.3-alpine
51+
options: >-
52+
--tmpfs /tmp:exec
53+
--tmpfs /var/tmp:exec
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v4
57+
58+
- name: Install GD / ZIP PHP extension
59+
run: |
60+
apk add $PHPIZE_DEPS libpng-dev libzip-dev
61+
docker-php-ext-configure gd
62+
docker-php-ext-configure zip
63+
docker-php-ext-install gd zip
64+
65+
- name: Install Composer
66+
run: wget -qO - https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet
67+
68+
- name: Validate Composer
69+
run: composer validate
70+
71+
- name: Update to highest dependencies with Composer
72+
run: composer update --no-interaction --no-progress --ansi
73+
74+
- name: Analyze
75+
run: PHP_CS_FIXER_IGNORE_ENV=True vendor/bin/php-cs-fixer fix --ansi
76+
77+
phpunit:
78+
name: PHPUnit (PHP ${{ matrix.php }})
79+
runs-on: ubuntu-latest
80+
container:
81+
image: php:${{ matrix.php }}-alpine
82+
options: >-
83+
--tmpfs /tmp:exec
84+
--tmpfs /var/tmp:exec
85+
services:
86+
mysql:
87+
image: mariadb:10.11
88+
env:
89+
# Corresponds to what is in .env.test
90+
MYSQL_DATABASE: davis_test
91+
MYSQL_USER: davis
92+
MYSQL_PASSWORD: davis
93+
MYSQL_ROOT_PASSWORD: root
94+
options: >-
95+
--health-cmd "mysqladmin ping"
96+
--health-interval 10s
97+
--health-timeout 5s
98+
--health-retries 5
99+
ports:
100+
- 3306:3306
101+
102+
strategy:
103+
matrix:
104+
php:
105+
- '8.2'
106+
- '8.3'
107+
- '8.4'
108+
fail-fast: false
109+
110+
steps:
111+
- name: Checkout
112+
uses: actions/checkout@v4
113+
114+
- name: Install MySQL / GD / ZIP PHP extensions
115+
run: |
116+
apk add $PHPIZE_DEPS icu-libs icu-dev libpng-dev libzip-dev
117+
docker-php-ext-configure intl
118+
docker-php-ext-configure gd
119+
docker-php-ext-configure zip
120+
docker-php-ext-install pdo pdo_mysql intl gd zip
121+
122+
- name: Install Composer
123+
run: wget -qO - https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet
124+
125+
- name: Install dependencies with Composer
126+
run: composer install --no-progress --no-interaction --ansi
127+
128+
- name: Run tests with PHPUnit
129+
env:
130+
DATABASE_URL: mysql://davis:davis@mysql:3306/davis_test
131+
run: vendor/bin/phpunit --process-isolation --colors=always
132+
133+
migrations:
134+
name: Migrations (${{ matrix.database }})
135+
runs-on: ubuntu-latest
136+
container:
137+
image: php:8.3-alpine
138+
options: >-
139+
--tmpfs /tmp:exec
140+
--tmpfs /var/tmp:exec
141+
142+
services:
143+
mysql:
144+
image: mariadb:10.11
145+
env:
146+
MYSQL_DATABASE: davis_test
147+
MYSQL_USER: davis
148+
MYSQL_PASSWORD: davis
149+
MYSQL_ROOT_PASSWORD: root
150+
options: >-
151+
--health-cmd "mysqladmin ping"
152+
--health-interval 10s
153+
--health-timeout 5s
154+
--health-retries 5
155+
156+
postgres:
157+
image: postgres:15-alpine
158+
env:
159+
POSTGRES_DB: davis_test
160+
POSTGRES_USER: davis
161+
POSTGRES_PASSWORD: davis
162+
options: >-
163+
--health-cmd pg_isready
164+
--health-interval 10s
165+
--health-timeout 5s
166+
--health-retries 5
167+
168+
strategy:
169+
matrix:
170+
database:
171+
- mysql
172+
- postgresql
173+
- sqlite
174+
fail-fast: false
175+
176+
steps:
177+
- name: Checkout
178+
uses: actions/checkout@v4
179+
180+
- name: Install database extensions
181+
run: |
182+
apk add $PHPIZE_DEPS icu-libs icu-dev libpng-dev libzip-dev postgresql-dev sqlite-dev
183+
docker-php-ext-configure intl
184+
docker-php-ext-configure gd
185+
docker-php-ext-configure zip
186+
docker-php-ext-install pdo pdo_mysql pdo_pgsql pdo_sqlite intl gd zip
187+
188+
- name: Install Composer
189+
run: wget -qO - https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet
190+
191+
- name: Install dependencies with Composer
192+
run: composer install --no-progress --no-interaction --ansi
193+
194+
- name: Run migrations (MySQL)
195+
if: matrix.database == 'mysql'
196+
env:
197+
DATABASE_URL: mysql://davis:davis@mysql:3306/davis_test
198+
run: |
199+
php bin/console doctrine:database:create --if-not-exists --env=test
200+
php bin/console doctrine:migrations:migrate --no-interaction --env=test
201+
php bin/console doctrine:schema:validate --env=test
202+
203+
- name: Run migrations (PostgreSQL)
204+
if: matrix.database == 'postgresql'
205+
env:
206+
DATABASE_URL: postgresql://davis:davis@postgres:5432/davis_test?serverVersion=15&charset=utf8
207+
run: |
208+
php bin/console doctrine:database:create --if-not-exists --env=test
209+
php bin/console doctrine:migrations:migrate --no-interaction --env=test
210+
php bin/console doctrine:schema:validate --skip-sync --env=test
211+
212+
- name: Run migrations (SQLite)
213+
if: matrix.database == 'sqlite'
214+
env:
215+
DATABASE_URL: sqlite:///%kernel.project_dir%/var/data_test.db
216+
run: |
217+
php bin/console doctrine:migrations:migrate --no-interaction --env=test
218+
php bin/console doctrine:schema:validate --skip-sync --env=test
219+
220+
smoke-test:
221+
name: Application Smoke Test
222+
runs-on: ubuntu-latest
223+
container:
224+
image: php:8.3-alpine
225+
options: >-
226+
--tmpfs /tmp:exec
227+
--tmpfs /var/tmp:exec
228+
229+
services:
230+
mysql:
231+
image: mariadb:10.11
232+
env:
233+
MYSQL_DATABASE: davis_test
234+
MYSQL_USER: davis
235+
MYSQL_PASSWORD: davis
236+
MYSQL_ROOT_PASSWORD: root
237+
options: >-
238+
--health-cmd "mysqladmin ping"
239+
--health-interval 10s
240+
--health-timeout 5s
241+
--health-retries 5
242+
243+
steps:
244+
- name: Checkout
245+
uses: actions/checkout@v4
246+
247+
- name: Install extensions and curl
248+
run: |
249+
apk add $PHPIZE_DEPS icu-libs icu-dev libpng-dev libzip-dev curl
250+
docker-php-ext-configure intl
251+
docker-php-ext-configure gd
252+
docker-php-ext-configure zip
253+
docker-php-ext-install pdo pdo_mysql intl gd zip
254+
255+
- name: Install Composer
256+
run: wget -qO - https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --quiet
257+
258+
- name: Install dependencies with Composer
259+
run: composer install --no-progress --no-interaction --ansi --optimize-autoloader
260+
261+
- name: Prepare application
262+
env:
263+
DATABASE_URL: mysql://davis:davis@mysql:3306/davis_test
264+
APP_ENV: test
265+
run: |
266+
php bin/console doctrine:database:create --if-not-exists --env=test
267+
php bin/console doctrine:migrations:migrate --no-interaction --env=test
268+
php bin/console cache:clear --env=test
269+
270+
- name: Start Symfony server in background
271+
env:
272+
DATABASE_URL: mysql://davis:davis@mysql:3306/davis_test
273+
APP_ENV: test
274+
run: |
275+
php -S 127.0.0.1:8000 -t public/ &
276+
echo $! > server.pid
277+
sleep 3
278+
279+
- name: Test application responds
280+
run: |
281+
# Test that the app responds with a successful HTTP status
282+
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:8000/)
283+
echo "HTTP Response code: $RESPONSE"
284+
if [ "$RESPONSE" -ge 200 ] && [ "$RESPONSE" -lt 400 ]; then
285+
echo "✅ Application is responding correctly"
286+
else
287+
echo "❌ Application returned unexpected status code: $RESPONSE"
288+
exit 1
289+
fi
290+
291+
- name: Test dashboard
292+
continue-on-error: true
293+
run: |
294+
curl -f http://127.0.0.1:8000/dashboard || echo "No health endpoint available"
295+
296+
- name: Stop server
297+
if: always()
298+
run: |
299+
if [ -f server.pid ]; then
300+
kill $(cat server.pid) || true
301+
fi

0 commit comments

Comments
 (0)