Skip to content

Commit a44754a

Browse files
committed
CI/frontend-docker: test all environments with frontend image
1 parent 66653de commit a44754a

File tree

2 files changed

+167
-1
lines changed

2 files changed

+167
-1
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/bin/bash
2+
# Test frontend Docker image with specific environment configuration
3+
# Usage: ./test-frontend-docker.sh <image> <environment> [port]
4+
#
5+
# Parameters:
6+
# image - Docker image name/tag to test
7+
# environment - Frontend environment configuration (local, webnode, production, development, producer, fuzzing)
8+
# port - Optional port to use (default: 8080)
9+
#
10+
# Examples:
11+
# ./test-frontend-docker.sh o1labs/mina-rust-frontend:latest production
12+
# ./test-frontend-docker.sh test-frontend:local local 9090
13+
14+
set -euo pipefail
15+
16+
# Check arguments
17+
if [ $# -lt 2 ]; then
18+
echo "Usage: $0 <image> <environment> [port]"
19+
echo ""
20+
echo "Supported environments: local, webnode, production, development, producer, fuzzing"
21+
echo ""
22+
echo "Examples:"
23+
echo " $0 o1labs/mina-rust-frontend:latest production"
24+
echo " $0 test-frontend:local local 9090"
25+
exit 1
26+
fi
27+
28+
IMAGE="$1"
29+
ENVIRONMENT="$2"
30+
PORT="${3:-8080}"
31+
CONTAINER_NAME="test-frontend-${ENVIRONMENT}-$$"
32+
33+
# Supported environments
34+
SUPPORTED_ENVS="local webnode production development producer fuzzing"
35+
if [[ ! " $SUPPORTED_ENVS " =~ \ $ENVIRONMENT\ ]]; then
36+
echo "❌ Unsupported environment: $ENVIRONMENT"
37+
echo "Supported environments: $SUPPORTED_ENVS"
38+
exit 1
39+
fi
40+
41+
echo "🧪 Testing frontend image with environment: $ENVIRONMENT"
42+
echo "📦 Image: $IMAGE"
43+
echo "🔌 Port: $PORT"
44+
echo "📝 Container: $CONTAINER_NAME"
45+
echo ""
46+
47+
# Cleanup function
48+
cleanup() {
49+
echo "🧹 Cleaning up container: $CONTAINER_NAME"
50+
docker stop "$CONTAINER_NAME" 2>/dev/null || true
51+
docker rm "$CONTAINER_NAME" 2>/dev/null || true
52+
}
53+
54+
# Set up cleanup trap
55+
trap cleanup EXIT
56+
57+
# Check if port is available
58+
if ss -tuln | grep -q ":$PORT "; then
59+
echo "❌ Port $PORT is already in use"
60+
exit 1
61+
fi
62+
63+
# Run the container with the specific environment configuration
64+
echo "🚀 Starting container..."
65+
docker run --rm -d \
66+
--name "$CONTAINER_NAME" \
67+
-p "$PORT:80" \
68+
-e MINA_FRONTEND_ENVIRONMENT="$ENVIRONMENT" \
69+
"$IMAGE"
70+
71+
# Wait a moment for container to start
72+
echo "⏳ Waiting for container to initialize..."
73+
sleep 10
74+
75+
# Check if container is running
76+
if ! docker ps | grep -q "$CONTAINER_NAME"; then
77+
echo "❌ Container failed to start with environment: $ENVIRONMENT"
78+
echo "📋 Container logs:"
79+
docker logs "$CONTAINER_NAME" || echo "No logs available"
80+
exit 1
81+
fi
82+
83+
echo "✅ Container started successfully with environment: $ENVIRONMENT"
84+
85+
# Test HTTP endpoint with retries (30 attempts with 3 second intervals = ~90s total)
86+
RETRY_COUNT=0
87+
MAX_RETRIES=30
88+
SUCCESS=false
89+
90+
echo "🔍 Testing HTTP endpoint with retries (max $MAX_RETRIES attempts)..."
91+
92+
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
93+
if curl -f -s -m 5 "http://localhost:$PORT/" > /dev/null 2>&1; then
94+
echo "✅ HTTP endpoint is responding for environment: $ENVIRONMENT (attempt $((RETRY_COUNT + 1)))"
95+
SUCCESS=true
96+
break
97+
else
98+
RETRY_COUNT=$((RETRY_COUNT + 1))
99+
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
100+
echo "❌ HTTP endpoint not ready after $MAX_RETRIES attempts"
101+
else
102+
echo "⏳ HTTP endpoint not ready, attempt $RETRY_COUNT/$MAX_RETRIES for environment: $ENVIRONMENT"
103+
sleep 3
104+
fi
105+
fi
106+
done
107+
108+
if [ "$SUCCESS" = false ]; then
109+
echo "❌ HTTP endpoint failed after $MAX_RETRIES attempts for environment: $ENVIRONMENT"
110+
echo "📋 Container logs:"
111+
docker logs "$CONTAINER_NAME"
112+
exit 1
113+
fi
114+
115+
echo "🎉 Test completed successfully for environment: $ENVIRONMENT"
116+
echo ""
117+
echo "🌐 Frontend is available at: http://localhost:$PORT/"
118+
echo "🔍 To view logs: docker logs $CONTAINER_NAME"
119+
echo "🛑 Container will be automatically stopped when script exits"

.github/workflows/docker.yaml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,59 @@ jobs:
122122
if-no-files-found: error
123123
retention-days: 1
124124

125+
# Test frontend image with all environment configurations
126+
test-frontend-image:
127+
runs-on: ubuntu-latest
128+
if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/release')
129+
needs:
130+
- build-mina-frontend-image
131+
strategy:
132+
matrix:
133+
environment: [local, webnode, production, development, producer, fuzzing]
134+
steps:
135+
- name: Git checkout
136+
uses: actions/checkout@v5
137+
138+
- name: Download frontend digest artifacts
139+
uses: actions/download-artifact@v4
140+
with:
141+
path: /tmp/digests
142+
pattern: frontend-*-digests-*
143+
merge-multiple: true
144+
145+
- name: Set up Docker Buildx
146+
uses: docker/setup-buildx-action@v3
147+
148+
- name: Login to Docker Hub
149+
uses: docker/login-action@v3
150+
with:
151+
username: ${{ secrets.DOCKERHUB_USERNAME }}
152+
password: ${{ secrets.DOCKERHUB_TOKEN }}
153+
154+
- name: Get image digest
155+
id: digest
156+
run: |
157+
# Get the first digest from artifacts (we'll test with amd64)
158+
DIGEST=$(ls /tmp/digests | head -1)
159+
echo "digest=sha256:${DIGEST}" >> $GITHUB_OUTPUT
160+
161+
- name: Test frontend image with ${{ matrix.environment }} environment
162+
run: |
163+
# Pull the image by digest
164+
docker pull ${{ env.REGISTRY_FRONTEND_IMAGE }}@${{ steps.digest.outputs.digest }}
165+
166+
# Tag it for easier reference
167+
docker tag ${{ env.REGISTRY_FRONTEND_IMAGE }}@${{ steps.digest.outputs.digest }} test-frontend:${{ matrix.environment }}
168+
169+
# Run the test script
170+
./.github/scripts/docker/test-frontend-docker.sh test-frontend:${{ matrix.environment }} ${{ matrix.environment }}
171+
125172
# Push frontend multi-arch manifest
126173
push-frontend-image:
127174
runs-on: ubuntu-latest
128175
if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/release')
129176
needs:
130-
- build-mina-frontend-image
177+
- test-frontend-image
131178
steps:
132179
- name: Git checkout
133180
uses: actions/checkout@v5

0 commit comments

Comments
 (0)