# Generic CI runner image: cirruslabs/flutter base + Node from the
# official node image, so Gitea Actions / GitHub Actions runners can
# execute JS-based actions (actions/checkout, actions/upload-artifact,
# actions/setup-*) on Flutter projects. Vanilla cirruslabs/flutter
# ships no Node, which is why pipelines using those actions fail with
# `exec: "node": executable file not found in $PATH`.
#
# Bases are pinned via build-args. Bump deliberately by editing this
# file; the weekly cron in .gitea/workflows/build.yaml picks up
# Cirrus's :stable refresh (and Node 20.x patch updates) automatically
# without a source change.

ARG FLUTTER_IMAGE=ghcr.io/cirruslabs/flutter:stable
ARG NODE_IMAGE=node:20-bookworm-slim
ARG IMAGE_SOURCE=

FROM ${NODE_IMAGE} AS node

FROM ${FLUTTER_IMAGE}
ARG IMAGE_SOURCE

# Links the published OCI package to its source repo so Gitea inherits
# visibility (public repo → publicly pullable image, no auth needed).
# IMAGE_SOURCE is supplied at build time from vars.REGISTRY_HOST.
LABEL org.opencontainers.image.source="${IMAGE_SOURCE}"
LABEL org.opencontainers.image.description="Flutter (cirruslabs/flutter:stable) + Node 20, for CI runners that execute JS-based actions."
LABEL org.opencontainers.image.licenses="MIT"

# Bring node + npm + npx in from the official node image. Symlinks
# mirror what `npm install -g` does on a normal install.
COPY --from=node /usr/local/bin/node          /usr/local/bin/node
COPY --from=node /usr/local/lib/node_modules  /usr/local/lib/node_modules
RUN ln -sf /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
 && ln -sf /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx

# Sanity gate: a missing binary fails the build rather than silently
# shipping a broken image.
RUN node --version && npm --version && npx --version && flutter --version
