-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
61 lines (50 loc) · 2.14 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
# syntax=docker/dockerfile:1
################################################################
# Build the React App
################################################################
FROM node:16-alpine AS client-build
WORKDIR /usr/src/listo
# ensure npm can hit font awesome pro registry.
ARG FONT_AWESOME_NPM_AUTH_TOKEN
RUN npm config set "@fortawesome:registry" https://npm.fontawesome.com/
RUN npm config set "//npm.fontawesome.com/:_authToken" $FONT_AWESOME_NPM_AUTH_TOKEN
# npm workspaces add some complexity to the package install.
# need to ensure that the root and the client package*.json files are copied.
COPY ./client/package.json client/
COPY package*.json ./
# install packages for the client workspace.
RUN npm ci --workspace=client
# replace the root package.json with the client specific one and delete the client subdirectory
RUN mv ./client/package.json ./package.json && rm -rf ./client
# copy app contents, taking advantage of layers for things less likely to change.
COPY ./client/*.config.js ./client/.env ./client/jsconfig.json ./
COPY ./client/public ./public
COPY ./client/src ./src
# build the react app.
RUN npm run build
################################################################
# Run the Express API
################################################################
FROM node:16-alpine
ENV NODE_ENV=production
WORKDIR /usr/src/listo
# npm workspaces add some complexity to the package install.
# need to ensure that the root and the client package*.json files are copied.
COPY ./api/package.json api/
COPY package*.json ./
# install packages for the api workspace.
RUN npm ci --workspace=api --omit=dev
# replace the root package.json with the api specific one and delete the api subdirectory
RUN mv ./api/package.json ./package.json && rm -rf ./api
# ensure db directory exists and permissions are set properly.
RUN mkdir /var/lib/listo && chown node /var/lib/listo
RUN chown node:node /usr/src/listo
# copy the static files from the client-build layer
COPY --from=client-build /usr/src/listo/build ./public
# copy the api files.
COPY ./api/config ./config
COPY ./api/src ./src
# run the api
EXPOSE 3000
USER node
CMD ["node","./src/server.js"]