# Stage 1: Build Flutter web application FROM ghcr.io/cirruslabs/flutter:stable AS builder WORKDIR /app # VERSION arg busts cache when version changes in pubspec.yaml # Extract version: docker build --build-arg VERSION=$(grep '^version:' pubspec.yaml | cut -d' ' -f2) . ARG VERSION=0.0.0 RUN echo "Building version: $VERSION" # Copy dependency files first for better caching COPY pubspec.yaml pubspec.lock* ./ # Get dependencies RUN flutter pub get # Copy the rest of the application COPY . . # Clean any cached build artifacts to ensure fresh build RUN flutter clean && flutter pub get # Generate code with build_runner (after clean for fresh generation) RUN dart run build_runner build --delete-conflicting-outputs # Generate health.json with version info RUN dart run tool/generate_health_json.dart # Build for web release with production configuration # These URLs enable authentication (requiresAuth = true when URL contains schweitz.net) RUN flutter build web --release \ --dart-define=CORE_API_URL=https://api.schweitz.net \ --dart-define=TATLOCK_API_URL=https://tatlock.schweitz.net # Stage 2: Serve with nginx FROM nginx:alpine # Install curl for healthcheck RUN apk add --no-cache curl # Copy custom nginx configuration COPY nginx.conf /etc/nginx/nginx.conf # Copy built web app to nginx html directory COPY --from=builder /app/build/web /usr/share/nginx/html # Expose port 80 EXPOSE 80 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD curl -f http://localhost:80/ || exit 1 # Run nginx in foreground CMD ["nginx", "-g", "daemon off;"]