# lucee6 
#FROM ortussolutions/commandbox:lucee5-light-alpine-3.9.2
FROM ortussolutions/commandbox:lucee5-alpine-3.9.2

RUN apk add argon2-dev

COPY . ${APP_DIR}/api/

# Get chain certificates by splitted certificates
WORKDIR /usr/local/share/ca-certificates/
RUN openssl s_client -showcerts -verify 5 -connect acme.mgmt.nubes.ru:443 < /dev/null | awk '/BEGIN CERTIFICATE/,/END CERTIFICATE/{ if(/BEGIN CERTIFICATE/){a++}; out="acme"a".pem"; print >out}'
#RUN openssl s_client -showcerts -verify 5 -connect jenkins-master1.adl.nubes.ru:443 < /dev/null | awk '/BEGIN CERTIFICATE/,/END CERTIFICATE/{ if(/BEGIN CERTIFICATE/){a++}; out="jenkins"a".pem"; print >out}'

RUN for i in $(ls); do keytool -noprompt -deststorepass "changeit" -importcert -file $i -keystore /usr/lib/serverHome/WEB-INF/lucee-server/context/security/cacerts -alias "nubes-$i"; done
RUN update-ca-certificates

#RUN sed -i 's~<url-pattern>/index.cfml/\*</url-pattern>~<url-pattern>/index.cfml/*</url-pattern><url-pattern>/api/v1/index.cfm/*</url-pattern>~' /usr/lib/serverHome/WEB-INF/web.xml
RUN sed -i 's~"debug"~"debugBDF952SPR"~' /app/index.cfm
RUN sed -i 's~"#url.debug#"~"#url.debugBDF952SPR#"~' /app/index.cfm


WORKDIR ${APP_DIR}
RUN box server set runwar.console.appenderLayout=JSONTemplateLayout
RUN box server set runwar.console.appenderLayoutOptions.pattern="{\"level\":\"%-5p\",\"timestamp\":\"%d{ISO8601}\",\"logger\":\"%c\",\"message\":\"%m\"}%n"

# set jvm memory
RUN box server set JVM.heapSize=1G

#RUN box server set runwar.console.appenderLayoutOptions.pattern="[%-5p] %d{dd MMM yyyy HH:mm:ss.SSS} %c: %m%n"
RUN box server set web.accessLogEnable=true
RUN box server set web.log.file=console
RUN box server set web.log.level=DEBUG
#RUN box server set runwar.console.appenderLayout=net.minidev.json.writer.JsonWriter

RUN box server set web.accessLogEnable=true
RUN box touch /usr/lib/serverHome/logs/access.txt

#RUN box touch /usr/lib/serverHome/logs/access.txt
# Get submodules PostgreSql
RUN wget https://ext.lucee.org/org.postgresql.jdbc-42.6.0.lex -P /usr/lib/serverHome/WEB-INF/lucee-server/deploy

EXPOSE 8080

#CMD /usr/lib/build/run.sh