-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
89 lines (74 loc) · 3.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
FROM ubuntu:20.04
# Note: Ensure the Dockerfile is in the same dir or above of all files meant to be copied into
# the image because Docker doesn't allow accessing any files outside of the same/child dir of
# where the Dockerfile is due to how the context of the build logic is needed before running
# any Docker commands.
#
# See:
# - https://stackoverflow.com/questions/24537340/docker-adding-a-file-from-a-parent-directory
# Change default shell to Bash for better feature support/easier usage.
# Note: Removes the need for specifying an `ENTRYPOINT` since Bash will now
# be the default fallback.
SHELL [ "/bin/bash", "-c" ]
ENV SHELL=/bin/bash
# `docker` flags useful for debugging:
# `--progress=plain`: show STDOUT/STDERR.
# `--no-cache`: force rebuilding all dependencies, packages, etc. that would usually be cached.
#
# Passing flags to `ARG` entries for customizing `Dockerfile` run:
# `--build-arg myArg=myValue`
# From: https://stackoverflow.com/questions/34254200/how-to-pass-arguments-to-a-dockerfile/34254700#34254700
# Activate CLI logging during `docker build` via `--build-arg BUILD_VERBOSE=true`
#
# See:
# - https://stackoverflow.com/questions/64804749/why-is-docker-build-not-showing-any-output-from-commands/67682576#67682576
# - https://vsupalov.com/docker-build-time-env-values/#here-s-how
# - https://vsupalov.com/docker-arg-vs-env
ARG BUILD_VERBOSE=true
ENV BUILDKIT_PROGRESS=${BUILD_VERBOSE:+plain}
# Set placeholder timezone so required package `tzdata` doesn't require interactive input
# See: https://stackoverflow.com/questions/44331836/apt-get-install-tzdata-noninteractive/44333806#44333806
RUN ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime
# Since the Java app now bundles OpenJFX, no need to install it here
RUN apt-get clean && \
apt-get update && \
apt-get install -y --no-install-recommends \
curl \
git \
sqlite3 \
jq \
openjdk-17-jdk \
openjfx
# Change CWD from <root> to $HOME
WORKDIR /home
ENV ROOT_DIR=./
RUN export ROOT_DIR="$(realpath -se .)"
ENV CLIENT_DIR="${ROOT_DIR}/client"
ENV SERVER_DIR="${ROOT_DIR}/server"
ENV BUILD_DIR="${SERVER_DIR}/build/libs"
ENV WAR_FILE_NAME="anime-atsume.war"
ENV WAR_FILE_BUILD_PATH="${BUILD_DIR}/${WAR_FILE_NAME}"
ENV WAR_FILE_FINAL_PATH="./${WAR_FILE_NAME}"
ENV DB_FILE_NAME="anime_atsume.db"
ENV DB_FILE_BUILD_PATH="${BUILD_DIR}/${DB_FILE_NAME}"
ENV DB_FILE_FINAL_PATH="./${DB_FILE_NAME}"
ENV HTTP_PORT=8080
ENV HTTPS_PORT=8443
# Copy the entire app (server/client) from the local filesystem to the Docker image
COPY . .
# Build the app if not already done before attempting Docker image generation
# Copy build-output files to root dir for ease of use
RUN if ! [[ -f "${WAR_FILE_FINAL_PATH}" ]]; then \
if ! [[ -f "${WAR_FILE_BUILD_PATH}" ]]; then \
./index.sh build -frm; \
else \
cp "${WAR_FILE_BUILD_PATH}" "${WAR_FILE_FINAL_PATH}"; \
cp "${DB_FILE_BUILD_PATH}" "${DB_FILE_FINAL_PATH}"; \
fi; \
fi;
EXPOSE ${HTTP_PORT}
EXPOSE ${HTTPS_PORT}
# Limit memory usage in website host via `JAVA_OPTS=-Xmx640m` (replace number with MB of RAM desired).
# Modify Spring .properties with `-Dmy.prop.name=myVal` if running directly from `java`
# or `-e JAVA_OPTS=-Dmy.prop.name=myVal` if running from `docker run`.
CMD java ${JAVA_OPTS} -Dglass.platform=Monocle -Dmonocle.platform=Headless -jar "${WAR_FILE_FINAL_PATH}" --server.http.port=${HTTP_PORT} --server.https.port=${HTTPS_PORT}