FROM svrnty/base-distro:flutter-sdk-latest

ARG FLUTTER_VERSION=3.38.9

LABEL org.opencontainers.image.title="flutter-sdk-web"
LABEL org.opencontainers.image.description="Minimal Flutter SDK for Web/WASM CI builds"
LABEL org.opencontainers.image.version="${FLUTTER_VERSION}"

USER 0

# Clone Flutter SDK from git (supports both amd64 and arm64)
RUN git clone --depth 1 --branch ${FLUTTER_VERSION} https://github.com/flutter/flutter.git /opt/flutter && \
    git config --global --add safe.directory /opt/flutter && \
    rm -rf /opt/flutter/dev /opt/flutter/examples && \
    chown -R 65532:65532 /opt/flutter

USER 65532

# Configure for web-only (disable everything else)
RUN flutter config --enable-web \
    --no-enable-android \
    --no-enable-ios \
    --no-enable-linux-desktop \
    --no-enable-macos-desktop \
    --no-enable-windows-desktop

# Precache only web artifacts
RUN flutter precache --web \
    --no-android \
    --no-ios \
    --no-linux \
    --no-macos \
    --no-windows \
    --no-fuchsia \
    --no-universal

# Verify installation
RUN flutter doctor -v

WORKDIR /app
