Skip to content

Commit 07dca03

Browse files
committed
Multistage build
1 parent 7edee29 commit 07dca03

File tree

4 files changed

+241
-13
lines changed

4 files changed

+241
-13
lines changed

.github/workflows/docker-image.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,7 @@ jobs:
2828
- name: Checkout repository
2929
uses: actions/checkout@v4
3030

31-
- uses: actions/setup-java@v4
32-
with:
33-
java-version: '11'
34-
distribution: 'temurin'
35-
architecture: x64
36-
cache: maven
37-
38-
- run: mvn install --batch-mode --update-snapshots -o -DskipTests
39-
40-
- run: mkdir staging && cp target/*.war staging
41-
42-
- name: Log in to the Container registry
31+
- name: Log in to the Container registry
4332
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
4433
with:
4534
registry: ${{ env.REGISTRY }}
@@ -55,7 +44,7 @@ jobs:
5544
- name: Build and push Docker image
5645
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09
5746
with:
58-
context: ./georoma
47+
context: .
5948
push: true
6049
tags: ${{ steps.meta.outputs.tags }}
6150
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# Build stage
3+
#
4+
FROM maven:3.6.0-jdk-11-slim AS build
5+
COPY ./ /home/app
6+
RUN mvn -f /home/app/pom.xml clean install
7+
8+
#
9+
# Package stage
10+
#
11+
FROM tomcat:8.5-jdk11
12+
13+
ENV GN_FILE geonetwork.war
14+
ENV DATA_DIR=$CATALINA_HOME/webapps/geonetwork/WEB-INF/data
15+
ENV JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -server -Xms512m -Xmx2024m -XX:NewSize=512m -XX:MaxNewSize=1024m -XX:+UseConcMarkSweepGC"
16+
ENV GN_DIR $CATALINA_HOME/webapps/geonetwork
17+
18+
#Environment variables
19+
ENV GN_VERSION 4.4.5
20+
21+
WORKDIR $CATALINA_HOME/webapps
22+
23+
USER root
24+
25+
RUN apt-get -y update && \
26+
apt-get -y install --no-install-recommends \
27+
curl \
28+
unzip
29+
30+
COPY --from=build /home/app/web/target/geonetwork.war geonetwork.war
31+
32+
RUN mkdir -p geonetwork && \
33+
unzip -e $GN_FILE -d geonetwork && \
34+
rm $GN_FILE
35+
36+
# To enable AJP and support for traefik headers
37+
COPY ./georoma/server.xml $CATALINA_HOME/conf/server.xml
38+
39+
#Set geonetwork data dir
40+
COPY ./georoma/docker-entrypoint.sh /entrypoint.sh
41+
42+
RUN chmod +x /entrypoint.sh
43+
44+
EXPOSE 8009
45+
46+
ENTRYPOINT ["/entrypoint.sh"]
47+
48+
CMD ["catalina.sh", "run"]

georoma/docker-entrypoint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
set -e
3+
4+
if [ "$1" = 'catalina.sh' ]; then
5+
6+
mkdir -p "$DATA_DIR"
7+
8+
#Set geonetwork data dir
9+
export CATALINA_OPTS="$CATALINA_OPTS -Dgeonetwork.dir=$DATA_DIR"
10+
fi
11+
12+
exec "$@"

georoma/server.xml

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<!-- Note: A "Server" is not itself a "Container", so you may not
19+
define subcomponents such as "Valves" at this level.
20+
Documentation at /docs/config/server.html
21+
-->
22+
<Server port="8005" shutdown="SHUTDOWN">
23+
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
24+
<!-- Security listener. Documentation at /docs/config/listeners.html
25+
<Listener className="org.apache.catalina.security.SecurityListener" />
26+
-->
27+
<!-- APR library loader. Documentation at /docs/apr.html -->
28+
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
29+
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
30+
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
31+
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
32+
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
33+
34+
<!-- Global JNDI resources
35+
Documentation at /docs/jndi-resources-howto.html
36+
-->
37+
<GlobalNamingResources>
38+
<!-- Editable user database that can also be used by
39+
UserDatabaseRealm to authenticate users
40+
-->
41+
<Resource name="UserDatabase" auth="Container"
42+
type="org.apache.catalina.UserDatabase"
43+
description="User database that can be updated and saved"
44+
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
45+
pathname="conf/tomcat-users.xml" />
46+
</GlobalNamingResources>
47+
48+
<!-- A "Service" is a collection of one or more "Connectors" that share
49+
a single "Container" Note: A "Service" is not itself a "Container",
50+
so you may not define subcomponents such as "Valves" at this level.
51+
Documentation at /docs/config/service.html
52+
-->
53+
<Service name="Catalina">
54+
55+
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
56+
<!--
57+
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
58+
maxThreads="150" minSpareThreads="4"/>
59+
-->
60+
61+
62+
<!-- A "Connector" represents an endpoint by which requests are received
63+
and responses are returned. Documentation at :
64+
Java HTTP Connector: /docs/config/http.html
65+
Java AJP Connector: /docs/config/ajp.html
66+
APR (HTTP/AJP) Connector: /docs/apr.html
67+
Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
68+
-->
69+
<!-- <Connector port="8080" protocol="HTTP/1.1"
70+
connectionTimeout="20000"
71+
redirectPort="8443"
72+
maxParameterCount="1000"
73+
/> -->
74+
<!-- A "Connector" using the shared thread pool-->
75+
<!--
76+
<Connector executor="tomcatThreadPool"
77+
port="8080" protocol="HTTP/1.1"
78+
connectionTimeout="20000"
79+
redirectPort="8443"
80+
maxParameterCount="1000"
81+
/>
82+
-->
83+
<!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443
84+
This connector uses the NIO implementation. The default
85+
SSLImplementation will depend on the presence of the APR/native
86+
library and the useOpenSSL attribute of the AprLifecycleListener.
87+
Either JSSE or OpenSSL style configuration may be used regardless of
88+
the SSLImplementation selected. JSSE style configuration is used below.
89+
-->
90+
<!--
91+
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
92+
maxThreads="150" SSLEnabled="true"
93+
maxParameterCount="1000"
94+
>
95+
<SSLHostConfig>
96+
<Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
97+
type="RSA" />
98+
</SSLHostConfig>
99+
</Connector>
100+
-->
101+
<!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
102+
This connector uses the APR/native implementation which always uses
103+
OpenSSL for TLS.
104+
Either JSSE or OpenSSL style configuration may be used. OpenSSL style
105+
configuration is used below.
106+
-->
107+
<!--
108+
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
109+
maxThreads="150" SSLEnabled="true"
110+
maxParameterCount="1000"
111+
>
112+
<UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
113+
<SSLHostConfig>
114+
<Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
115+
certificateFile="conf/localhost-rsa-cert.pem"
116+
certificateChainFile="conf/localhost-rsa-chain.pem"
117+
type="RSA" />
118+
</SSLHostConfig>
119+
</Connector>
120+
-->
121+
122+
<!-- Define an AJP 1.3 Connector on port 8009 -->
123+
<!-- -->
124+
<Connector port="8009" enableLookups="false" address="0.0.0.0" redirectPort="8443" protocol="AJP/1.3" secretRequired="false" URIEncoding="UTF-8" />
125+
126+
127+
<!-- An Engine represents the entry point (within Catalina) that processes
128+
every request. The Engine implementation for Tomcat stand alone
129+
analyzes the HTTP headers included with the request, and passes them
130+
on to the appropriate Host (virtual host).
131+
Documentation at /docs/config/engine.html -->
132+
133+
<!-- You should set jvmRoute to support load-balancing via AJP ie :
134+
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
135+
-->
136+
<Engine name="Catalina" defaultHost="localhost">
137+
138+
<!--For clustering, please take a look at documentation at:
139+
/docs/cluster-howto.html (simple how to)
140+
/docs/config/cluster.html (reference documentation) -->
141+
<!--
142+
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
143+
-->
144+
145+
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
146+
via a brute-force attack -->
147+
<Realm className="org.apache.catalina.realm.LockOutRealm">
148+
<!-- This Realm uses the UserDatabase configured in the global JNDI
149+
resources under the key "UserDatabase". Any edits
150+
that are performed against this UserDatabase are immediately
151+
available for use by the Realm. -->
152+
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
153+
resourceName="UserDatabase"/>
154+
</Realm>
155+
156+
<Host name="localhost" appBase="webapps"
157+
unpackWARs="true" autoDeploy="true">
158+
159+
<!-- SingleSignOn valve, share authentication between web applications
160+
Documentation at: /docs/config/valve.html -->
161+
<!--
162+
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
163+
-->
164+
<Valve className="org.apache.catalina.valves.RemoteIpValve"
165+
remoteIpHeader="x-forwarded-for"
166+
proxiesHeader="x-forwarded-by"
167+
protocolHeader="x-forwarded-proto" />
168+
169+
<!-- Access log processes all example.
170+
Documentation at: /docs/config/valve.html
171+
Note: The pattern used is equivalent to using pattern="common" -->
172+
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
173+
prefix="localhost_access_log" suffix=".txt"
174+
pattern="%h %l %u %t &quot;%r&quot; %s %b" />
175+
176+
</Host>
177+
</Engine>
178+
</Service>
179+
</Server>

0 commit comments

Comments
 (0)