/
Dockerfile
68 lines (42 loc) · 1.18 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
#
# Common Dependencies
#
FROM node:12 AS base
RUN mkdir -p /srv/todo/storage && chown -R node:node /srv/todo
USER node
WORKDIR /srv/todo/storage
COPY --chown=node:node storage/package.json storage/package-lock.json ./
RUN npm install --quiet
#
# Backend for Development
#
FROM base AS development-backend
RUN mkdir /srv/todo/backend
WORKDIR /srv/todo/backend
COPY --chown=node:node backend/package.json backend/package-lock.json ./
RUN npm install --quiet
#
# Frontend for Development
#
FROM base AS development-frontend
RUN mkdir /srv/todo/frontend
WORKDIR /srv/todo/frontend
COPY frontend/package.json frontend/package-lock.json ./
RUN npm install --quiet
#
# Frontend Build for Production
#
FROM development-frontend AS build-frontend
COPY frontend .
RUN npm run build
#
# Backend for Production
#
FROM node:12-slim AS production
USER node
WORKDIR /srv/todo/backend
COPY --from=development-backend --chown=root:root /srv/todo/backend/node_modules ./node_modules
COPY --from=development-backend --chown=root:root /srv/todo/storage/node_modules ../storage/node_modules
COPY --from=build-frontend --chown=root:root /srv/todo/frontend/dist ./dist
COPY . .
CMD ["node", "server.js"]