content: # syntax=docker/dockerfile:1
  
  # This dockerfile builds a distribution image that contains
  # - the node binary at /concordium-node
  # - the node collector binary at /node-collector
  # - environment specific genesis data at /${environment}-genesis.dat
  #
  # No environment variables are set for the node or the collector. Those are
  # intended to be set by a docker-compose or similar configuration for the
  # specific container runtime environment.
  
  # This builder image expects the following environment variables to be set
  # - genesis_path (root of the genesis directory from which the genesis block is taken)
  # - genesis_ref (branch or commit of the genesis_data repository where the genesis data is located)
  # - environment (testnet/mainnet/stagenet, affects the naming of the genesis block)
  #
  # The build of the image will clone the genesis data repository so needs
  # credentials to access it.
  
  ARG static_binaries_image_tag=latest
  FROM static-node-binaries:${static_binaries_image_tag} AS binaries
  
  # Fetch genesis-data.
  FROM alpine/git:latest AS genesis-data
  ARG genesis_ref=main
  ARG genesis_path=testnet/2022-06-13/genesis_data
  RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
  RUN --mount=type=ssh git clone --depth 1 --branch "${genesis_ref}" git@github.com:Concordium/concordium-infra-genesis-data.git
  RUN mv "concordium-infra-genesis-data/${genesis_path}" /data
  
  FROM ubuntu:22.04
   
  # Which environment we are building the image for.
  # Currently it should be either
  #   - stagenet
  #   - testnet
  #   - mainnet
  ARG environment=testnet
  
  RUN apt-get update && \
      apt-get install -y ca-certificates && \
      rm -rf /var/lib/apt/lists/*
  
  COPY --from=binaries /build/bin/concordium-node /concordium-node
  COPY --from=binaries /build/bin/node-collector /node-collector
  COPY --from=genesis-data /data/genesis.dat /${environment}-genesis.dat
  