content: # syntax=docker/dockerfile:1@sha256:dabfc0969b935b2080555ace70ee69a5261af8a8f1b4df97b9e7fbcf6722eddf
  # For production images, use the adoptium.net official JRE & JDK docker images.
  FROM --platform=linux/amd64 eclipse-temurin:17.0.16_8-jdk-alpine@sha256:c0dfec8fb4aec4adad2d00d267c5cb5348465d77f087e455d2905fb180ce27d2 AS stage1
  
  ARG SBT_VERSION
  ENV SBT_VERSION="${SBT_VERSION}"
  ENV INSTALL_DIR=/usr/local
  ENV SBT_HOME=/usr/local/sbt
  ENV PATH="${PATH}:${SBT_HOME}/bin"
  ENV SBT_URL="https://github.com/sbt/sbt/releases/download/v$SBT_VERSION/sbt-$SBT_VERSION.tgz"
  
  RUN set -o pipefail && \
      apk update && \
      apk add --upgrade apk-tools && \
      apk upgrade --available && \
      apk add --no-cache --update bash wget npm git && \
      mkdir -p "$SBT_HOME" && \
      wget -qO - "${SBT_URL}" | tar xz -C "${INSTALL_DIR}" && \
      echo -ne "- with sbt $SBT_VERSION\n" >> /root/.built
  
  ENV PROJECT_HOME=/usr/src
  ENV PROJECT_NAME=server
  ENV PROJECT_LOC="${PROJECT_HOME}/${PROJECT_NAME}"
  
  COPY "${PROJECT_NAME}" "${PROJECT_LOC}"
  RUN cd "${PROJECT_LOC}" && \
      npm install -g npm && \
      npm install && \
      sbt addCustomAssets && \
      sbt update && \
      sbt dist && \
      unzip "${PROJECT_LOC}/target/universal/civiform-server-0.0.1.zip" -d / && \
      chmod +x /civiform-server-0.0.1/bin/civiform-server
  
  # This is a common trick to shrink container sizes. We discard everything added
  # during the build phase and use only the inflated artifacts created by sbt dist.
  FROM --platform=linux/amd64 eclipse-temurin:17.0.16_8-jre-alpine@sha256:fc47f4a190b599de0835d98830976f5938588b4c17b07f19dba903d5b29f666e AS stage2
  COPY --from=stage1 /civiform-server-0.0.1 /civiform-server-0.0.1
  
  # Upgrade packages for stage2 to include latest versions.
  RUN set -o pipefail && \
      apk update && \
      apk add --upgrade apk-tools && \
      apk upgrade --available && \
      apk add --no-cache --update bash openssh
  
  ARG image_tag
  ENV CIVIFORM_IMAGE_TAG=$image_tag
  
  ARG git_commit_sha
  LABEL civiform.git.commit_sha=$git_commit_sha
  
  CMD ["/civiform-server-0.0.1/bin/civiform-server", "-Dconfig.file=/civiform-server-0.0.1/conf/application.conf"]
  