forked from kruize/autotune
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile.autotune
100 lines (81 loc) · 4.09 KB
/
Dockerfile.autotune
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
#
# Copyright (c) 2020, 2021 Red Hat, IBM Corporation and others.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##########################################################
# Build Docker Image
##########################################################
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.4 as mvnbuild-jdk21
ARG USER=autotune
ARG AUTOTUNE_HOME=/home/$USER
RUN microdnf --setopt=install_weak_deps=0 --setopt=tsflags=nodocs install -y java-21-openjdk-devel \
tar gzip java-21-openjdk-jmods binutils git vim \
&& microdnf clean all
RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
&& curl -fsSL -o /tmp/apache-maven.tar.gz https://apache.osuosl.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz \
&& tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
&& rm -f /tmp/apache-maven.tar.gz \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
WORKDIR $AUTOTUNE_HOME/src/autotune
# Copy only the pom.xml and download the dependencies
COPY pom.xml $AUTOTUNE_HOME/src/autotune/
RUN mvn -f pom.xml install dependency:copy-dependencies
# Now copy the sources and compile and package them
COPY src $AUTOTUNE_HOME/src/autotune/src/
RUN mvn -f pom.xml clean package
COPY migrations target/bin/migrations
# Create a jlinked JRE specific to the App
RUN jlink --strip-debug --compress 2 --no-header-files --no-man-pages --module-path $AUTOTUNE_HOME/java/openjdk/jmods --add-modules java.base,java.compiler,java.desktop,java.logging,java.management,java.naming,java.security.jgss,java.sql,java.xml,jdk.compiler,jdk.httpserver,jdk.unsupported,jdk.crypto.ec --exclude-files=**java_**.properties,**J9TraceFormat**.dat,**OMRTraceFormat**.dat,**j9ddr**.dat,**public_suffix_list**.dat --output jre
##########################################################
# Runtime Docker Image
##########################################################
# Use ubi-minimal as the base image
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.4
ARG AUTOTUNE_VERSION
ARG USER=autotune
ARG UID=1001
ARG AUTOTUNE_HOME=/home/$USER
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' LC_ALL='en_US.UTF-8'
# Install packages needed for Java to function correctly
RUN microdnf --setopt=install_weak_deps=0 --setopt=tsflags=nodocs install -y tzdata openssl ca-certificates fontconfig \
glibc-langpack-en gzip tar \
&& microdnf update -y \
&& microdnf clean all
LABEL name="Kruize Autotune" \
vendor="Red Hat" \
version=${AUTOTUNE_VERSION} \
release=${AUTOTUNE_VERSION} \
run="docker run --rm -it -p 8080:8080 <image_name:tag>" \
summary="Docker Image for Autotune with ubi-minimal" \
description="For more information on this image please see https://github.com/kruize/autotune/blob/master/README.md"
WORKDIR $AUTOTUNE_HOME/app
# Create the non root user, same as the one used in the build phase.
RUN microdnf -y install shadow-utils \
&& useradd -u ${UID} -s /usr/sbin/nologin default \
&& chown -R ${UID}:0 ${AUTOTUNE_HOME}/app \
&& chmod -R g+rw ${AUTOTUNE_HOME}/app \
&& microdnf -y remove shadow-utils \
&& microdnf clean all
# Switch to the non root user
USER ${UID}
# Copy the jlinked JRE
COPY --chown=${UID}:0 --from=mvnbuild-jdk21 ${AUTOTUNE_HOME}/src/autotune/jre/ ${AUTOTUNE_HOME}/app/jre/
# Copy the app binaries
COPY --chown=${UID}:0 --from=mvnbuild-jdk21 ${AUTOTUNE_HOME}/src/autotune/target/ ${AUTOTUNE_HOME}/app/target/
# Grant execute permission
RUN chmod -R +x $AUTOTUNE_HOME/app/target/bin/
EXPOSE 8080
ENV JAVA_HOME=${AUTOTUNE_HOME}/app/jre \
PATH="${AUTOTUNE_HOME}/app/jre/bin:$PATH"
ENTRYPOINT bash target/bin/Autotune