Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker multistage build image on commit #58

Merged
merged 18 commits into from
Oct 19, 2023
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
56 changes: 56 additions & 0 deletions Jenkinsfile
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']])
}
}
}
}
52 changes: 52 additions & 0 deletions build-in-docker/Dockerfile
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"]




8 changes: 8 additions & 0 deletions build-in-docker/build_last_image.sh
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} \
.
24 changes: 24 additions & 0 deletions build-in-docker/docker-entrypoint.sh
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
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>/var/local/gn_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
Loading