FROM netfoundry/java-base:latest

ARG version=1.0.0
ARG bitbucket_commit
ARG bitbucket_build_number
ARG uid=0
ARG gid=0
ARG home=/app

ENV JAVAAGENT=/app/target/jacoco-agent/org.jacoco.agent-0.8.0-runtime.jar=port=6310,output=tcpserver,address=*,includes=*
ENV VERSION=${version}
ENV BITBUCKET_COMMIT=${bitbucket_commit}
ENV BITBUCKET_BUILD_NUMBER=${bitbucket_build_number}
ENV HOME=${home}

RUN pip install --upgrade pip
RUN pip install credstash

WORKDIR ${home}

COPY target/sds-${version}-SNAPSHOT.jar /app/
COPY ./target /app/target/
RUN mkdir -p ${home}/.aws
RUN chmod -R go+rx ${home}
RUN chown -R ${uid}:${gid} ${home}/.aws

EXPOSE 9302

USER ${uid}:${gid}

# start normally
CMD ["sh", "-c", "java -javaagent:${JAVAAGENT} -jar sds-${VERSION}-SNAPSHOT.jar ${JAVA_OPTS:-}", "2>&1"]

# keep ECS task alive until healthcheck grace period
#CMD ["sleep", "infinity"]
