Skip to content

Commit

Permalink
Update CI for Docker build
Browse files Browse the repository at this point in the history
Signed-off-by: MadCat34 <[email protected]>
  • Loading branch information
Romain Bastide authored and MadCat34 committed Dec 18, 2024
1 parent e89f80d commit 3254a1d
Showing 1 changed file with 58 additions and 6 deletions.
64 changes: 58 additions & 6 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,66 @@ on:
types: [opened, reopened]

jobs:
build:
lint:
name: Lint Dockerfile
runs-on: ubuntu-latest

steps:
- name: "Checkout"
uses: "actions/checkout@v4"
- name: Checkout
uses: actions/checkout@v4

- name: Build and run docker compose file
- 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 compose up -d --build
docker compose run laminas echo "ok"
docker ps
docker stop laminas-test-${{ matrix.target.name }}

0 comments on commit 3254a1d

Please sign in to comment.