-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
54 lines (37 loc) · 1.34 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
FROM gradle:7.3.0-jdk11 as cache
WORKDIR /app
# Set and create the cache dir
ENV GRADLE_USER_HOME /cache
RUN mkdir /cache
# Copy dependency source
COPY build.gradle.kts gradle.properties settings.gradle.kts gradle ./
# Download all dependencies
RUN gradle build -x test -x detekt --no-daemon
FROM gradle:7.3.0-jdk11 as builder
WORKDIR /app
# Copy cache from cache stage
COPY --from=cache /cache /root/.gradle
# Define Build Args
ARG Version=0.0.1
# Copy source
COPY build.gradle.kts gradle.properties settings.gradle.kts gradle ./
COPY . app
# Execute the build
RUN gradle buildFatJar --stacktrace -x test -x detekt -PappVersion=$Version --no-daemon
FROM openjdk:11
WORKDIR /app
ARG Version=0.0.1
ARG CONTAINER_USER_NAME=dig
# Create non-root user
# hadolint ignore=SC2015
RUN set -xe \
&& addgroup --system ${CONTAINER_USER_NAME} || true \
&& adduser --system --disabled-login --ingroup ${CONTAINER_USER_NAME} --home /home/${CONTAINER_USER_NAME} --gecos "${CONTAINER_USER_NAME} user" --shell /bin/false ${CONTAINER_USER_NAME} || true
# Copy the build artifacts (*.jars) from build stage
COPY --from=builder /app/build/libs/ .
EXPOSE 8080
# hadolint ignore=SC2028
RUN echo "#!/bin/bash \n java -jar dig-all.jar" > ./entrypoint.sh && chmod +x ./entrypoint.sh
# Use non-root user and start
USER $CONTAINER_USER_NAME
ENTRYPOINT ["./entrypoint.sh"]