Skip to content

Commit

Permalink
Aling Docker image with official GN image
Browse files Browse the repository at this point in the history
  • Loading branch information
juanluisrp committed Sep 28, 2023
1 parent ad16a5f commit 6b2ccb1
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 209 deletions.
39 changes: 20 additions & 19 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pipeline {
agent {
node { label "docker-host" }
node { label "docker-host" }
}

environment {
Expand All @@ -10,31 +10,32 @@ pipeline {
}

stages {

stage ('Docker build and push') {
when {
environment name: 'CHANGE_ID', value: ''
environment name: 'CHANGE_ID', value: ''
}

steps {
script{
if (env.BRANCH_NAME == env.default_branch ) {
tagName = GIT_COMMIT.take(8)
} else {
tagName = "$BRANCH_NAME"
}
try {
dockerImage = docker.build("$registry:$tagName", "--no-cache ./build-in-docker/")
docker.withRegistry( '', 'eeajenkins' ) {
dockerImage.push()
}
}
finally {
sh "docker rmi $registry:$tagName"
}
if (env.BRANCH_NAME == env.default_branch ) {
tagName = GIT_COMMIT.take(8)
} else {
tagName = "$BRANCH_NAME"
}
try {
dockerImage = docker.build("$registry:$tagName", "--no-cache --build-arg COMMIT_OR_BRANCH=$tagName ./build-in-docker/")
docker.withRegistry( '', 'eeajenkins' ) {
dockerImage.push()
}
}
finally {
sh "docker rmi $registry:$tagName"
}
}
}

}
}

}

post {
Expand Down
54 changes: 33 additions & 21 deletions build-in-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
FROM jetty:9-jdk8-eclipse-temurin as build
FROM maven:3-eclipse-temurin-8 AS build

ARG COMMIT_OR_BRANCH=eea-4.2.0

USER root
RUN apt-get -y update && \
apt-get install -y maven \
git \
zip
apt-get install -y --no-install-recommends \
unzip


RUN git clone --recursive https://github.com/eea/geonetwork-eea.git /tmp/geonetwork-eea
WORKDIR /tmp/geonetwork-eea
RUN git checkout $COMMIT_OR_BRANCH
RUN git submodule update --init --recursive
RUN mvn install -DskipTests -Penv-catalogue
RUN unzip /tmp/geonetwork-eea/web/target/catalogue.war -d /tmp/geonetwork

USER jetty
RUN git clone --recursive https://github.com/eea/geonetwork-eea.git

RUN cd geonetwork-eea && \
mvn clean install -DskipTests
RUN cd geonetwork-eea/web && \
mvn package -DskipTests -Penv-catalogue
FROM jetty:9-jdk8-eclipse-temurin AS final
LABEL maintainer="michimau <[email protected]>"

RUN unzip /var/lib/jetty/geonetwork-eea/web/target/catalogue.war -d /var/lib/jetty/webapps/catalogue
ENV DATA_DIR /catalogue-data
ENV WEBAPP_CONTEXT_PATH /geonetwork
ENV GN_CONFIG_PROPERTIES -Dgeonetwork.dir=${DATA_DIR} \
-Dgeonetwork.formatter.dir=${DATA_DIR}/data/formatter \
-Dgeonetwork.schema.dir=/opt/geonetwork/WEB-INF/data/config/schema_plugins \
-Dgeonetwork.indexConfig.dir=/opt/geonetwork/WEB-INF/data/config/index


FROM jetty:9-jdk8-eclipse-temurin
MAINTAINER michimau <[email protected]>
ENV JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true \
-Xms512M -Xss512M -Xmx2G -XX:+UseConcMarkSweepGC


USER root

RUN rm -rf /var/lib/jetty/webapps/* && \
chown jetty:jetty /var/lib/jetty/webapps && \
mkdir -p /catalogue-data && \
chown -R jetty:jetty /catalogue-data

COPY --from=build /var/lib/jetty/webapps/catalogue /var/lib/jetty/webapps/catalogue

COPY docker-entrypoint.sh /
mkdir -p ${DATA_DIR} && \
chown -R jetty:jetty ${DATA_DIR}

USER jetty
COPY jetty/geonetwork_context_template.xml /usr/local/share/geonetwork/geonetwork_context_template.xml
RUN java -jar /usr/local/jetty/start.jar --create-startd --add-module=http-forwarded
COPY docker-entrypoint.sh /geonetwork-entrypoint.sh

COPY --chown=jetty:jetty --from=build /tmp/geonetwork /opt/geonetwork

ENTRYPOINT ["/docker-entrypoint.sh"]
ENTRYPOINT ["/geonetwork-entrypoint.sh"]
CMD ["java","-jar","/usr/local/jetty/start.jar"]



Expand Down
7 changes: 6 additions & 1 deletion build-in-docker/build_last_image.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#!/bin/bash

docker build -t eeacms/geonetwork-eea:$(git ls-remote https://github.com/eea/geonetwork-eea.git HEAD | cut -f1) .
GIT_COMMIT=$(git ls-remote https://github.com/eea/geonetwork-eea.git HEAD | cut -f1)
echo "Building https://github.com/eea/geonetwork-eea.git at $GIT_COMMIT"
docker build \
-t eeacms/geonetwork-eea:${GIT_COMMIT} \
--build-arg COMMIT_OR_BRANCH=${GIT_COMMIT} \
.
151 changes: 14 additions & 137 deletions build-in-docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,147 +1,24 @@
#!/bin/sh

#!/bin/bash
set -e

mkdir -p /catalogue-data/htmlcache
mkdir -p /catalogue-data/lucene
mkdir -p /catalogue-data/logs

if [ "${ES_HOST}" != "localhost" ]; then
sed -i "s#http://localhost:9200#${ES_PROTOCOL:="http"}://${ES_HOST}:${ES_PORT:="9200"}#g" "${JETTY_BASE}/webapps/$CATALOGUE/WEB-INF/web.xml" ;
sed -i "s#es.host=localhost#es.host=${ES_HOST}#" "${JETTY_BASE}/webapps/$CATALOGUE/WEB-INF/config.properties" ;
fi;

if [ -n "${ES_PROTOCOL}" ] && [ "${ES_PROTOCOL}" != "http" ] ; then
sed -i "s#es.protocol=http#es.protocol=${ES_PROTOCOL}#" "${JETTY_BASE}/webapps/$CATALOGUE/WEB-INF/config.properties" ;
fi

if [ -n "${ES_PORT}" ] && [ "$ES_PORT" != "9200" ] ; then
sed -i "s#es.port=9200#es.port=${ES_PORT}#" "${JETTY_BASE}/webapps/$CATALOGUE/WEB-INF/config.properties" ;
fi

if [ -n "${ES_INDEX_RECORDS}" ] && [ "$ES_INDEX_RECORDS" != "gn-records" ] ; then
sed -i "s#es.index.records=gn-records#es.index.records=${ES_INDEX_RECORDS}#" "${JETTY_BASE}/webapps/$CATALOGUE/WEB-INF/config.properties" ;
fi

if [ "${ES_USERNAME}" != "" ] ; then
sed -i "s#es.username=#es.username=${ES_USERNAME}#" "${JETTY_BASE}/webapps/$CATALOGUE/WEB-INF/config.properties" ;
fi

if [ "${ES_PASSWORD}" != "" ] ; then
sed -i "s#es.password=#es.password=${ES_PASSWORD}#" "${JETTY_BASE}/webapps/$CATALOGUE/WEB-INF/config.properties" ;
fi

if [ -n "${KB_URL}" ] && [ "$KB_URL" != "http://localhost:5601" ]; then
sed -i "s#kb.url=http://localhost:5601#kb.url=${KB_URL}#" "${JETTY_BASE}/webapps/$CATALOGUE/WEB-INF/config.properties" ;
sed -i "s#http://localhost:5601#${KB_URL}#g" "${JETTY_BASE}/webapps/$CATALOGUE/WEB-INF/web.xml" ;
fi

if [ "$1" = jetty.sh ]; then
if ! command -v bash >/dev/null 2>&1 ; then
cat >&2 <<- 'EOWARN'
********************************************************************
ERROR: bash not found. Use of jetty.sh requires bash.
********************************************************************
EOWARN
exit 1
fi
cat >&2 <<- 'EOWARN'
********************************************************************
WARNING: Use of jetty.sh from this image is deprecated and may
be removed at some point in the future.
export JAVA_OPTIONS="${JAVA_OPTS} ${GN_CONFIG_PROPERTIES}"

See the documentation for guidance on extending this image:
https://github.com/docker-library/docs/tree/master/jetty
********************************************************************
EOWARN
fi
GN_BASE_DIR=/opt/geonetwork

if ! command -v -- "$1" >/dev/null 2>&1 ; then
set -- java -jar "$JETTY_HOME/start.jar" "$@"
fi

: ${TMPDIR:=/tmp/jetty}
[ -d "$TMPDIR" ] || mkdir -p $TMPDIR 2>/dev/null

: ${JETTY_START:=$JETTY_BASE/jetty.start}

case "$JAVA_OPTIONS" in
*-Djava.io.tmpdir=*) ;;
*) JAVA_OPTIONS="-Djava.io.tmpdir=$TMPDIR $JAVA_OPTIONS" ;;
esac
if [[ "$1" = jetty.sh ]] || [[ $(expr "$*" : 'java .*/start\.jar.*$') != 0 ]]; then
# Customize context path
if [ ! -f "${JETTY_BASE}/webapps/geonetwork.xml" ]; then
echo "Using ${WEBAPP_CONTEXT_PATH} for deploying the application"
cp /usr/local/share/geonetwork/geonetwork_context_template.xml "${JETTY_BASE}/webapps/geonetwork.xml"
sed -i "s#GEONETWORK_CONTEXT_PATH#${WEBAPP_CONTEXT_PATH}#" "${JETTY_BASE}/webapps/geonetwork.xml"
fi

if expr "$*" : 'java .*/start\.jar.*$' >/dev/null ; then
# this is a command to run jetty

# check if it is a terminating command
for A in "$@" ; do
case $A in
--add-to-start* |\
--create-files |\
--create-startd |\
--download |\
--dry-run |\
--exec-print |\
--help |\
--info |\
--list-all-modules |\
--list-classpath |\
--list-config |\
--list-modules* |\
--stop |\
--update-ini |\
--version |\
-v )\
# It is a terminating command, so exec directly
JAVA="$1"
shift
exec $JAVA $JAVA_OPTIONS "$@"
esac
done

if [ $(whoami) != "jetty" ]; then
cat >&2 <<- EOWARN
********************************************************************
WARNING: User is $(whoami)
The user should be (re)set to 'jetty' in the Dockerfile
********************************************************************
EOWARN
fi

if [ -f $JETTY_START ] ; then
if [ $JETTY_BASE/start.d -nt $JETTY_START ] ; then
cat >&2 <<- EOWARN
********************************************************************
WARNING: The $JETTY_BASE/start.d directory has been modified since
the $JETTY_START files was generated. Either delete
the $JETTY_START file or re-run
/generate-jetty.start.sh
from a Dockerfile
********************************************************************
EOWARN
fi
echo $(date +'%Y-%m-%d %H:%M:%S.000'):INFO:docker-entrypoint:jetty start from $JETTY_START
set -- $(cat $JETTY_START)
else
# Do a jetty dry run to set the final command
JAVA="$1"
shift
$JAVA $JAVA_OPTIONS "$@" --dry-run > $JETTY_START
if [ $(egrep -v '\\$' $JETTY_START | wc -l ) -gt 1 ] ; then
# command was more than a dry-run
cat $JETTY_START \
| awk '/\\$/ { printf "%s", substr($0, 1, length($0)-1); next } 1' \
| egrep -v '[^ ]*java .* org\.eclipse\.jetty\.xml\.XmlConfiguration '
exit
fi
set -- $(sed -e 's/ -Djava.io.tmpdir=[^ ]*//g' -e 's/\\$//' $JETTY_START)
fi
# Delegate on base image entrypoint to start jetty
exec /docker-entrypoint.sh "$@"
else
exec "$@"
fi

if [ "${1##*/}" = java -a -n "$JAVA_OPTIONS" ] ; then
JAVA="$1"
shift
set -- "$JAVA" $JAVA_OPTIONS "$@"
fi

exec "$@"
17 changes: 17 additions & 0 deletions build-in-docker/jetty/geonetwork_context_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">GEONETWORK_CONTEXT_PATH</Set>
<Set name="war">/opt/geonetwork</Set>
<Get name="systemClasspathPattern">
<Call name="add"><Arg>-javax.mail.</Arg></Call>
</Get>
<Get name="serverClasspathPattern">
<Call name="add"><Arg>javax.mail.</Arg></Call>
</Get>
<Call name="setAttribute">
<Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
<Arg>nomatches</Arg>
</Call>
</Configure>
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,6 @@
<module>healthmonitor</module>
<module>services</module>
<module>wro4j</module>
<module>web</module>
<module>inspire-atom</module>
<module>doi</module>
<module>es</module>
Expand Down
30 changes: 0 additions & 30 deletions web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1229,8 +1229,6 @@
</property>
</activation>
<properties>
<application.name>geonetwork</application.name>
<geonetwork.config.security>config-security</geonetwork.config.security>
<env>prod</env>
</properties>
</profile>
Expand All @@ -1244,9 +1242,6 @@
</activation>
<properties>
<env>prod</env>
<geonetwork.config.security>config-security</geonetwork.config.security>
<application.name>geonetwork</application.name>
<security.config.file>config-security-noldap.xml</security.config.file>
</properties>
</profile>
<profile>
Expand All @@ -1259,34 +1254,9 @@
</activation>
<properties>
<env>dev</env>
<geonetwork.data.dir>${geonetwork.webapp.dir}/WEB-INF/data</geonetwork.data.dir>
<geonetwork.config.security>config-security</geonetwork.config.security>
<application.name>geonetwork</application.name>
<security.config.file>config-security-noldap.xml</security.config.file>
<wro.debug>true</wro.debug>
</properties>
</profile>
<profile>
<id>env-catalogue</id>
<activation>
<property>
<name>env</name>
<value>prod</value>
</property>
</activation>
<properties>
<env>prod</env>
<geonetwork.config.security>config-securitycatalogue</geonetwork.config.security>
<application.name>catalogue</application.name>
<geonetwork.log>/catalogue-data/logs/catalogue.log</geonetwork.log>
<geonetwork.data.dir>file:///catalogue-data</geonetwork.data.dir>
<!-- If merging internal and editor / this should enable ldap auth. -->
<security.config.file>config-security-noldap.xml</security.config.file>
<war.excludes>xml/schemas/**,WEB-INF/web*.xml</war.excludes>
<ldap.mapping.defaultProfile>Editor</ldap.mapping.defaultProfile>
<ldap.mapping.defaultGroup>SDI_EDITING_DEFAULT</ldap.mapping.defaultGroup>
</properties>
</profile>
<profile>
<id>env-inspire</id>
<activation> <!-- -Denv=inspire -->
Expand Down

0 comments on commit 6b2ccb1

Please sign in to comment.