# This sample, non-production-ready template describes an Amazon EC2 instance and an Elastic Load Balancer.  
# © 2020 Amazon Web Services, Inc. or its affiliates. All Rights Reserved.  
# This AWS Content is provided subject to the terms of the AWS Customer Agreement available at  
# http://aws.amazon.com/agreement or other written agreement between Customer and either
# Amazon Web Services, Inc. or Amazon Web Services EMEA SARL or both.

FROM ${buildRegistry}/build/java:${dockerBuildVersion}

ARG artifactId=<% print module=='module_less'?repo_name:module %>
ARG XMS=2G
ARG XMX=2G

ADD https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.15.0/jmx_prometheus_javaagent-0.15.0.jar /opt/jmx_exporter.jar
#ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.17.0/opentelemetry-javaagent.jar /opt/opentelemetry-javaagent.jar

ADD https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v2.26.0/opentelemetry-javaagent.jar /opt/opentelemetry-javaagent.jar

EXPOSE 8880 8010

COPY <% print module=='module_less'?'':module+"/" %>target/*.jar /opt/target/<% print '$artifactId' %>.jar
#RUN mkdir -p /var/log/<% print '$artifactId' %> && touch /var/log/<% print '$artifactId' %>/gc.log
<% add_files.each { print "COPY ${it.path} ${it.target}\n" } %>
<% if (copy_file) { print "COPY copied_files/* $copy_target"} %>

WORKDIR /opt/target

CMD ["<% print '$artifactId' %>.jar", "-javaagent:/opt/jmx_exporter.jar=8880:/opt/config/jmx-config.yaml", \\ 
     "-XX:MinRAMPercentage=50.0", "-XX:MaxRAMPercentage=80.0", \\ 
     "-XX:+UseParallelGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails", \\
     "-XX:+PrintGCApplicationStoppedTime -XX:+PrintGCApplicationConcurrentTime", "-XX:+PrintHeapAtGC", \\ 
     "-Xloggc:/var/log/gc.log", \\
     "-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=9000k", \\
     "-Xms<% print '$XMS'%>", "-Xmx<% print '$XMX'%>"]
