-
-
Notifications
You must be signed in to change notification settings - Fork 65
73 lines (61 loc) · 2.21 KB
/
docker-build.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
name: docker-build
on:
push:
branches:
- '*'
pull_request:
types: [opened, reopened]
jobs:
lint:
name: Lint Dockerfile
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lint Dockerfile
uses: hadolint/[email protected]
with:
recursive: true
build_and_test:
name: Build and Test Docker Images
runs-on: ubuntu-latest
strategy:
matrix:
target:
- { name: dev, port: 8080 }
- { name: prod, port: 8081 }
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build image for ${{ matrix.target.name }}
run: docker buildx build --target ${{ matrix.target.name }} -t laminas:${{ matrix.target.name }} .
- name: PHPUnit for dev only
if: matrix.target.name == 'dev'
run: docker run --rm laminas:${{ matrix.target.name }} vendor/bin/phpunit module/*/test
- name: Start container for ${{ matrix.target.name }}
run: docker run --rm -d -p ${{ matrix.target.port }}:80 --name laminas-test-${{ matrix.target.name }} laminas:${{ matrix.target.name }}
- name: Check HTTP status
run: |
retries=15
while [ $retries -gt 0 ]; do
http_status_code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:${{ matrix.target.port }})
response_body=$(curl -s http://localhost:${{ matrix.target.port }})
if [ "$http_status_code" -eq 200 ] && [[ "$response_body" =~ "Welcome" ]]; then
echo "HTTP status code: $http_status_code"
echo "Response body: $response_body"
break
fi
echo "Waiting for service to be ready..."
sleep 10
retries=$((retries-1))
done
if [ $retries -eq 0 ]; then
echo "Service did not start successfully."
echo "HTTP status code: $http_status_code"
echo "Response body: $response_body"
exit 1
fi
- name: Stop and remove container for ${{ matrix.target.name }}
run: |
docker ps
docker stop laminas-test-${{ matrix.target.name }}