🐋 Container Validation • main #5
This file contains hidden or 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 Validation | |
| run-name: 🐋 Container Validation • ${{ github.ref_name }} | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - develop | |
| - dev | |
| pull_request: | |
| branches: | |
| - main | |
| - develop | |
| - dev | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| validate: | |
| name: 🐋 Validate Development and Production Images | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 📥 Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: 🐋 Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: ✅ Build validation stage | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| target: validation | |
| push: false | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: 🏗️ Build production-preview image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| target: production | |
| load: true | |
| push: false | |
| tags: devalltect00-docs-prod:ci | |
| cache-from: type=gha | |
| - name: 🚀 Start production-preview image | |
| id: preview | |
| run: | | |
| container_id="$(docker run --detach --publish 8080:8080 devalltect00-docs-prod:ci)" | |
| echo "container_id=$container_id" >> "$GITHUB_OUTPUT" | |
| - name: 🔎 Smoke-test static site | |
| run: | | |
| container_id="${{ steps.preview.outputs.container_id }}" | |
| for attempt in $(seq 1 60); do | |
| container_status="$(docker inspect --format='{{.State.Status}}' "$container_id")" | |
| health_status="$(docker inspect --format='{{if .State.Health}}{{.State.Health.Status}}{{else}}unavailable{{end}}' "$container_id")" | |
| if [ "$health_status" = "healthy" ]; then | |
| break | |
| fi | |
| if [ "$container_status" != "running" ] || [ "$health_status" = "unhealthy" ]; then | |
| echo "Container failed before the smoke test completed." | |
| docker logs "$container_id" | |
| docker inspect "$container_id" | |
| exit 1 | |
| fi | |
| if [ "$attempt" -eq 60 ]; then | |
| echo "Timed out waiting for the container to become healthy." | |
| docker logs "$container_id" | |
| docker inspect "$container_id" | |
| exit 1 | |
| fi | |
| sleep 1 | |
| done | |
| curl --fail --show-error --silent --retry 5 --retry-delay 1 --retry-all-errors \ | |
| http://127.0.0.1:8080/healthz | |
| curl --fail --show-error --silent --retry 5 --retry-delay 1 --retry-all-errors \ | |
| http://127.0.0.1:8080/devalltect-docs/ | |
| - name: 🧹 Stop production-preview image | |
| if: always() && steps.preview.outputs.container_id != '' | |
| run: docker rm --force "${{ steps.preview.outputs.container_id }}" |