-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docker multistage build image on commit (#58)
* build in docker, with multistage approach * Aling Docker image with official GN image * Remove unused Maven profiles that can be now set via environment variables/properties * Using Ubuntu Focal based image due to incompatibilities of newer images with the Jenkins host OS. --------- Co-authored-by: michimau <[email protected]> Co-authored-by: Juan Luis Rodríguez <[email protected]>
- Loading branch information
1 parent
1dc16a1
commit f2ef4b0
Showing
7 changed files
with
157 additions
and
31 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
pipeline { | ||
agent { | ||
node { label "docker-host" } | ||
} | ||
|
||
environment { | ||
GIT_NAME = "geonetwork-eea" | ||
registry = "eeacms/eea-geonetwork" | ||
default_branch = "eea-4.2.0" | ||
} | ||
|
||
stages { | ||
|
||
stage ('Docker build and push') { | ||
when { | ||
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", "--pull --no-cache --build-arg COMMIT_OR_BRANCH=$tagName ./build-in-docker/") | ||
docker.withRegistry( '', 'eeajenkins' ) { | ||
dockerImage.push() | ||
} | ||
} | ||
finally { | ||
sh "docker rmi $registry:$tagName" | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
post { | ||
always { | ||
cleanWs(cleanWhenAborted: true, cleanWhenFailure: true, cleanWhenNotBuilt: true, cleanWhenSuccess: true, cleanWhenUnstable: true, deleteDirs: true) | ||
script { | ||
def url = "${env.BUILD_URL}/display/redirect" | ||
def status = currentBuild.currentResult | ||
def subject = "${status}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'" | ||
def summary = "${subject} (${url})" | ||
def details = """<h1>${env.JOB_NAME} - Build #${env.BUILD_NUMBER} - ${status}</h1> | ||
<p>Check console output at <a href="${url}">${env.JOB_BASE_NAME} - #${env.BUILD_NUMBER}</a></p> | ||
""" | ||
emailext (subject: summary, body: details, attachLog: true, compressLog: true, recipientProviders: [ [$class: 'CulpritsRecipientProvider']]) | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
FROM maven:3-eclipse-temurin-8-focal AS build | ||
|
||
ARG COMMIT_OR_BRANCH=eea-4.2.0 | ||
|
||
RUN apt-get -y update && \ | ||
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 -B install -DskipTests | ||
RUN unzip /tmp/geonetwork-eea/web/target/geonetwork.war -d /tmp/geonetwork | ||
|
||
|
||
FROM jetty:9-jdk8-eclipse-temurin AS final | ||
LABEL maintainer="michimau <[email protected]>" | ||
|
||
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 | ||
|
||
|
||
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 ${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 ["/geonetwork-entrypoint.sh"] | ||
CMD ["java","-jar","/usr/local/jetty/start.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
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} \ | ||
. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
export JAVA_OPTIONS="${JAVA_OPTS} ${GN_CONFIG_PROPERTIES}" | ||
|
||
GN_BASE_DIR=/opt/geonetwork | ||
|
||
if ! command -v -- "$1" >/dev/null 2>&1 ; then | ||
set -- java -jar "$JETTY_HOME/start.jar" "$@" | ||
fi | ||
|
||
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 | ||
|
||
# Delegate on base image entrypoint to start jetty | ||
exec /docker-entrypoint.sh "$@" | ||
else | ||
exec "$@" | ||
fi |
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
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> |
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
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