# Dockerfile für Flutter Web App
FROM ubuntu:22.04 AS build

# Avoid interactive prompts
ENV DEBIAN_FRONTEND=noninteractive

# Install dependencies
RUN apt-get update && apt-get install -y \
    curl \
    git \
    unzip \
    xz-utils \
    zip \
    libglu1-mesa \
    wget \
    && rm -rf /var/lib/apt/lists/*

# Install Flutter
ENV FLUTTER_HOME=/usr/local/flutter
ENV PATH="${FLUTTER_HOME}/bin:${PATH}"

RUN git clone https://github.com/flutter/flutter.git ${FLUTTER_HOME} -b stable --depth 1 && \
    flutter config --enable-web --no-analytics && \
    flutter doctor -v

# Set working directory
WORKDIR /app

# Copy app files
COPY pubspec.yaml pubspec.lock ./

# Run pub get (downloads web dependencies without needing gradle)
RUN flutter pub get

COPY . .

# Build web app (downloads web artifacts on-demand without gradle)
RUN flutter build web --release --web-renderer canvaskit

# Production stage - Nginx
FROM nginx:alpine

# Copy built app to nginx
COPY --from=build /app/build/web /usr/share/nginx/html

# Copy custom nginx config
COPY nginx.conf /etc/nginx/conf.d/default.conf

# Expose port
EXPOSE 80

# Start nginx
CMD ["nginx", "-g", "daemon off;"]
