-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
145 lines (122 loc) · 4.45 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
FROM ubuntu:xenial
MAINTAINER Guocheng Zheng<[email protected]>
# ubuntu
ENV DEBIAN_FRONTEND noninteractive
RUN locale-gen en_US en_US.UTF-8
RUN \
echo "LANG=en_US.UTF-8" >> /etc/default/locale
ENV LANG en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV LC_CTYPE en_US.UTF-8
RUN \
dpkg-reconfigure locales && \
echo "Asia/Shanghai" > /etc/timezone && \
dpkg-reconfigure -f noninteractive tzdata
ENV SOURCES_DOMAIN mirrors.aliyun.com
RUN \
sed -i "s/archive.ubuntu.com/$SOURCES_DOMAIN/g" /etc/apt/sources.list
# oracle jdk
ENV JAVA_VER 8
RUN \
echo oracle-java$JAVA_VER-installer shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list && \
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list && \
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 && \
apt update && \
apt install -y oracle-java$JAVA_VER-installer oracle-java$JAVA_VER-unlimited-jce-policy && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/oracle-jdk$JAVA_VER*
ENV JAVA_HOME /usr/lib/jvm/java-$JAVA_VER-oracle
# tomcat
ENV CATALINA_HOME /usr/local/tomcat
ENV PATH $CATALINA_HOME/bin:$PATH
RUN mkdir -p "$CATALINA_HOME"
WORKDIR $CATALINA_HOME
RUN apt update && apt install -y --no-install-recommends \
curl \
libapr1 \
openssl \
&& rm -rf /var/lib/apt/lists/*
ENV TOMCAT_MAJOR 8
ENV TOMCAT_VERSION 8.5.2
ENV TOMCAT_TGZ_URL https://www.apache.org/dist/tomcat/tomcat-$TOMCAT_MAJOR/v$TOMCAT_VERSION/bin/apache-tomcat-$TOMCAT_VERSION.tar.gz
# INSTALL TOMCAT
RUN set -ex \
\
&& curl -fSL "$TOMCAT_TGZ_URL" -o tomcat.tar.gz \
&& curl -fSL "$TOMCAT_TGZ_URL.sha1" -o tomcat.tar.gz.sha1 \
&& sha1sum tomcat.tar.gz > tomcat.tar.gz.sha1 \
&& sha1sum -c tomcat.tar.gz.sha1 \
&& tar -xvf tomcat.tar.gz --strip-components=1 \
&& rm bin/*.bat \
&& rm tomcat.tar.gz* \
\
&& nativeBuildDir="$(mktemp -d)" \
&& tar -xvf bin/tomcat-native.tar.gz -C "$nativeBuildDir" --strip-components=1 \
&& nativeBuildDeps=" \
gcc \
libapr1-dev \
libssl-dev \
make \
" \
&& apt update && apt install -y --no-install-recommends $nativeBuildDeps && rm -rf /var/lib/apt/lists/* \
&& ( \
export CATALINA_HOME="$PWD" \
&& cd "$nativeBuildDir/native" \
&& ./configure \
--libdir=/usr/lib/jni \
--prefix="$CATALINA_HOME" \
--with-apr=/usr/bin/apr-1-config \
--with-java-home="$JAVA_HOME" \
--with-ssl=yes \
&& make -j$(nproc) \
&& make install \
) \
&& apt purge -y --auto-remove $nativeBuildDeps \
&& rm -rf "$nativeBuildDir" \
&& rm bin/tomcat-native.tar.gz \
&& ln -s /usr/lib/jni/libtcnative-1.so /usr/lib/libtcnative-1.so
# verify Tomcat Native is working properly
RUN set -e \
&& nativeLines="$(catalina.sh configtest 2>&1)" \
&& nativeLines="$(echo "$nativeLines" | grep 'Apache Tomcat Native')" \
&& nativeLines="$(echo "$nativeLines" | sort -u)" \
&& if ! echo "$nativeLines" | grep 'INFO: Loaded APR based Apache Tomcat Native library' >&2; then \
echo >&2 "$nativeLines"; \
exit 1; \
fi
# maven
ENV MAVEN_HOME /usr/local/maven
ENV PATH MAVEN_HOME/bin:$PATH
RUN mkdir -p "$MAVEN_HOME"
WORKDIR $MAVEN_HOME
ENV MAVEN_MAJOR_VERSION 3
ENV MAVEN_MINOR_VERSION 3.3.9
ENV MAVEN_TGZ_URL https://archive.apache.org/dist/maven/maven-$MAVEN_MAJOR_VERSION/$MAVEN_MINOR_VERSION/binaries/apache-maven-$MAVEN_MINOR_VERSION-bin.tar.gz
# INSTALL MAVEN
RUN set -ex \
\
&& curl -fSL "$MAVEN_TGZ_URL" -o maven.tar.gz \
&& curl -fSL "$MAVEN_TGZ_URL.sha1" -o maven.tar.gz.sha1 \
&& sha1sum maven.tar.gz > maven.tar.gz.sha1 \
&& sha1sum -c maven.tar.gz.sha1 \
&& tar -xvf maven.tar.gz --strip-components=1 \
&& rm bin/*.cmd \
&& rm maven.tar.gz* \
&& ln -s $MAVEN_HOME/bin/mvn /usr/bin/mvn
# code
ENV CODE /code
RUN mkdir -p "$CODE"
WORKDIR $CODE
ADD pom.xml $CODE/pom.xml
ADD src $CODE/src
RUN mvn install && rm -rf $CATALINA_HOME/webapps/* && \
cp target/*.war $CATALINA_HOME/webapps/ROOT.war && \
rm -rf /usr/bin/mvn
WORKDIR $CATALINA_HOME
RUN rm -rf $CODE $MAVEN_HOME ~/.m2 && \
apt purge -y --auto-remove curl && \
apt autoclean && apt --purge -y autoremove && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EXPOSE 8080
CMD ["catalina.sh", "run"]