# PLAN Dockerfile
#
# Copyright 2024 Terma GmbH
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
# “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# The Dockerfile takes a RedHat UBI container image, and adds Terma PLAN.

# Link to Red Hat UBI OpenJDK container images:
# https://jboss-container-images.github.io/openjdk/
# Link to concrete version of base image:
# https://catalog.redhat.com/software/containers/ubi9/openjdk-17-runtime/61ee7d45384a3eb331996bee?architecture=amd64&image=66315a97705a3ba5552b9f7d&container-tabs=technical-information
FROM registry.access.redhat.com/ubi9/openjdk-17-runtime:1.18-4
# The PLAN_VERSION number has to be passed as argument.
ARG PLAN_VERSION

LABEL "com.terma.tgss.plan.short_description"="Terma Ground Segment Suite (TGSS), PLAN"
LABEL "com.terma.tgss.plan.vendor"="Terma"
LABEL "com.terma.tgss.plan.version"="$PLAN_VERSION"

# RedHat Universal Base Image (also included in the container, see below)
# https://www.redhat.com/licenses/EULA_Red_Hat_Universal_Base_Image_English_20190422.pdf
ADD https://www.redhat.com/licenses/EULA_Red_Hat_Universal_Base_Image_English_20190422.pdf .

# Section for configuring and installing Terma PLAN:
ENV PLAN_JAR plan-${PLAN_VERSION}.jar


WORKDIR /app

COPY entrypoint.sh ./
COPY ./target/${PLAN_JAR} ./
COPY ./target/lib ./lib
COPY ./target/application.properties ./demo/
COPY ./target/classes/configurations/ ./demo/configurations

USER root
RUN sed -i 's/plan.license.provided_key=/plan.license.provided_key=${PLAN_LICENSE_KEY}/g' /app/demo/application.properties && \
    chmod 750 /app/entrypoint.sh && \
    ln -s /rw_volume/config/log4j2.xml /app/log4j2.xml && \
    chown default:root /app && \
    mkdir /rw_volume && \
    chmod 750 /rw_volume && \
    chown default:root /rw_volume
USER default

ENV PLAN_LICENSE_KEY ""
ENV FORCE_RW_CONFIG_INIT 0

EXPOSE 8080

CMD /app/entrypoint.sh
