Skip to content

Merge pull request #268 from helpfulengineering/guard-deploy-environment #144

Merge pull request #268 from helpfulengineering/guard-deploy-environment

Merge pull request #268 from helpfulengineering/guard-deploy-environment #144

name: Docker Build and Test
on:
pull_request:
branches: [main, dev]
push:
branches: [main]
workflow_dispatch:
env:
IMAGE: supply-graph-ai
jobs:
docker-test:
name: Test Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Read expected version from pyproject.toml
id: version
run: |
VERSION=$(grep -E '^version = ' pyproject.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "expected=$VERSION" >> "$GITHUB_OUTPUT"
echo "Expected app version: $VERSION"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: .
push: false
load: true
tags: ${{ env.IMAGE }}:test
build-args: |
APP_VERSION=${{ steps.version.outputs.expected }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test Docker image
run: |
docker run -d \
--name test-container \
-p 8001:8001 \
-e ENVIRONMENT=test \
-e LOG_LEVEL=INFO \
-e STORAGE_PROVIDER=local \
-e LLM_ENABLED=false \
${{ env.IMAGE }}:test
- name: Wait for container to be ready
run: |
timeout=60
elapsed=0
while [ $elapsed -lt $timeout ]; do
if curl -f http://localhost:8001/health > /dev/null 2>&1; then
echo "Container is ready"
exit 0
fi
echo "Waiting for container... ($elapsed/$timeout seconds)"
sleep 2
elapsed=$((elapsed + 2))
done
echo "Container failed to start within $timeout seconds"
docker logs test-container
exit 1
- name: Run health checks
run: |
EXPECTED="${{ steps.version.outputs.expected }}"
BODY=$(curl -sf http://localhost:8001/health)
echo "$BODY"
ACTUAL=$(echo "$BODY" | python3 -c "import sys,json; print(json.load(sys.stdin)['version'])")
echo "version=$ACTUAL (expected $EXPECTED)"
test "$ACTUAL" = "$EXPECTED"
curl -f http://localhost:8001/health/liveness
curl -f http://localhost:8001/health/readiness || echo "Readiness check returned non-zero (expected in test environment)"
- name: Test metrics endpoint
run: |
curl -f http://localhost:8001/v1/api/utility/metrics?format=json
curl -f http://localhost:8001/v1/api/utility/metrics?format=prometheus
- name: Check container logs
if: failure()
run: |
echo "=== Container Logs ==="
docker logs test-container
echo "=== Container Status ==="
docker ps -a
- name: Cleanup
if: always()
run: |
docker stop test-container || true
docker rm test-container || true