This repository has been archived by the owner on Feb 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Dockerfile
67 lines (46 loc) · 1.58 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
# refrence:
# https://blog.logrocket.com/containerized-development-nestjs-docker/
FROM node:14.17.4-alpine as development
WORKDIR /srv/
COPY . .
COPY scripts/*.js ./scripts/
# Remove husky install since git is not existed in the image
RUN node scripts/set-script prepare ''
RUN yarn install --production=false --frozen-lockfile
# build the strapi admin ui
ARG SERVER_URL=http://localhost:1337
ENV SERVER_URL=${SERVER_URL}
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
# complie typescript to javascript in app directory
RUN yarn build
# run strapi build process
RUN yarn app build
# -------------------- break point --------------------
FROM node:14.17.4-alpine as production
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /srv/
COPY package.json ./
COPY yarn.lock ./
COPY scripts/*.js ./scripts/
# Just copy the app directory and install the dependencies seems a good idea
# But I am afraid that the lock file will not work. So We keep the yarn workspaces structure
COPY --from=development /srv/app ./app
RUN node scripts/set-script prepare ''
RUN yarn install --production=true --frozen-lockfile
# reduce node_modules size
# COPY scripts/trim-node-modules.sh ./
# RUN ["chmod", "+x", "./trim-node-modules.sh"]
# RUN sh ./trim-node-modules.sh
RUN rm -rf app/jest.*
RUN rm -rf app/tests
# make sure enviroment variables file not public
RUN find app/public -name ".*env*" -exec rm -rf {} +
# install node-prune (https://github.com/tj/node-prune)
RUN apk --no-cache add curl bash
RUN npx node-prune
RUN npx node-prune app/node_modules
WORKDIR /srv/app
EXPOSE 1337
CMD ["yarn", "start"]