Better docker support #64
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |