ARG deb_version=latest
ARG deb_codename=bullseye
ARG network=mainnet
ARG docker_repo=gcr.io/o1labs-192920
ARG image_name=mina-daemon
ARG custom_suffix=""
ARG image_profile=""
ARG image_build_flags=""
ARG build_flags_suffix=""
ARG deb_suffix=""
ARG deb_arch="all"
ARG version=latest
# Network segment of the generic base image tag. Empty for the daemon (its
# generic image is network-free: "<version>-generic"); "-<network>" for rosetta
# (its generic image is still per-network: "<version>-<network>-generic").
ARG generic_network=""

# This Dockerfile is used to build a Docker image that contains only the Mina daemon configuration package.
# It is intended to be used as a base image for other images that require the Mina daemon configuration, without including the full Mina daemon package and its dependencies.
FROM ${docker_repo}/${image_name}:${version}${generic_network}-generic${build_flags_suffix}${custom_suffix}

# In multi-stage builds, Docker requires to re-declare ARG variables after each FROM 
# to make them available in that stage. 
# Even if the ARG is declared globally before the first FROM, 
# it must be re-declared inside each stage.
ARG deb_version
ARG deb_arch
ARG network

WORKDIR /root/

COPY mina-${network}-config_${deb_version}_${deb_arch}.deb mina-${network}-config.deb
RUN if [ ! -f "mina-${network}-config.deb" ]; then \
        echo "ERROR: Expected config package 'mina-${network}-config_${deb_version}_${deb_arch}.deb' in build context, but it was not found or not copied to 'mina-${network}-config.deb'."; \
        echo "Ensure the cache artifact exists with the correct network, deb_version, and deb_arch."; \
        exit 1; \
    fi && \
    dpkg -i mina-${network}-config.deb && \
    rm mina-${network}-config.deb