Fix GitHub Actions workflow: container build and test
- Add 'load: true' to docker/build-push-action to ensure image is available in local Docker daemon - Improve container testing with retry logic and better error handling - Add container logs output on test failure for better debugging
This commit is contained in:
24
.github/workflows/build-container.yml
vendored
24
.github/workflows/build-container.yml
vendored
@@ -53,16 +53,34 @@ jobs:
|
|||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
push: false
|
push: false
|
||||||
|
load: true
|
||||||
tags: ${{ env.IMAGE_NAME }}:latest
|
tags: ${{ env.IMAGE_NAME }}:latest
|
||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
- name: Test container
|
- name: Test container
|
||||||
run: |
|
run: |
|
||||||
|
# Start the container
|
||||||
docker run --rm -d -p 3000:3000 --name test-container ${{ env.IMAGE_NAME }}:latest
|
docker run --rm -d -p 3000:3000 --name test-container ${{ env.IMAGE_NAME }}:latest
|
||||||
sleep 10
|
|
||||||
# Test if the container is responding
|
# Wait for container to be ready
|
||||||
curl -f http://localhost:3000 || exit 1
|
echo "Waiting for container to start..."
|
||||||
|
for i in {1..30}; do
|
||||||
|
if curl -f http://localhost:3000 > /dev/null 2>&1; then
|
||||||
|
echo "Container is responding!"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
if [ $i -eq 30 ]; then
|
||||||
|
echo "Container failed to respond within 30 seconds"
|
||||||
|
docker logs test-container
|
||||||
|
docker stop test-container
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Attempt $i/30 - waiting..."
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
# Test successful, stop container
|
||||||
docker stop test-container
|
docker stop test-container
|
||||||
|
|
||||||
- name: Upload build artifacts
|
- name: Upload build artifacts
|
||||||
|
|||||||
Reference in New Issue
Block a user