forked from civiform/civiform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
85 lines (65 loc) · 3.04 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
# syntax=docker/dockerfile:1
# The eclipse-temurin image and the standard openJDK11 fails to run on M1 Macs because it is incompatible with ARM architecture. This
# workaround uses an aarch64 (arm64) image instead when an optional platform argument is set to arm64.
# Docker's BuildKit skips unused stages so the image for the platform that isn't used will not be built.
FROM eclipse-temurin:11.0.16_8-jdk-alpine as amd64
FROM bellsoft/liberica-openjdk-alpine:11.0.16-8 as arm64
FROM ${TARGETARCH}
ENV SBT_VERSION "1.6.2"
ENV INSTALL_DIR /usr/local
ENV SBT_HOME /usr/local/sbt
ENV PATH "${PATH}:${SBT_HOME}/bin"
ENV SBT_URL "https://github.com/sbt/sbt/releases/download/v${SBT_VERSION}/sbt-${SBT_VERSION}.tgz"
ENV PROJECT_HOME /usr/src
ENV PROJECT_NAME server
ENV PROJECT_LOC "${PROJECT_HOME}/${PROJECT_NAME}"
########################################################
### First, add dependancies that don't often change. ###
########################################################
# Update and add system dependancies
RUN set -o pipefail && \
apk update && \
apk add --upgrade apk-tools && \
apk upgrade --available && \
apk add --no-cache --update openjdk11 bash wget npm git openssh ncurses
# Install npm (node)
RUN npm install -g npm@8.5.1
# Download sbt
RUN set -o pipefail && \
mkdir -p "${SBT_HOME}" && \
wget -qO - "${SBT_URL}" | tar xz -C "${INSTALL_DIR}" && \
echo -ne "- with sbt ${SBT_VERSION}\n" >> /root/.built
# Make the project dir and install sbt
# (cannot do it in root dir)
RUN mkdir -p "${PROJECT_LOC}"
WORKDIR "${PROJECT_LOC}"
# SBT downloads a lot at run-time.
RUN sbt update
########################################################
### Install dependancies and build the server, ###
### In order of how frequently the files change ###
########################################################
# Copy the node package files (package.json and package-lock.json)
# and save them to the npm cache.
# Do this before the rest of the server code, so they don't
# get re-downloaded every time code changes.
COPY "${PROJECT_NAME}"/package* .
RUN npm install
# Copy over the remainder of the server code
# Everything below here is re-run whenever any file changes.
COPY "${PROJECT_NAME}" "${PROJECT_LOC}"
# We need to save the build assets to a seperate directory (pushRemoteCache)
RUN sbt update compile pushRemoteCache -Dconfig.file=conf/application.dev.conf
########################################################
### Get the volumes and startup commands set up ###
########################################################
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
# Save build results to anonymous volumes for reuse
# We do this first, so they don't get shadowed by the
# local server directory when running locally.
VOLUME [ "/usr/src/server/target","/usr/src/server/project/project", "/usr/src/server/project/target", "/usr/src/server/node_modules", "/usr/src/server/.bsp/","/usr/src/server/public/stylesheets/" ]
# Then map the server code to a volume, which can be shadowed
# locally.
VOLUME ["/usr/src/server"]
EXPOSE 9000