|
1 |
| -# Doesn't matter what we put here - it get's overwritten by the docker \ |
2 |
| -# build command |
3 |
| -FROM node:23 AS build_image |
| 1 | +# ============================================================================= |
| 2 | +# Mina Frontend Docker Image |
| 3 | +# ============================================================================= |
| 4 | +# |
| 5 | +# This Dockerfile creates a production-ready Apache HTTP server image that serves |
| 6 | +# the Mina frontend application with pre-built WebAssembly (WASM) components. |
| 7 | +# |
| 8 | +# IMAGE STAGES: |
| 9 | +# 1. build_frontend - Compiles Angular frontend application |
| 10 | +# 2. build_wasm - Builds WebAssembly files for web node functionality |
| 11 | +# 3. wasm_files - Extracts only WASM artifacts (size optimization) |
| 12 | +# 4. final - Apache HTTP server with frontend and WASM assets |
| 13 | +# |
| 14 | +# FEATURES: |
| 15 | +# - Multi-stage build for optimized image size |
| 16 | +# - Pre-built WASM files for Mina web node |
| 17 | +# - Environment-specific configuration support |
| 18 | +# - Caching optimization for web assets |
| 19 | +# - WebRTC signaling configuration |
| 20 | +# |
| 21 | +# BUILD ARGUMENTS: |
| 22 | +# BUILD_CONFIGURATION - Angular build configuration (default: production) |
| 23 | +# |
| 24 | +# USAGE: |
| 25 | +# # Build frontend image |
| 26 | +# docker build -t mina-frontend . |
| 27 | +# |
| 28 | +# # Run with webnode environment |
| 29 | +# docker run -p 80:80 -e MINA_FRONTEND_ENVIRONMENT=webnode mina-frontend |
| 30 | +# |
| 31 | +# ============================================================================= |
| 32 | + |
| 33 | +# Build arguments |
4 | 34 | ARG BUILD_CONFIGURATION=production
|
5 |
| -WORKDIR /app |
6 |
| -COPY . . |
| 35 | + |
| 36 | +# Build stage for Angular frontend |
| 37 | +FROM node:23 AS build_frontend |
| 38 | +ARG BUILD_CONFIGURATION |
| 39 | +WORKDIR /app/frontend |
| 40 | +COPY frontend/ . |
7 | 41 | RUN npm install && \
|
8 | 42 | node_modules/.bin/ng build --configuration \
|
9 | 43 | ${BUILD_CONFIGURATION} && \
|
10 | 44 | npm prune --production && \
|
11 |
| - echo "---------- USING APACHE ----------" |
| 45 | + echo "---------- FRONTEND BUILD COMPLETE ----------" |
| 46 | + |
| 47 | +# Build stage for WASM files |
| 48 | +FROM rust:latest AS build_wasm |
| 49 | +# IMPORTANT: The nightly version should match the version specified in: |
| 50 | +# - Makefile (NIGHTLY_RUST_VERSION) |
| 51 | +# - .github/workflows/ci.yaml |
| 52 | +# - .github/workflows/fmt.yaml |
| 53 | +# - .github/workflows/lint.yaml |
| 54 | +# - frontend/Dockerfile (this file) |
| 55 | + |
| 56 | +# Install system dependencies required for building WASM |
| 57 | +RUN apt-get update && \ |
| 58 | + apt-get install -y --no-install-recommends \ |
| 59 | + build-essential \ |
| 60 | + libssl-dev \ |
| 61 | + pkg-config \ |
| 62 | + protobuf-compiler \ |
| 63 | + sqlite3 && \ |
| 64 | + rm -rf /var/lib/apt/lists/* |
| 65 | + |
| 66 | +# Install Rust nightly and WASM target |
| 67 | +RUN rustup toolchain install nightly && \ |
| 68 | + rustup default nightly && \ |
| 69 | + rustup target add wasm32-unknown-unknown && \ |
| 70 | + cargo install wasm-bindgen-cli |
12 | 71 |
|
| 72 | +WORKDIR /app |
| 73 | +COPY . . |
| 74 | +RUN make build-wasm && \ |
| 75 | + echo "---------- WASM BUILD COMPLETE ----------" |
13 | 76 |
|
| 77 | +# Extract WASM files stage |
| 78 | +FROM scratch AS wasm_files |
| 79 | +COPY --from=build_wasm /app/node/web/pkg /pkg |
| 80 | + |
| 81 | +# Circuit files stage |
| 82 | +FROM alpine:latest AS circuit_files |
| 83 | +WORKDIR /circuit-blobs |
| 84 | +COPY circuit-blobs/3.0.1devnet/ . |
| 85 | +# Remove the symbolic link that might cause issues |
| 86 | +RUN rm -f tests |
| 87 | + |
| 88 | +# Final Apache image |
14 | 89 | FROM httpd:2.4
|
15 | 90 |
|
16 | 91 | # hadolint ignore=DL3008
|
17 | 92 | RUN apt-get update && \
|
18 | 93 | apt-get install -y --no-install-recommends curl && \
|
19 | 94 | rm -rf /var/lib/apt/lists/*
|
20 | 95 |
|
21 |
| -COPY --from=BUILD_IMAGE /app/dist/frontend/browser \ |
| 96 | +# Copy frontend assets |
| 97 | +COPY --from=build_frontend /app/frontend/dist/frontend/browser \ |
22 | 98 | /usr/local/apache2/htdocs/
|
23 |
| -COPY --from=BUILD_IMAGE /app/httpd.conf \ |
| 99 | +COPY --from=build_frontend /app/frontend/httpd.conf \ |
24 | 100 | /usr/local/apache2/conf/httpd.conf
|
25 | 101 |
|
26 |
| -COPY docker/startup.sh /usr/local/bin/startup.sh |
27 |
| -RUN chmod +x /usr/local/bin/startup.sh |
| 102 | +# Copy WASM files to webnode assets directory |
| 103 | +COPY --from=wasm_files /pkg \ |
| 104 | + /usr/local/apache2/htdocs/assets/webnode/pkg |
| 105 | + |
| 106 | +# Copy circuit files for webnode |
| 107 | +RUN mkdir -p /usr/local/apache2/htdocs/assets/webnode/circuit-blobs/3.0.1devnet |
| 108 | +COPY --from=circuit_files /circuit-blobs/ \ |
| 109 | + /usr/local/apache2/htdocs/assets/webnode/circuit-blobs/3.0.1devnet/ |
28 | 110 |
|
29 |
| -ENTRYPOINT ["/usr/local/bin/startup.sh"] |
| 111 | +# Add labels for image metadata |
| 112 | +LABEL mina.circuit-files-included="true" |
| 113 | +LABEL mina.image-type="frontend" |
| 114 | +LABEL mina.components="angular,wasm,circuits" |
30 | 115 |
|
31 | 116 | CMD ["httpd-foreground"]
|
0 commit comments