# Dockerfile for Flutter project - builds from source using a Ubuntu base image
FROM ubuntu:jammy-20260217 as builder
ENV DEBIAN_FRONTEND=noninteractive
# Install required system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
git \
unzip \
xz-utils \
zip \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Install Flutter SDK (stable) by cloning the repository
WORKDIR /opt
RUN git clone -b stable https://github.com/flutter/flutter.git
ENV FLUTTER_ROOT=/opt/flutter
ENV PATH="$FLUTTER_ROOT/bin:$FLUTTER_ROOT/bin/cache/dart-sdk/bin:$PATH"
# Copy the source code and fetch/build dependencies
WORKDIR /workspace
COPY . .
# Get Dart/Flutter dependencies and run tests to validate the build
RUN flutter pub get
RUN flutter test
# Runtime image
FROM ubuntu:jammy-20260217 as runtime
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
git \
unzip \
xz-utils \
zip \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /workspace
# Copy Flutter SDK from builder and set PATH
COPY --from=builder /opt/flutter /opt/flutter
ENV FLUTTER_ROOT=/opt/flutter
ENV PATH="$FLUTTER_ROOT/bin:$FLUTTER_ROOT/bin/cache/dart-sdk/bin:$PATH"
# Copy the project files from the builder stage
COPY --from=builder /workspace /workspace
# Default to a shell in the final image; user can run flutter commands as needed
CMD ["/bin/bash"]