# GODOT_VERSION is a stable Godot release tag (e.g. "4.7.1", no "-stable" suffix — Godot 4.0+
# only, see docs/handoff/godot-ci-custom-image.md). BLENDER_URL is the tarball to bake in.
# .gitea/workflows/publish.yml always resolves both at build time via
# scripts/resolve-godot-version.sh and scripts/resolve-blender-url.sh. The defaults below are
# only a fallback for a plain local `docker build`.
#
# Godot itself is downloaded straight from its official GitHub releases (godot-builds), the same
# source barichello/godot-ci's own Dockerfile uses — this image no longer depends on that image
# as a base. Decided via wayfinder map https://git.arthurerlich.de/haylan/godot-ci/issues/2,
# ticket https://git.arthurerlich.de/haylan/godot-ci/issues/7: Alpine was considered and rejected
# (official Godot/Blender binaries are glibc-only, and Alpine's musl-native alternatives live
# only on its unpinned `edge` repo); a plain glibc-slim base doesn't cost the compatibility risk.
ARG GODOT_VERSION=4.7.1
FROM debian:bookworm-slim

ARG GODOT_VERSION
ARG BLENDER_URL=https://download.blender.org/release/Blender4.2/blender-4.2.3-linux-x64.tar.xz

RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates curl unzip xz-utils \
    libfontconfig1 \
    build-essential scons pkg-config \
    libx11-dev libxcursor-dev libxinerama-dev libgl1-mesa-dev \
    libasound2-dev libpulse-dev libudev-dev libxi-dev libxrandr-dev libwayland-dev \
    mingw-w64 \
    # Blender's own runtime deps, not pulled in by anything above — without
    # these `blender --version` fails with "libxkbcommon.so.0: cannot open
    # shared object file" (caught via a local `docker build`, see README).
    libxkbcommon0 libsm6 libice6 \
  && update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix \
  && update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix \
  && rm -rf /var/lib/apt/lists/* \
  # Godot editor + export templates, straight from the official release (same URL shape
  # barichello/godot-ci's own Dockerfile uses) — stable releases only, matching what
  # scripts/resolve-godot-version.sh resolves.
  && curl -fsSLO "https://github.com/godotengine/godot-builds/releases/download/${GODOT_VERSION}-stable/Godot_v${GODOT_VERSION}-stable_linux.x86_64.zip" \
  && curl -fsSLO "https://github.com/godotengine/godot-builds/releases/download/${GODOT_VERSION}-stable/Godot_v${GODOT_VERSION}-stable_export_templates.tpz" \
  && mkdir -p "/root/.local/share/godot/export_templates/${GODOT_VERSION}.stable" \
  && unzip -q "Godot_v${GODOT_VERSION}-stable_linux.x86_64.zip" \
  && mv "Godot_v${GODOT_VERSION}-stable_linux.x86_64" /usr/local/bin/godot \
  && unzip -q "Godot_v${GODOT_VERSION}-stable_export_templates.tpz" \
  && mv templates/* "/root/.local/share/godot/export_templates/${GODOT_VERSION}.stable/" \
  && rm -rf "Godot_v${GODOT_VERSION}-stable_linux.x86_64.zip" "Godot_v${GODOT_VERSION}-stable_export_templates.tpz" templates \
  # Blender is not bundled anywhere here — install the resolved tarball straight from
  # download.blender.org instead of an apt package.
  && curl -fsSL "$BLENDER_URL" -o /tmp/blender.tar.xz \
  && mkdir -p /opt/blender \
  && tar -xJf /tmp/blender.tar.xz -C /opt/blender --strip-components=1 \
  && ln -sf /opt/blender/blender /usr/local/bin/blender \
  && rm /tmp/blender.tar.xz
