# Use Debian 12 Slim as the base image
FROM debian:12-slim

# Set environment variables for non-interactive install
ENV DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC

# Install necessary tools: Flatpak, builder, git, etc.
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    flatpak \
    flatpak-builder \
    git \
    curl \
    unzip \
    ca-certificates \
    elfutils \
    # Build dependencies for system libraries
    build-essential \
    ninja-build \
    pkg-config \
    python3 \
    # Clean up apt cache
    && rm -rf /var/lib/apt/lists/*

# Add Flathub remote and install the Freedesktop SDK and Platform
# Using 23.08 version as specified in the manifest
RUN flatpak remote-add --system --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo && \
    flatpak install --system --noninteractive flathub org.freedesktop.Sdk//23.08 && \
    flatpak install --system --noninteractive flathub org.freedesktop.Platform//23.08

# Set working directory for the build process
WORKDIR /build

# Create cache-friendly directory structure
# This creates a clear layer separation for better Docker/Flatpak caching
RUN mkdir -p /sources /build/cache /build/build-dir /build/repo

# Copy the Flatpak manifest into the build directory
COPY com.aseprite.Aseprite.yaml .

# Default command for interactive use
CMD ["bash"]
