-
Notifications
You must be signed in to change notification settings - Fork 13
/
DockerfileTest
53 lines (42 loc) · 1.57 KB
/
DockerfileTest
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
ARG BASE_IMAGE="node:18"
FROM $BASE_IMAGE
ARG NPM_AUTH_TOKEN
ARG APP_UID=1000
ARG APP_GID=1000
USER root
# key dirs & globally usable binaries/packages
ENV APP_ROOT="/opt/app-root"
ENV APP_DIR="${APP_ROOT}/src"
ENV APP_FRONTEND_DIR="${APP_DIR}/frontend"
ENV APP_BACKEND_DIR="${APP_DIR}/backend"
ENV APP_SHARED_DIR="${APP_ROOT}/shared"
ENV APP_SHARED_BIN="${APP_SHARED_DIR}/node_modules/.bin"
ENV PATH="${APP_SHARED_BIN}:${PATH}"
RUN mkdir -p \
"${APP_DIR}" \
"${APP_BACKEND_DIR}" \
"${APP_FRONTEND_DIR}" \
"${APP_SHARED_DIR}" \
&& chown -R "$APP_UID:$APP_GID" "${APP_ROOT}"
USER "$APP_UID:$APP_GID"
# thou shall not root
# note on copy+chown: do not use $USER var, it will - surprisingly - be root
COPY --chown="$APP_UID:$APP_GID" ./frontend/package.json "${APP_FRONTEND_DIR}/package.json"
RUN npm set "@dod-advana:registry" "https://npm.pkg.github.com" && \
npm set "//npm.pkg.github.com/:_authToken" "${NPM_AUTH_TOKEN}" && \
cd "${APP_FRONTEND_DIR}" && yarn install
COPY --chown="$APP_UID:$APP_GID" ./backend/package.json "${APP_BACKEND_DIR}/package.json"
RUN npm set "@dod-advana:registry" "https://npm.pkg.github.com" && \
npm set "//npm.pkg.github.com/:_authToken" "${NPM_AUTH_TOKEN}" && \
cd "${APP_BACKEND_DIR}" && yarn install
COPY --chown="$APP_UID:$APP_GID" . "${APP_DIR}"
RUN cd "${APP_FRONTEND_DIR}" \
&& npm run build \
&& mv build "${APP_BACKEND_DIR}" \
&& cd "${APP_BACKEND_DIR}" \
&& rm -rf "${APP_FRONTEND_DIR}"
# http & https
EXPOSE 8990 8443
WORKDIR "${APP_BACKEND_DIR}"
ENTRYPOINT ["node"]
CMD ["index.js"]