|
1 | 1 | ############################################################################### |
2 | | -# 1. BUILD STAGE – uses the official Flutter image (Linux) # |
| 2 | +# 1 ─ BUILD STAGE # |
3 | 3 | ############################################################################### |
4 | | -FROM cirrusci/flutter:3.22 as build |
| 4 | +# Use the official Flutter image with the latest stable SDK (3.22 at July 2025) |
| 5 | +FROM cirrusci/flutter:3.22 AS build |
| 6 | + |
| 7 | +# Set working directory inside the container |
5 | 8 | WORKDIR /app |
6 | 9 |
|
7 | | -# copy source and download dependencies once |
| 10 | +# --- Caching trick: copy pubspec first, fetch deps, then rest of the code ---- |
8 | 11 | COPY pubspec.* ./ |
9 | 12 | RUN flutter pub get |
10 | 13 |
|
11 | | -# copy the rest of the project |
| 14 | +# Copy the rest of the sources and build the web release bundle |
12 | 15 | COPY . . |
13 | | - |
14 | | -# build the web release bundle |
15 | | -RUN flutter build web --release |
| 16 | +RUN flutter build web --release # output → build/web |
16 | 17 |
|
17 | 18 | ############################################################################### |
18 | | -# 2. RUNTIME STAGE – serve with Nginx (tiny image) # |
| 19 | +# 2 ─ RUNTIME STAGE (static site) # |
19 | 20 | ############################################################################### |
20 | 21 | FROM nginx:stable-alpine |
21 | | -# Remove default html |
22 | | -RUN rm -rf /usr/share/nginx/html/* |
23 | 22 |
|
24 | | -# Copy Flutter build output to Nginx web root |
| 23 | +# Remove default Nginx html & copy Flutter build |
| 24 | +RUN rm -rf /usr/share/nginx/html/* |
25 | 25 | COPY --from=build /app/build/web /usr/share/nginx/html |
26 | 26 |
|
27 | 27 | # Expose web port |
28 | 28 | EXPOSE 80 |
29 | 29 |
|
30 | | -# Start Nginx (Render detects the CMD automatically) |
| 30 | +# Start Nginx in the foreground (Render auto-detects this) |
31 | 31 | CMD ["nginx", "-g", "daemon off;"] |
0 commit comments