-
Notifications
You must be signed in to change notification settings - Fork 108
/
Dockerfile
62 lines (44 loc) · 2.26 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
################################################################################
# BASE IMAGE #
################################################################################
# Use Gradle image to run Gradle commands
FROM gradle:7.4.2-jdk17 AS base
# Set default docker build args
ARG APP_DIR=/home/gradle/galaxy-raiders
# Change default workdir
WORKDIR ${APP_DIR}
# Set environment variable to disable Gradle Daemon
ENV GRADLE_OPTS=-Dorg.gradle.daemon=false
# Give the ownership of workdir to the Gradle user
RUN chown -R gradle:gradle .
# Change to non-priviled user (PID 1000)
USER gradle
# NOTE: This repo has gradle wrappers to ensure developers use the same version
# of gradle in every environment. However, using gradle's docker image already
# guarantees that. Therefore, commands below can use the `gradle` CLI directly.
# Copy source code to workdir
COPY --chown=gradle:gradle . .
# NOTE: Gradle download dependencies only when they are necessary, which slows
# tasks the first time they execute. Running them here will allow docker to
# cache these dependencies to speed up containers that execute gradle tasks.
# Force gradle to download dependencies to build, lint and test code
RUN gradle --no-build-cache clean
################################################################################
# BUILDER IMAGE #
################################################################################
# Use base image to build the project
FROM base AS builder
# Use gradle wrapper to generate an uber JAR
RUN gradle --no-daemon shadowJar
################################################################################
# PRODUCTION IMAGE #
################################################################################
# Use Eclipse Temurin image to run the project
FROM eclipse-temurin:17-jdk AS runner
# Reuse default docker build args
ARG APP_DIR=/home/gradle/galaxy-raiders
# Copy runtime from image
COPY --from=builder ${APP_DIR}/app/build/libs/galaxy-raiders.jar \
/bin/runner/galaxy-raiders.jar
# Run uber JAR to start application
CMD ["java", "-jar", "galaxy-raiders.jar"]