Skip to content

Commit 4daffad

Browse files
committed
feat: improve code quality, CI/CD pipelines and health monitoring
- Add GitLab CI support and improve GitHub Actions workflows - Enhance health.php with SOLID architecture and comprehensive checks - Fix Dockerfile linting issues and PHPIZE_DEPS build error - Update TESTING.md with new CI/CD procedures - Improve Makefile with health monitoring targets BREAKING CHANGE: Replace docker-publish.yml with test.yml workflow
1 parent 1e72cfa commit 4daffad

7 files changed

Lines changed: 1210 additions & 309 deletions

File tree

.github/workflows/docker-publish.yml

Whitespace-only changes.

.github/workflows/test.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Test PHP API Stack
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
jobs:
11+
lint:
12+
name: Lint Dockerfile
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- name: Run hadolint
18+
run: make lint
19+
20+
build:
21+
name: Build Image
22+
needs: lint
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v3
26+
27+
- name: Build production image
28+
run: make build
29+
30+
- name: Quick component tests
31+
run: make test-quick
32+
33+
- name: Save image
34+
run: docker save kariricode/php-api-stack:latest | gzip > image.tar.gz
35+
36+
- name: Upload artifact
37+
uses: actions/upload-artifact@v3
38+
with:
39+
name: docker-image
40+
path: image.tar.gz
41+
42+
test:
43+
name: Run Tests
44+
needs: build
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v3
48+
49+
- name: Download image
50+
uses: actions/download-artifact@v3
51+
with:
52+
name: docker-image
53+
54+
- name: Load image
55+
run: docker load < image.tar.gz
56+
57+
- name: Run comprehensive tests
58+
run: make test
59+
60+
- name: Run integration tests
61+
run: |
62+
make run
63+
sleep 10
64+
curl -f http://localhost:8080
65+
curl -f http://localhost:8080/health
66+
make stop
67+
68+
test-health:
69+
name: Test Health Checks
70+
needs: build
71+
runs-on: ubuntu-latest
72+
steps:
73+
- uses: actions/checkout@v3
74+
75+
- name: Download image
76+
uses: actions/download-artifact@v3
77+
with:
78+
name: docker-image
79+
80+
- name: Load image
81+
run: docker load < image.tar.gz
82+
83+
- name: Build test image
84+
run: make build-test-image
85+
86+
- name: Run test container
87+
run: make run-test
88+
89+
- name: Test comprehensive health check
90+
run: |
91+
sleep 10
92+
make test-health
93+
curl -s http://localhost:8080/health.php | jq '.status' | grep -q "healthy"
94+
95+
- name: Stop test container
96+
run: make stop-test
97+
98+
security:
99+
name: Security Scan
100+
needs: build
101+
runs-on: ubuntu-latest
102+
steps:
103+
- uses: actions/checkout@v3
104+
105+
- name: Download image
106+
uses: actions/download-artifact@v3
107+
with:
108+
name: docker-image
109+
110+
- name: Load image
111+
run: docker load < image.tar.gz
112+
113+
- name: Run Trivy scan
114+
uses: aquasecurity/trivy-action@master
115+
with:
116+
image-ref: "kariricode/php-api-stack:latest"
117+
format: "sarif"
118+
output: "trivy-results.sarif"
119+
severity: "CRITICAL,HIGH"
120+
121+
- name: Upload Trivy results
122+
uses: github/codeql-action/upload-sarif@v2
123+
with:
124+
sarif_file: "trivy-results.sarif"

.gitlab-ci.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
stages:
2+
- lint
3+
- build
4+
- test
5+
- security
6+
7+
variables:
8+
DOCKER_DRIVER: overlay2
9+
IMAGE_NAME: kariricode/php-api-stack
10+
11+
lint:dockerfile:
12+
stage: lint
13+
image: hadolint/hadolint:latest
14+
script:
15+
- hadolint Dockerfile
16+
only:
17+
- merge_requests
18+
- main
19+
- develop
20+
21+
build:production:
22+
stage: build
23+
image: docker:latest
24+
services:
25+
- docker:dind
26+
script:
27+
- make build
28+
- docker save $IMAGE_NAME:latest | gzip > image.tar.gz
29+
artifacts:
30+
paths:
31+
- image.tar.gz
32+
- VERSION
33+
expire_in: 1 hour
34+
35+
test:quick:
36+
stage: test
37+
image: docker:latest
38+
services:
39+
- docker:dind
40+
dependencies:
41+
- build:production
42+
script:
43+
- docker load < image.tar.gz
44+
- make test-quick
45+
46+
test:full:
47+
stage: test
48+
image: docker:latest
49+
services:
50+
- docker:dind
51+
dependencies:
52+
- build:production
53+
script:
54+
- docker load < image.tar.gz
55+
- make test
56+
57+
test:integration:
58+
stage: test
59+
image: docker:latest
60+
services:
61+
- docker:dind
62+
dependencies:
63+
- build:production
64+
script:
65+
- docker load < image.tar.gz
66+
- make run
67+
- sleep 10
68+
- curl -f http://localhost:8080
69+
- curl -f http://localhost:8080/health
70+
- make stop
71+
72+
test:health:
73+
stage: test
74+
image: docker:latest
75+
services:
76+
- docker:dind
77+
dependencies:
78+
- build:production
79+
script:
80+
- docker load < image.tar.gz
81+
- make build-test-image
82+
- make run-test
83+
- sleep 10
84+
- make test-health
85+
- make stop-test
86+
87+
security:trivy:
88+
stage: security
89+
image: aquasec/trivy:latest
90+
dependencies:
91+
- build:production
92+
script:
93+
- docker load < image.tar.gz
94+
- trivy image --severity HIGH,CRITICAL --exit-code 1 $IMAGE_NAME:latest
95+
allow_failure: false

0 commit comments

Comments
 (0)