# adoptopenjdk/openjdk8:jre8u252-b09-centos
#FROM netfoundry/java-base:adoptopenjdk-openjdk8-jre8u252-b09-centos
#FROM 447513199460.dkr.ecr.us-east-1.amazonaws.com/amazoncorretto-21-alpine:latest
FROM amazoncorretto:21-alpine

RUN apk update \
    && apk add --no-cache ca-certificates docker-cli-compose \
    openssh-client wget tar git netcat-openbsd bash curl

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

ENV VERSION=${version}
ENV BITBUCKET_COMMIT=${bitbucket_commit}
ENV BITBUCKET_BUILD_NUMBER=${bitbucket_build_number}
ENV HOME=${home}

WORKDIR ${home}

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

EXPOSE 8094

USER ${uid}:${gid}
ENTRYPOINT ["/app/entrypoint.sh"]

# start normally
CMD ["sh", "-c", "java ${JAVA_OPTS:-} --add-opens java.base/java.net=ALL-UNNAMED -jar clientsync-${VERSION}-SNAPSHOT.jar", "2>&1"]

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