# CI image for the `build` job (.gitea/workflows/build.yml): the Flutter image
# plus node (actions/cache is a JS action; the image has node 18 only) and
# fixed paths for the Gradle and pub caches.
#
# Deliberately thin. The big downloads - the Android SDK packages Gradle
# auto-installs (two NDKs, CMake, ~4 min) and Gradle's dependencies - are
# restored by actions/cache, whose store is on the runner's disk. Baking the
# NDKs in made a 14 G image in the runner's 48 G RAM-backed image store
# (grg-runner); its cleanup evicts such images under pressure, so it would be
# rebuilt most runs, and on 2026-10-26 it filled the store (Gradle: "No space
# left on device").
#
# Built by the `ci-image` job, tagged by a hash of this file, into the local
# Docker of the `big` runner; a Renovate bump of either base digest rebuilds
# it (a minute or two - node and the Flutter SDK are added on top).
FROM node:26-trixie-slim@sha256:e6bedef217677b276c591795e169840edd9096dbf13f29df8ef8d1856b8820bc AS node

FROM ghcr.io/cirruslabs/flutter:stable@sha256:46691e311715845de03a3ba4753a475476936805b29431b1f00f1816981033f8

COPY --from=node /usr/local/bin/node /usr/local/bin/node

# cirruslabs stopped publishing at Flutter 3.44.0 (May 2026), while upstream
# pins `environment.flutter` in pubspec.yaml (3.47.9 since 2026-11-06) and
# `pub get` refuses any other SDK. Keep their image for the Android SDK and
# Java, and swap the Flutter SDK for the official release tarball. Bump
# together with pubspec.yaml; the hash is in Google's
# releases/releases_linux.json.
ARG FLUTTER_VERSION=3.47.9
ARG FLUTTER_SHA256=25ed8c3c29d51a7353f2a944310b478af8214920639524b19c50a19e6c044c5a
RUN curl -fsSL -o /tmp/flutter.tar.xz \
      "https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_${FLUTTER_VERSION}-stable.tar.xz" \
 && echo "${FLUTTER_SHA256}  /tmp/flutter.tar.xz" | sha256sum -c - \
 && rm -rf "$FLUTTER_HOME" \
 && mkdir -p "$FLUTTER_HOME" \
 && tar -xJf /tmp/flutter.tar.xz -C "$FLUTTER_HOME" --strip-components=1 \
 && rm /tmp/flutter.tar.xz \
 && git config --global --add safe.directory "$FLUTTER_HOME" \
 && flutter --disable-analytics \
 && flutter precache --android --no-ios --no-web --no-linux --no-windows --no-macos --no-fuchsia \
 && flutter --version | grep -q "Flutter ${FLUTTER_VERSION} "

# Fixed cache paths: the build job restores/saves exactly these (HOME inside
# a job container is not reliably /root, and Gradle takes its home from
# passwd, not $HOME). Gradle's build cache lives in there too.
ENV GRADLE_USER_HOME=/ci-cache/gradle \
    PUB_CACHE=/ci-cache/pub
RUN mkdir -p "$GRADLE_USER_HOME" "$PUB_CACHE" \
 && echo 'org.gradle.caching=true' >"$GRADLE_USER_HOME/gradle.properties" \
 && node --version
