generated from MapColonies/ts-npm-package-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
54 lines (47 loc) · 1.98 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
## Base ########################################################################
# Use a larger node image to do the build for native deps (e.g., gcc, python)
FROM node:20-alpine3.16 as base
# Reduce npm log spam and colour during install within Docker
ENV NPM_CONFIG_LOGLEVEL=warn
ENV NPM_CONFIG_COLOR=false
# We'll run the app as the `node` user, so put it in their home directory
WORKDIR /home/node/app
# Copy the source code over
COPY --chown=node:node . /home/node/app/
## Development #################################################################
# Define a development target that installs devDeps and runs in dev mode
FROM base as development
WORKDIR /home/node/app
# Install (not ci) with dependencies, and for Linux vs. Linux Musl (which we use for -alpine)
RUN apk --update --no-cache add \
automake \
autoconf \
build-base && \
npm install
# Switch to the node user vs. root
USER node
# Expose port 3000
EXPOSE 3000
# Start the app in debug mode so we can attach the debugger
CMD ["npm", "start"]
## Production ##################################################################
# Also define a production target which doesn't use devDeps
FROM base as production
WORKDIR /home/node/app
COPY --chown=node:node --from=development /home/node/app/node_modules /home/node/app/node_modules
# Build the Docusaurus app
ENV PLAYGROUND_URL=https://PLAYGROUND_URL.com
ENV PUZZLE_URL=https://PUZZLE_URL.com
ENV CATALOG_APPLICATION_URL=https://CATALOG_APPLICATION_URL.com
RUN npm run build
## Deploy ######################################################################
# Use a stable nginx image
FROM nginxinc/nginx-unprivileged:1.24.0-alpine3.17 as deploy
WORKDIR /home/node/app
USER root
COPY ./entry-point.sh /docker-entrypoint.d/init-urls.sh
RUN chmod +x /docker-entrypoint.d/init-urls.sh
# Copy what we've installed/built from production
COPY --from=production /home/node/app/build /usr/share/nginx/html/
RUN chmod -R g+w /usr/share/nginx/html/
COPY ./default.conf /etc/nginx/conf.d/default.conf