Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 34 additions & 33 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Le premier stage du Dockerfile utilise une image Maven pour compiler le plugin
# de persistence obéissant à l'API spécifiée par Apache Chemistry OpenCMIS
# The first stage of the Dockerfile uses a Maven image to build the persistence
# plugin implementing the API specified by Apache Chemistry OpenCMIS
FROM maven:3.9.9-eclipse-temurin-8 AS build
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ADD pom.xml /usr/src/app
ADD src/ /usr/src/app/src
RUN ["mvn", "-e", "clean", "install"]

# Le second stage utilise une image OpenJDK allégée sur laquelle on va déployer
# Tomcat, le plugin compilé en premier stage, et paramétrer le tout
# The second stage uses a lightweight OpenJDK image where we'll deploy
# Tomcat and the plugin compiled in the first stage, and configure everything
FROM openjdk:8-jre-alpine

# Déclaration du port d'écoute
# Declare the listening port
EXPOSE 8080

# Téléchargement et déploiement de la version de Tomcat validée
# Download and deploy the validated Tomcat version
ENV TOMCAT_VERSION_MAJOR=9
ENV TOMCAT_VERSION_FULL=9.0.89
RUN set -x \
Expand All @@ -23,53 +23,54 @@ RUN set -x \
&& addgroup tomcat && adduser -s /bin/bash -D -G tomcat tomcat \
&& mkdir -p /opt \
&& curl -LO https://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_VERSION_MAJOR}/v${TOMCAT_VERSION_FULL}/bin/apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz \
# && curl -LO https://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_VERSION_MAJOR}/v${TOMCAT_VERSION_FULL}/bin/apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz.md5 \
# && md5sum -c apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz.md5 \
# && curl -LO https://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_VERSION_MAJOR}/v${TOMCAT_VERSION_FULL}/bin/apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz.md5 \
# && md5sum -c apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz.md5 \
&& gunzip -c apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz | tar -xf - -C /opt \
# && rm -f apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz.md5 \
# && rm -f apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz apache-tomcat-${TOMCAT_VERSION_FULL}.tar.gz.md5 \
&& ln -s /opt/apache-tomcat-${TOMCAT_VERSION_FULL} /opt/tomcat \
&& rm -rf /opt/tomcat/webapps/examples /opt/tomcat/webapps/docs /opt/tomcat/webapps/manager /opt/tomcat/webapps/host-manager \
&& apk del curl \
&& rm -rf /var/cache/apk/*
# Configuration des utilisateurs Tomcat et des types secondaires CMIS
# Attention, les utilisateurs Tomcat ne sont pas la même chose que les utilisateurs d'exposition CMIS
# Ces derniers sont spécifiés dans le fichier default.properties, et variabilisés par le Dockerfile
# de second niveau, qui spécialise la présente image de base pour les différentes BU, qui ont à ce jour
# des schémas de métadonnées différents, même s'il pourrait y avoir convergence à terme

# Configure Tomcat users and CMIS secondary types
# Note: Tomcat users are not the same as CMIS-exposed users.
# CMIS users are specified in `default.properties` and parameterized by the
# downstream Dockerfile that specializes this base image for different business units (BUs).
# Each BU currently has different metadata schemas, though they may converge in the future.
ADD tomcat-users.xml /opt/tomcat/conf/
ADD default-types.xml /data/cmis/default-types.xml

# On déclare le volume qui contient les données à sauvegarder, à savoir les fichiers et les fichiers
# de stockage des métadonnées associés (un pour un dans cette implémentation) ; attention à bien garder
# cette valeur en cohérence avec l'entrée persistenceDirectory du fichier default.properties
# Declare the volume that contains persistent data: files and their associated
# metadata storage files (one-to-one in this implementation). Ensure this value
# stays consistent with the `persistenceDirectory` entry in `default.properties`.
VOLUME ["/data/cmis/default"]
# RUN set -x && chown -R tomcat:tomcat /data/cmis/default # Fait dans l'entrypoint, sinon on n'agit pas sur le répertoire monté à la volée par Docker lors du démarrage du conteneur
# RUN set -x && chown -R tomcat:tomcat /data/cmis/default # Done in the entrypoint; ownership
# changes don't apply to a directory mounted at container start by Docker

# Paramétrage du positionnement de Tomcat
# Set Tomcat location environment variables
ENV TOMCAT_BASE=/opt/tomcat
ENV CATALINA_HOME=/opt/tomcat

# Recopie du WAR produit en premier stage de compilation Docker pour déploiement dans Tomcat sur la version spécifiée
# Cette version doit être en cohérence avec celle spécifiée dans le fichier pom.xml
# Copy the WAR produced in the first build stage for deployment into Tomcat.
# The `VERSION` must match the one specified in `pom.xml`.
ENV VERSION=0.13.0-SNAPSHOT
COPY --from=build /usr/src/app/target/*.war /tmp/lightweightcmis-${VERSION}.war

# Préparation des répertoires nécessaires pour le plugin CMIS
# Prepare the required directories for the CMIS plugin
RUN set -x \
&& mkdir -p /data/cmis \
&& mkdir -p /data/log
&& mkdir -p /data/cmis \
&& mkdir -p /data/log
RUN set -x \
&& mkdir ${TOMCAT_BASE}/webapps/lightweightcmis \
&& cd ${TOMCAT_BASE}/webapps/lightweightcmis \
&& unzip -qq /tmp/lightweightcmis-${VERSION}.war -d . \
&& chown -R tomcat:tomcat "$TOMCAT_BASE" \
&& chown -R tomcat:tomcat /data \
&& rm -fr /tmp/lightweightcmis-${VERSION}.war
&& cd ${TOMCAT_BASE}/webapps/lightweightcmis \
&& unzip -qq /tmp/lightweightcmis-${VERSION}.war -d . \
&& chown -R tomcat:tomcat "$TOMCAT_BASE" \
&& chown -R tomcat:tomcat /data \
&& rm -fr /tmp/lightweightcmis-${VERSION}.war

# Paramétrage du démarrage du conteneur, qui doit lancer Tomcat
# C'est l'entrypoint qui se chargera de la variabilisation du compte de service
# Le dos2unix est nécessaire pour que l'encodage Windows ne casse pas la compilation Docker sur une image Linux
# Configure container startup to run Tomcat.
# The entrypoint will handle parameterizing the service account.
# Run `dos2unix` to prevent Windows line endings from breaking Docker builds on Linux.
COPY docker-entrypoint.sh /
RUN dos2unix ./docker-entrypoint.sh && chmod 755 /docker-entrypoint.sh
ENTRYPOINT ["/docker-entrypoint.sh"]
Expand Down
10 changes: 5 additions & 5 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh

# A décommenter pour le debug, de façon à 1) sortir immédiatement sur une erreur, 2) émettre une erreur si une variable d'environnement n'est pas définie, et 3) afficher toutes les commandes dans le log
# Uncomment for debugging to 1) exit immediately on error, 2) treat unset variables as errors, and 3) print commands as they are executed
# set -eux

# Les variables d'environnement permettent de paramétrer les crédentiels
# La spécification du mot de passe est obligatoire pour des raisons de sécurité
# Environment variables are used to configure credentials
# Providing a password is mandatory for security reasons
SERVICE_ACCOUNT_LOGIN=${SERVICE_ACCOUNT_LOGIN:-admin}
if [ -z "$SERVICE_ACCOUNT_PASSWORD" ]; then
echo "Error: SERVICE_ACCOUNT_PASSWORD must be specified using the -e flag (SERVICE_ACCOUNT_LOGIN can be used to alter default login, which is admin)."
Expand All @@ -13,11 +13,11 @@ fi
TOMCAT_LOGIN=${TOMCAT_LOGIN:-$SERVICE_ACCOUNT_LOGIN}
TOMCAT_PASSWORD=${TOMCAT_PASSWORD:-$SERVICE_ACCOUNT_PASSWORD}

# Mise à jour du fichier de configuration du compte utilisé pour la connexion au endpoint CMIS
# Update the configuration file that defines the account used to connect to the CMIS endpoint
# echo "Updating default.properties with login: $SERVICE_ACCOUNT_LOGIN and password: $SERVICE_ACCOUNT_PASSWORD"
sed -i "s|^user\.1 = .*|user\.1 = $SERVICE_ACCOUNT_LOGIN:$SERVICE_ACCOUNT_PASSWORD|" /opt/apache-tomcat-9.0.89/webapps/lightweightcmis/WEB-INF/classes/default.properties

# Mise à jour du fichier de configuration des utilisateurs Tomcat
# Update the Tomcat users configuration file
# echo "Updating tomcat-users.xml with login: $TOMCAT_LOGIN and password: $TOMCAT_PASSWORD"
sed -i "s|<user name=\"[^\"]*\"|<user name=\"$TOMCAT_LOGIN\"|" /opt/tomcat/conf/tomcat-users.xml
sed -i "s|password=\"[^\"]*\"|password=\"$TOMCAT_PASSWORD\"|" /opt/tomcat/conf/tomcat-users.xml
Expand Down