diff --git a/3.8.3/Dockerfile b/3.8.3/Dockerfile new file mode 100644 index 0000000..252e32d --- /dev/null +++ b/3.8.3/Dockerfile @@ -0,0 +1,24 @@ +FROM tomcat:8.5-jdk8 + +ENV GN_FILE geonetwork.war +ENV DATA_DIR=$CATALINA_HOME/webapps/geonetwork/WEB-INF/data +ENV JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -server -Xms512m -Xmx2024m -XX:NewSize=512m -XX:MaxNewSize=1024m -XX:+UseConcMarkSweepGC" + +#Environment variables +ENV GN_VERSION 3.8.3 +ENV GN_DOWNLOAD_MD5 0d05c65aa4ac67fea90fa74f947822d6 + +WORKDIR $CATALINA_HOME/webapps + +RUN curl -fSL -o $GN_FILE \ + https://sourceforge.net/projects/geonetwork/files/GeoNetwork_opensource/v${GN_VERSION}/geonetwork.war/download && \ + echo "$GN_DOWNLOAD_MD5 *$GN_FILE" | md5sum -c && \ + mkdir -p geonetwork && \ + unzip -e $GN_FILE -d geonetwork && \ + rm $GN_FILE + +#Set geonetwork data dir +COPY ./docker-entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] + +CMD ["catalina.sh", "run"] diff --git a/3.8.3/docker-entrypoint.sh b/3.8.3/docker-entrypoint.sh new file mode 100755 index 0000000..57f3672 --- /dev/null +++ b/3.8.3/docker-entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e + +if [ "$1" = 'catalina.sh' ]; then + + mkdir -p "$DATA_DIR" + + #Set geonetwork data dir + export CATALINA_OPTS="$CATALINA_OPTS -Dgeonetwork.dir=$DATA_DIR" +fi + +exec "$@" \ No newline at end of file diff --git a/3.8.3/postgres/Dockerfile b/3.8.3/postgres/Dockerfile new file mode 100644 index 0000000..e15db3b --- /dev/null +++ b/3.8.3/postgres/Dockerfile @@ -0,0 +1,16 @@ +FROM geonetwork:3.8.3 + +RUN apt-get update && apt-get install -y postgresql-client && \ + rm -rf /var/lib/apt/lists/* + +#Set PostgreSQL as default GN DB +RUN sed -i -e 's###g' $CATALINA_HOME/webapps/geonetwork/WEB-INF/config-node/srv.xml && \ +sed -i -e 's###g' $CATALINA_HOME/webapps/geonetwork/WEB-INF/config-node/srv.xml + +COPY ./jdbc.properties $CATALINA_HOME/webapps/geonetwork/WEB-INF/config-db/jdbc.properties + +#Initializing database & connection string for GN +COPY ./docker-entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] + +CMD ["catalina.sh", "run"] diff --git a/3.8.3/postgres/docker-entrypoint.sh b/3.8.3/postgres/docker-entrypoint.sh new file mode 100755 index 0000000..527c8f2 --- /dev/null +++ b/3.8.3/postgres/docker-entrypoint.sh @@ -0,0 +1,55 @@ +#!/bin/bash +set -e + +if [ "$1" = 'catalina.sh' ]; then + + + if [ ! -d "$DATA_DIR" ]; then + echo "$Data directory '$DATA_DIR' does not exist. Creating it..." + mkdir -p "$DATA_DIR" + fi + + #Set geonetwork data dir + export CATALINA_OPTS="$CATALINA_OPTS -Dgeonetwork.dir=$DATA_DIR" + + #Setting host (use $POSTGRES_DB_HOST if it's set, otherwise use "postgres") + db_host="${POSTGRES_DB_HOST:-postgres}" + echo "db host: $db_host" + + #Setting port + db_port="${POSTGRES_DB_PORT:-5432}" + echo "db port: $db_port" + + if [ -z "$POSTGRES_DB_USERNAME" ] || [ -z "$POSTGRES_DB_PASSWORD" ]; then + echo >&2 "you must set POSTGRES_DB_USERNAME and POSTGRES_DB_PASSWORD" + exit 1 + fi + + db_gn="${POSTGRES_DB_NAME:-geonetwork}" + + #Create databases, if they do not exist yet (http://stackoverflow.com/a/36591842/433558) + echo "$db_host:$db_port:*:$POSTGRES_DB_USERNAME:$POSTGRES_DB_PASSWORD" > ~/.pgpass + chmod 0600 ~/.pgpass + if psql -h "$db_host" -U "$POSTGRES_DB_USERNAME" -p "$db_port" -tqc "SELECT 1 FROM pg_database WHERE datname = '$db_gn'" | grep -q 1; then + echo "Database '$db_gn' exists; skipping createdb" + elif psql -h "$db_host" -U "$POSTGRES_DB_USERNAME" -p "$db_port" -d "$db_gn" -tqc "SELECT 1 FROM pg_database WHERE datname = '$db_gn'" | grep -q 1;then + echo "Database '$db_gn' already exist; skipping database creation" + else + echo "Database '$db_gn' doesn't exist. Creating it..." + createdb -h "$db_host" -U "$POSTGRES_DB_USERNAME" -p "$db_port" -O "$POSTGRES_DB_USERNAME" "$db_gn" + fi + rm ~/.pgpass + + #Write connection string for GN + sed -ri '/^jdbc[.](username|password|database|host|port)=/d' "$CATALINA_HOME"/webapps/geonetwork/WEB-INF/config-db/jdbc.properties + echo "jdbc.username=$POSTGRES_DB_USERNAME" >> "$CATALINA_HOME"/webapps/geonetwork/WEB-INF/config-db/jdbc.properties + echo "jdbc.password=$POSTGRES_DB_PASSWORD" >> "$CATALINA_HOME"/webapps/geonetwork/WEB-INF/config-db/jdbc.properties + echo "jdbc.database=$db_gn" >> "$CATALINA_HOME"/webapps/geonetwork/WEB-INF/config-db/jdbc.properties + echo "jdbc.host=$db_host" >> "$CATALINA_HOME"/webapps/geonetwork/WEB-INF/config-db/jdbc.properties + echo "jdbc.port=$db_port" >> "$CATALINA_HOME"/webapps/geonetwork/WEB-INF/config-db/jdbc.properties + + #Fixing an hardcoded port on the connection string (bug fixed on development branch) + sed -i -e 's#5432#${jdbc.port}#g' $CATALINA_HOME/webapps/geonetwork/WEB-INF/config-db/postgres.xml +fi + +exec "$@" diff --git a/3.8.3/postgres/jdbc.properties b/3.8.3/postgres/jdbc.properties new file mode 100644 index 0000000..00a8ba1 --- /dev/null +++ b/3.8.3/postgres/jdbc.properties @@ -0,0 +1,17 @@ +jdbc.basic.removeAbandoned=true +jdbc.basic.removeAbandonedTimeout=120 +jdbc.basic.logAbandoned=true +jdbc.basic.maxActive=33 +jdbc.basic.maxIdle=${jdbc.basic.maxActive} +jdbc.basic.initialSize=${jdbc.basic.maxActive} +jdbc.basic.maxWait=200 +jdbc.basic.testOnBorrow=true +jdbc.basic.timeBetweenEvictionRunsMillis=10000 +jdbc.basic.minEvictableIdleTimeMillis=1800000 +jdbc.basic.testWhileIdle=true +jdbc.basic.numTestsPerEvictionRun=3 +jdbc.basic.poolPreparedStatements=true +jdbc.basic.maxOpenPreparedStatements=1200 +jdbc.basic.validationQuery=SELECT 1 +jdbc.basic.defaultReadOnly=false +jdbc.basic.defaultAutoCommit=false