# Build environment for deck_in_a_dash release artifacts: a plain C
# toolchain for the desktop deck-engine/interpreter-cli binaries (`make
# test`, `make package`), the Pebble SDK for the watch app (`make
# watchapp`), and the Android SDK/NDK for the Android app (`make
# android`), pinned to the versions validated on the maintainer's dev
# machine. Rebuild with ../build-image.sh whenever a version below
# changes.
#
# Does NOT contain any secrets - registry/SFTP credentials are injected
# at job runtime from Gitea Actions secrets, never baked into this image.
FROM ubuntu:22.04

ARG PEBBLE_TOOL_VERSION=5.0.39
ARG PEBBLE_SDK_CORE_VERSION=4.17
ARG NODE_VERSION=24.16.0
ARG ANDROID_CMDLINE_TOOLS_VERSION=9862592
ARG ANDROID_PLATFORM_VERSION=36
ARG ANDROID_BUILD_TOOLS_VERSION=36.0.0
ARG ANDROID_NDK_VERSION=30.0.14904198
ARG ANDROID_CMAKE_VERSION=3.22.1

ENV DEBIAN_FRONTEND=noninteractive \
    PATH=/root/.local/bin:${PATH}

# build-essential: gcc/make for the desktop deck-engine/interpreter-cli
# binaries (`make test`, `make package`) and for the Android app's JNI
# native library (app/src/main/jni/CMakeLists.txt - the NDK's own
# toolchain does the actual cross-compiling, but AGP's build needs a
# host C toolchain available too).
# python3/python3-venv/python3-pip: `pebble sdk install` below creates a
# venv per SDK version; Pillow (installed below) is needed at `pebble
# build` time by watch/scripts/gen_card_images.py and gen_app_icon.py,
# and by the Android app's android/scripts/gen_card_images.py and
# gen_launcher_icon.py.
# git/curl/ca-certificates/unzip/tar/xz-utils: checkout, tool downloads,
# and `make package`/`make watchapp`/`make android`'s `git describe
# --tags` versioning.
# openssh-client: the build workflow's `sftp` publish to dl.ladkau.de.
RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential python3 python3-venv python3-pip \
        git curl ca-certificates unzip tar xz-utils openssh-client \
    && rm -rf /var/lib/apt/lists/*

RUN pip3 install --no-cache-dir Pillow

# Node.js: `pebble sdk install` below runs `npm install` for the SDK
# core's bundled webpack tooling - it does not bring its own node/npm.
RUN curl -sSL -o /tmp/node.tar.xz \
        "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz" \
    && tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 \
    && rm /tmp/node.tar.xz

# Pebble SDK: pebble-tool (via uv, pipx-style isolated install) + the
# sdk-core toolchain/webpack deps for PEBBLE_SDK_CORE_VERSION, both
# fully resolved here so no `docker run` of this image needs network
# access to install anything before `pebble build` works.
RUN curl -LsSf https://astral.sh/uv/install.sh | sh \
    && uv tool install "pebble-tool==${PEBBLE_TOOL_VERSION}" \
    && pebble sdk install "${PEBBLE_SDK_CORE_VERSION}"

# Android SDK/NDK: openjdk-17 (Gradle/AGP's own minimum JDK) + the
# cmdline-tools' own sdkmanager to install exactly the platform/build-
# tools/NDK/CMake versions android/app/build.gradle.kts pins - unlike
# the Pebble/CLI build path above, `make android`'s own Gradle build
# still needs network access at build time (Gradle/AGP/androidx
# dependency resolution against Google's Maven + Maven Central - see the
# root CLAUDE.md's Android section for why this is an accepted,
# deliberate deviation from this image's otherwise-offline build
# philosophy). android/gradlew resolves its own pinned Gradle version -
# no Gradle binary is baked into this image.
RUN apt-get update && apt-get install -y --no-install-recommends openjdk-17-jdk-headless \
    && rm -rf /var/lib/apt/lists/*

ENV ANDROID_HOME=/opt/android-sdk \
    ANDROID_SDK_ROOT=/opt/android-sdk
ENV PATH=${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/platform-tools:${PATH}

RUN mkdir -p "${ANDROID_HOME}/cmdline-tools" \
    && curl -sSL -o /tmp/cmdline-tools.zip \
        "https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_CMDLINE_TOOLS_VERSION}_latest.zip" \
    && unzip -q /tmp/cmdline-tools.zip -d "${ANDROID_HOME}/cmdline-tools" \
    && mv "${ANDROID_HOME}/cmdline-tools/cmdline-tools" "${ANDROID_HOME}/cmdline-tools/latest" \
    && rm /tmp/cmdline-tools.zip \
    && yes | sdkmanager --licenses >/dev/null \
    && sdkmanager --install \
        "platform-tools" \
        "platforms;android-${ANDROID_PLATFORM_VERSION}" \
        "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
        "ndk;${ANDROID_NDK_VERSION}" \
        "cmake;${ANDROID_CMAKE_VERSION}"

ENV ANDROID_NDK_HOME=${ANDROID_HOME}/ndk/${ANDROID_NDK_VERSION}

WORKDIR /workspace
