content: ARG BASE_IMAGE="alpine:3.22.1"
  ARG BASE_DIGEST="sha256:4bcff63911fcb4448bd4fdacec207030997caf25e9bea4045fa6c8c44de311d1"
  
  FROM ${BASE_IMAGE}@${BASE_DIGEST} AS base
  WORKDIR /
  
  ARG VERSION=""
  ARG DISTRO=production
  ARG ARTIFACT_PATH=./optimize-distro/target
  
  ENV TMP_DIR=/tmp/optimize \
      BUILD_DIR=/tmp/build
  
  RUN mkdir -p ${TMP_DIR} && \
      mkdir -p ${BUILD_DIR}
  
  COPY ${ARTIFACT_PATH}/camunda-optimize-${VERSION}-${DISTRO}.tar.gz ${BUILD_DIR}
  RUN tar -xzf ${BUILD_DIR}/camunda-optimize-${VERSION}-${DISTRO}.tar.gz -C ${BUILD_DIR} && \
      rm ${BUILD_DIR}/camunda-optimize-${VERSION}-${DISTRO}.tar.gz
  COPY ./optimize/docker/bin/optimize.sh ${BUILD_DIR}/optimize.sh
  # Prevent environment-config.yaml from overriding service-config.yaml since the
  # service-config.yaml allows usage of OPTIMIZE_ environment variables
  RUN rm ${BUILD_DIR}/config/environment-config.yaml
  
  ##### FINAL IMAGE #####
  FROM base AS app
  
  ARG VERSION=""
  ARG DATE=""
  ARG REVISION=""
  
  # leave the values below unset to use the default value at the top of the file
  ARG BASE_IMAGE
  ARG BASE_DIGEST
  
  # OCI labels: https://github.com/opencontainers/image-spec/blob/main/annotations.md
  LABEL org.opencontainers.image.base.name="docker.io/library/${BASE_IMAGE}"
  LABEL org.opencontainers.image.base.digest="${BASE_DIGEST}"
  LABEL org.opencontainers.image.created="${DATE}"
  LABEL org.opencontainers.image.authors="optimize@camunda.com"
  LABEL org.opencontainers.image.url="https://docs.camunda.io/docs/components/optimize/what-is-optimize/"
  LABEL org.opencontainers.image.documentation="https://docs.camunda.io/docs/self-managed/optimize-deployment/install-and-start/"
  LABEL org.opencontainers.image.source="https://github.com/camunda/camunda"
  LABEL org.opencontainers.image.version="${VERSION}"
  LABEL org.opencontainers.image.revision="${REVISION}"
  LABEL org.opencontainers.image.vendor="Camunda Services GmbH"
  LABEL org.opencontainers.image.licenses="Proprietary"
  LABEL org.opencontainers.image.title="Camunda Optimize"
  LABEL org.opencontainers.image.description="Provides business activity monitoring for workflows and uses BPMN-based analysis to uncover process bottlenecks"
  
  # OpenShift labels: https://docs.openshift.com/container-platform/4.10/openshift_images/create-images.html#defining-image-metadata
  LABEL io.openshift.tags="bpmn,optimization,camunda"
  LABEL io.openshift.wants="zeebe,elasticsearch,identity,keycloak,opensearch"
  LABEL io.k8s.description="Provides business activity monitoring for workflows and uses BPMN-based analysis to uncover process bottlenecks"
  LABEL io.openshift.non-scalable="false"
  LABEL io.openshift.min-memory="2Gi"
  LABEL io.openshift.min-cpu="1"
  
  ENV WAIT_FOR=
  ENV WAIT_FOR_TIMEOUT=30
  ENV TZ=UTC
  ENV CONTAINER_HOST=0.0.0.0
  
  EXPOSE 8090 8091
  
  VOLUME /tmp
  
  RUN apk add --no-cache bash curl tini openjdk21-jre tzdata && \
      apk -U upgrade && \
      curl "https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh" --output /usr/local/bin/wait-for-it.sh && \
      chmod +x /usr/local/bin/wait-for-it.sh && \
      addgroup -S -g 1001 camunda && \
      adduser -S -g 1001 -u 1001 camunda && \
      mkdir -p /optimize && \
      chown 1001:1001 /optimize
  
  WORKDIR /optimize
  USER 1001:1001
  
  ENTRYPOINT ["/sbin/tini", "--"]
  CMD ["./optimize.sh"]
  
  COPY --chown=1001:1001 --from=base /tmp/build .
  