Skip to content

Commit 6849cf5

Browse files
authored
Merge pull request #1473 from o1-labs/dw/dockerfile-frontend
Frontend: revamp Docker and make the node dashboard ready
2 parents 4decfe3 + 33bffbf commit 6849cf5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1817
-474
lines changed

.dockerignore

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ tools/heartbeats-processor/*.db
3131
# Ensure .sqlx files are included
3232
!tools/heartbeats-processor/.sqlx/
3333

34-
# Will be copied on demand in the Docker image, if necessary
35-
circuit-blobs
36-
3734
# GH workflows
3835
.claude
3936
.github
@@ -65,6 +62,11 @@ tests.tsv
6562

6663
# The website must not be included
6764
website
65+
## Ignore some scripts that can be used in the Docker images.
66+
## These scripts are used to be consistent with what is on the website and what
67+
## is actually used.
68+
!./website/docs/developers/scripts/frontend/install-nodejs-linux.sh
69+
!./website/docs/developers/scripts/frontend/install-angular-cli.sh
6870

6971
# NPM related
7072
node_modules
@@ -75,4 +77,4 @@ frontend/.gitignore
7577
frontend/.vscode
7678
frontend/dist/frontend
7779
frontend/Dockerfile
78-
frontend/node_modules
80+
frontend/node_modules

.github/actions/frontend-build/action.yml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ runs:
4848
working-directory: frontend
4949
shell: bash
5050

51-
# Test Makefile targets
51+
# Test Makefile targets (alphabetical order)
5252
- name: Test make build
5353
if: inputs.test-build-commands == 'true'
5454
run: |
@@ -58,13 +58,12 @@ runs:
5858
working-directory: frontend
5959
shell: bash
6060

61-
62-
- name: Test make build-development
61+
- name: Test make build-block-producers
6362
if: inputs.test-build-commands == 'true'
6463
run: |
6564
rm -rf dist
66-
make build-development
67-
[ -d "dist/frontend" ] || { echo "Error: make build-development failed"; exit 1; }
65+
make build-block-producers
66+
[ -d "dist/frontend" ] || { echo "Error: make build-block-producers failed"; exit 1; }
6867
working-directory: frontend
6968
shell: bash
7069

@@ -77,24 +76,25 @@ runs:
7776
working-directory: frontend
7877
shell: bash
7978

80-
- name: Test make build-local
79+
- name: Test make build-leaderboard
8180
if: inputs.test-build-commands == 'true'
8281
run: |
8382
rm -rf dist
84-
make build-local
85-
[ -d "dist/frontend" ] || { echo "Error: make build-local failed"; exit 1; }
83+
make build-leaderboard
84+
[ -d "dist/frontend" ] || { echo "Error: make build-leaderboard failed"; exit 1; }
8685
working-directory: frontend
8786
shell: bash
8887

89-
- name: Test make build-prod
88+
- name: Test make build-local
9089
if: inputs.test-build-commands == 'true'
9190
run: |
9291
rm -rf dist
93-
make build-prod
94-
[ -d "dist/frontend" ] || { echo "Error: make build-prod failed"; exit 1; }
92+
make build-local
93+
[ -d "dist/frontend" ] || { echo "Error: make build-local failed"; exit 1; }
9594
working-directory: frontend
9695
shell: bash
9796

97+
9898
- name: Test make build-producer
9999
if: inputs.test-build-commands == 'true'
100100
run: |
@@ -113,15 +113,25 @@ runs:
113113
working-directory: frontend
114114
shell: bash
115115

116-
- name: Test make build-webnodelocal
116+
- name: Test make build-staging
117117
if: inputs.test-build-commands == 'true'
118118
run: |
119119
rm -rf dist
120-
make build-webnodelocal
121-
[ -d "dist/frontend" ] || { echo "Error: make build-webnodelocal failed"; exit 1; }
120+
make build-staging
121+
[ -d "dist/frontend" ] || { echo "Error: make build-staging failed"; exit 1; }
122122
working-directory: frontend
123123
shell: bash
124124

125+
- name: Test make build-webnode
126+
if: inputs.test-build-commands == 'true'
127+
run: |
128+
rm -rf dist
129+
make build-webnode
130+
[ -d "dist/frontend" ] || { echo "Error: make build-webnode failed"; exit 1; }
131+
working-directory: frontend
132+
shell: bash
133+
134+
125135
- name: Run tests
126136
if: inputs.run-tests == 'true'
127137
uses: cypress-io/github-action@v6
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: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ jobs:
7575
runs-on: ubuntu-latest
7676
- platform: linux/arm64
7777
runs-on: ubuntu-24.04-arm
78-
configuration:
79-
- build_configuration: production
8078
runs-on: ${{ matrix.arch.runs-on }}
8179
steps:
8280
- name: Prepare
@@ -96,14 +94,20 @@ jobs:
9694
- name: Set up Docker Buildx
9795
uses: docker/setup-buildx-action@v3
9896

97+
- name: Download circuits files
98+
uses: ./.github/actions/setup-circuits
99+
100+
- name: Generate .env.docker
101+
run: |
102+
bash ./frontend/docker/generate-docker-env.sh
103+
99104
- name: Build Docker image
100105
id: build
101106
uses: docker/build-push-action@v6
102107
with:
103-
context: ./frontend
108+
context: ./
109+
file: ./frontend/Dockerfile
104110
platforms: ${{ matrix.arch.platform }}
105-
build-args: |
106-
BUILD_CONFIGURATION=${{ matrix.configuration.build_configuration }}
107111
cache-from: type=gha
108112
cache-to: type=gha,mode=max
109113
outputs: type=image,name=${{ env.REGISTRY_FRONTEND_IMAGE }},push-by-digest=true,name-canonical=true,push=true
@@ -117,17 +121,64 @@ jobs:
117121
- name: Upload digest
118122
uses: actions/upload-artifact@v4
119123
with:
120-
name: frontend-${{ matrix.configuration.build_configuration }}-digests-${{ env.PLATFORM_PAIR }}
124+
name: frontend-digests-${{ env.PLATFORM_PAIR }}
121125
path: /tmp/digests/*
122126
if-no-files-found: error
123127
retention-days: 1
124128

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

.github/workflows/frontend.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ on:
33
push:
44
branches: [ main, develop ]
55
pull_request:
6-
paths: [ "frontend/**", ".github/frontend.yaml" ]
76
workflow_dispatch:
87

98
concurrency:

0 commit comments

Comments
 (0)