-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
213 lines (171 loc) · 7.62 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
FROM tomcat:10.1.34-jre21-temurin-jammy
LABEL [email protected]
LABEL org.opencontainers.image.description="This tomcat image is used by poms and vpro statefull set deployments"
LABEL org.opencontainers.image.licenses="Apache-2.0"
ENV CATALINA_BASE=/usr/local/catalina-base
# used in add-cluster.sed
# generate one like this:
# od -vN "32" -An -tx1 /dev/urandom | tr -d " \n"
ENV SECURE_ENCRYPTION_KEY=""
# Jars containing web resources and TLD's, which we use here and there.
ARG JARS_TO_SCAN="log4j-taglib*.jar,\
log4j-web*.jar,\
log4javascript*.jar,\
slf4j-taglib*.jar,\
log4j-taglib*.jar,\
vpro-shared-swagger*.jar,\
swagger-ui*,\
jstl*.jar,\
jakarta.servlet.jsp.jstl*.jar,\
svg*.jar,\
poms-thesaurus*.jar,\
flag-icon*.jar,\
media-domain*.jar,\
media-server*.jar,\
image-domain*.jar, \
poms-shared*.jar,\
meeuw*.jar,\
extjs-*.jar"
ARG CI_COMMIT_SHA
ARG CI_COMMIT_REF_NAME
ARG CI_COMMIT_TITLE
ARG CI_COMMIT_TIMESTAMP
# This makes ${USER.HOME} /
ENV HOME=/
# Handy, on a new shell you'll be in the directory of interest
WORKDIR $CATALINA_BASE
# - Create the necessary dirs in catalina_base, with the needed permissions
# - set the jars to scan in catalian.properties
# - make the mount points and fill with example content which can be used when docker image is ran locally
# - install some useful tools
# - rsync: avoid warnings for oc rsync
# - curl: I forgot when this is needed, usefull for debugging. curl http://localhost:8080
# - dnsutils: for debugging it's usefull to have tools like 'host' available.
# - less, ncal: just for debugging, inspecting log files
# - procps: just for debugging. 'ps'.
# - psmisc: just for debugging. 'pstree'
# - netcat: just for debugging. 'nc'.
# - apache2-utils: we use rotatelogs to rotate catalina.out
# - file: used by mediatools, generally useful
# - unzip: to unzip the ware in on build
COPY eu-central-1-bundle.pem /tmp
COPY importcerts.sh /tmp
RUN keytool -list -cacerts > /tmp/cacerts.before && \
bash -e /tmp/importcerts.sh && \
keytool -list -cacerts > /tmp/cacerts.after
# conf/Catalina/localhost Otherwise 'Unable to create directory for deployment: [/usr/local/catalina-base/conf/Catalina/localhost]'
RUN set -eux && \
apt-get update && apt-get -y upgrade && \
apt-get -y install less ncal procps curl rsync dnsutils netcat apache2-utils vim-tiny psmisc inotify-tools gawk file unzip && \
rm -rf /var/lib/apt/lists/* && \
mkdir -p /conf && \
chmod 775 /conf
# Have a workable shell
SHELL ["/bin/bash", "-c"]
ENV TZ=Europe/Amsterdam
ENV PGTZ=Europe/Amsterdam
ENV HISTFILE=/data/.bash_history
ENV PSQL_HISTORY=/data/.pg_history
ENV PSQL_EDITOR=/usr/bin/vi
ENV LESSHISTFILE=/data/.lesshst
# 'When invoked as an interactive shell with the name sh, Bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute'
ENV ENV=/.binbash
COPY binbash /.binbash
# - Setting up timezone and stuff
RUN echo "dash dash/sh boolean false" | debconf-set-selections && DEBIAN_FRONTEND=noninteractive dpkg-reconfigure dash && \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
dpkg-reconfigure --frontend noninteractive tzdata && \
mkdir -p /scripts
# With bearable key bindings:
COPY inputrc /etc
# And a nicer bash prompt
COPY bashrc /.bashrc
# ' Failed to source defaults.vim' (even an empty vi config file like that avoid it)
COPY exrc /.exrc
# Clean up default /etc/bash.bashrc a bit (no call to groups)
COPY bash.bashrc /etc/bash.bashrc
# A script that can parse our access logs
COPY parse_tomcat_access_logs.pl /scripts
# some files which might be needed during build
ADD clustering /tmp/clustering
RUN mkdir -p /data /data/logs && \
chmod 2775 /data /data/logs
VOLUME "/data" "/conf"
# note that this is unused in helm, it then uses container.command
CMD ["/usr/local/catalina-base/bin/start.sh"]
#CMD ["catalina.sh", "run"]
# We want to split off catalina base, default it's catalina_home
ADD catalina_base ${CATALINA_BASE}/
RUN echo Catalina base: ${CATALINA_BASE} && \
for directory in 'webapps' 'work'; do \
mkdir -p ${CATALINA_BASE}/$directory && \
chmod 775 ${CATALINA_BASE}/$directory && \
rm -rf ${CATALINA_HOME}/$directory; \
done && \
rm -rf ${CATALINA_HOME}/webapps.dist && \
chmod -R o-w ${CATALINA_HOME} && \
chmod -R g=u ${CATALINA_HOME} && \
chmod -R o-w ${CATALINA_BASE} && \
chmod -R g=u ${CATALINA_BASE} && \
mkdir -p ${CATALINA_BASE}/conf/Catalina/localhost && \
chmod 775 ${CATALINA_BASE}/conf/Catalina/localhost && \
(cd ${CATALINA_BASE} && ln -s /data/logs logs) && \
for directory in 'work'; do \
mkdir -p ${CATALINA_BASE}/$directory && \
chmod 775 ${CATALINA_BASE}/$directory && \
chgrp -R 0 ${CATALINA_BASE}/$directory; \
done && \
sed -E -i "s|^(tomcat.util.scan.StandardJarScanFilter.jarsToScan[ \t]*=)(.*)$|\1${JARS_TO_SCAN}|g" ${CATALINA_BASE}/conf/catalina.properties && \
mkdir ${CATALINA_BASE}/lib && \
echo '#this file is hidden in openshift\nenv=localhost' > /conf/application.properties && \
(echo -e "vpro/tomcat git version=${CI_COMMIT_SHA}\t${CI_COMMIT_REF_NAME}\t${CI_COMMIT_TIMESTAMP}\t${CI_COMMIT_TITLE}") > /DOCKER.BUILD && \
(echo -n "vpro/tomcat build time=" ; date -Iseconds) >> /DOCKER.BUILD
RUN useradd tomcat
# The onbuild commands to install the application when this image is overlaid
ONBUILD ARG PROJECT_VERSION
ONBUILD ARG NAME
ONBUILD ARG CONTEXT
ONBUILD ENV CONTEXT=${CONTEXT}
# Link to use in 404 page of tomcat
ONBUILD ARG DOCLINK
ONBUILD ENV DOCLINK=${DOCLINK}
ONBUILD ARG JARS_TO_SCAN=UNSET
ONBUILD ARG CLUSTERING
ONBUILD ARG COPY_TESTS
ONBUILD ARG CI_COMMIT_REF_NAME
ONBUILD ARG CI_COMMIT_SHA
ONBUILD ARG CI_COMMIT_TITLE
ONBUILD ARG CI_COMMIT_TIMESTAMP
ONBUILD ADD target/*${PROJECT_VERSION}.war /tmp/app.war
# if clustering, it also makes some sense to have a peristent work dir (to write sessions in)
ONBUILD RUN (\
if [ -z "$CONTEXT" ] ; then \
CONTEXT=ROOT; \
fi && \
cd ${CATALINA_BASE}/webapps && \
mkdir -p ${CONTEXT} && \
chmod 775 ${CONTEXT} && \
cd ${CONTEXT} && \
unzip -q /tmp/app.war && \
rm /tmp/app.war &&\
if [ "$CLUSTERING" == "true" ] ; then \
(cd ${CATALINA_BASE} && rm -r work && mkdir /data/work && chmod 2775 /data/work && ln -s /data/work work) && \
cp -f /tmp/clustering/context.xml ${CATALINA_BASE}/conf/context.xml && \
sed -E -i -f /tmp/clustering/add-cluster.sed ${CATALINA_BASE}/conf/server.xml && \
if [ "$COPY_TESTS" == "true" ] ; then cp /tmp/clustering/test-clustering.jspx .; fi ; \
fi && \
rm -rf /tmp/* \
)
ONBUILD LABEL version="${PROJECT_VERSION}"
# We need regular security patches. E.g. on every build of the application
ONBUILD RUN apt-get update && apt-get -y upgrade && \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
( if [ "$JARS_TO_SCAN" != 'UNSET' ] ; then sed -E -i "s|^(tomcat.util.scan.StandardJarScanFilter.jarsToScan[ \t]*=)(.*)$|\1${JARS_TO_SCAN}|g" ${CATALINA_BASE}/conf/catalina.properties ; fi ) && \
for errorfile in ${CATALINA_BASE}/errorpages/*.html ; do \
sed -E -i "s|class='doclink' href='(.*?)'|class='doclink' href='${DOCLINK:-https://wiki.vpro.nl/}'|g" ${errorfile} && \
( if [ "$CONTEXT" != 'ROOT' ] ; then sed -E -i "s|class='home' href='(.*?)'|class='home' href='/${CONTEXT}'|g" ${errorfile} ; fi ) ; \
done && \
(echo "${NAME} version=${PROJECT_VERSION}") >> /DOCKER.BUILD && \
(echo -e "${NAME} git version=${CI_COMMIT_SHA}\t${CI_COMMIT_REF_NAME}\t${CI_COMMIT_TIMESTAMP}\t${CI_COMMIT_TITLE}") >> /DOCKER.BUILD && \
(echo -n "${NAME} build time=" ; date -Iseconds) >> /DOCKER.BUILD
ONBUILD USER tomcat