ARG docker_registry_url=docker-registry.mosip.io:51000
FROM ${docker_registry_url}/kernel-keymanager-softhsm:0.1

# can be passed during Docker build as build time environment for github branch to pickup configuration from.
ARG spring_config_label

# can be passed during Docker build as build time environment for spring profiles active 
ARG active_profile

# can be passed during Docker build as build time environment for config server URL 
ARG spring_config_url

# can be passed during Docker build as build time environment management rmi server hostname
ARG management_rmi_server_hostname

# can be passed during Docker build as build time environment management rmi server port
ARG management_jmxremote_rmi_port

# environment variable to pass active profile such as DEV, QA etc at docker runtime
ENV active_profile_env=${active_profile}

# environment variable to pass github branch to pickup configuration from, at docker runtime
ENV spring_config_label_env=${spring_config_label}

# environment variable to pass spring configuration url, at docker runtime
ENV spring_config_url_env=${spring_config_url}

# environment variable to pass artifactory url, at docker runtime
ENV artifactory_url_env=${artifactory_url}

# environment variable to pass iam_adapter url, at docker runtime
ENV iam_adapter_url_env=${iam_adapter_url}

RUN mkdir /config

COPY softhsm-application.conf /config

COPY ./target/kernel-keymanager-service-1.1.5.3.jar kernel-keymanager-service.jar

VOLUME /softhsm

EXPOSE 8088
EXPOSE 9010

CMD if [ "$is_glowroot_env" = "present" ]; then \
    wget "${artifactory_url_env}"/artifactory/libs-release-local/io/mosip/testing/glowroot.zip ; \
    apt-get update && apt-get install -y unzip ; \
    unzip glowroot.zip ; \
    rm -rf glowroot.zip ; \
    sed -i 's/<service_name>/kernel-keymanager-service/g' glowroot/glowroot.properties ; \
     wget "${iam_adapter_url_env}" -O kernel-auth-adapter.jar; \
    java -jar -javaagent:glowroot/glowroot.jar -Dloader.path=./kernel-auth-adapter.jar -Dspring.cloud.config.label="${spring_config_label_env}" -Dspring.profiles.active="${active_profile_env}" -Dspring.cloud.config.uri="${spring_config_url_env}" -XX:HeapDumpPath=/home/  kernel-keymanager-service.jar ; \
    else \    
     wget "${iam_adapter_url_env}" -O kernel-auth-adapter.jar; \
    java -jar -Dloader.path=./kernel-auth-adapter.jar -Dspring.cloud.config.label="${spring_config_label_env}" -Dspring.profiles.active="${active_profile_env}" -Dspring.cloud.config.uri="${spring_config_url_env}" kernel-keymanager-service.jar ; \
    fi
