Last active
November 25, 2021 22:06
-
-
Save sitle/1ed94a66f7f5217469d1cfd16c182a74 to your computer and use it in GitHub Desktop.
Conteneuriser une application JAVA (pour l'instant, une doc publique permettant de rationnaliser les devs externes)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker build -t sipf/CODENAME:VERSION . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# usage: file_env VAR [DEFAULT] | |
# ie: file_env 'XYZ_DB_PASSWORD' 'example' | |
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of | |
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature) | |
file_env() { | |
local var="$1" | |
local fileVar="${var}_FILE" | |
local def="${2:-}" | |
if [[ "${!var:-}" ]] && [[ "${!fileVar:-}" ]]; then | |
echo >&2 "error: both $var and $fileVar are set (but are exclusive)" | |
exit 1 | |
fi | |
local val="$def" | |
if [[ "${!var:-}" ]]; then | |
val="${!var}" | |
elif [[ "${!fileVar:-}" ]]; then | |
val="$(< "${!fileVar}")" | |
fi | |
export "$var"="$val" | |
unset "$fileVar" | |
} | |
file_env SPRING_DATASOURCE_URL | |
file_env SPRING_DATASOURCE_USERNAME | |
file_env SPRING_DATASOURCE_PASSWORD | |
file_env SECURITY_OAUTH2_CLIENT_CLIENTID | |
file_env SECURITY_OAUTH2_CLIENT_CLIENTSECRET | |
exec java $JAVA_OPTS \ | |
-Dfile.encoding=UTF-8 \ | |
-Dspring.main.banner-mode=OFF \ | |
-XX:+UnlockExperimentalVMOptions \ | |
-XX:+UseCGroupMemoryLimitForHeap \ | |
-XshowSettings:vm \ | |
-Djava.security.egd=file:/dev/./urandom \ | |
-jar /opt/app/app.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM govpf/maven:3.6-jdk-8 AS build | |
WORKDIR /opt/app/ | |
COPY . . | |
RUN mvn -B package -DskipTests | |
FROM govpf/openjdk:8-jre | |
# Build-time metadata as defined at http://label-schema.org | |
ARG BUILD_DATE | |
ARG VCS_REF | |
ARG VERSION | |
LABEL org.label-schema.build-date=$BUILD_DATE \ | |
org.label-schema.name="CODENAME" \ | |
org.label-schema.description="DESCRIPTION" \ | |
org.label-schema.url="https://URL" \ | |
org.label-schema.vcs-ref=$VCS_REF \ | |
org.label-schema.vcs-url="https://gitlab.gov.pf/CODENAME" \ | |
org.label-schema.vendor="SIPF" \ | |
org.label-schema.version=$VERSION \ | |
org.label-schema.schema-version="1.0" | |
# JRE fails to load fonts if there are no standard fonts in the image; DejaVu is a good choice, | |
# see https://github.com/docker-library/openjdk/issues/73#issuecomment-207816707 | |
RUN apk add --update ttf-dejavu && rm -rf /var/cache/apk/* | |
WORKDIR /opt/app | |
COPY --from=build /opt/app/target/*.jar app.jar | |
COPY docker-entrypoint.sh /opt/app/docker-entrypoint.sh | |
ENV JAVA_OPTS="-XX:MinRAMPercentage=50.0 -XX:MaxRAMPercentage=80.0" | |
ENTRYPOINT ["/opt/app/docker-entrypoint.sh"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment