-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
100 lines (72 loc) · 2.86 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Stage 1 - Building Stage: Build the front-end application
FROM node:18.19-bullseye-slim AS front-end-build
# Switch to the main working directory
WORKDIR /app
# Copy both package.json and package-lock.json files
COPY tdm-fe/package*.json /app/
# Install dependency
RUN npm ci
# Copy the front-end source code into the build container
COPY tdm-fe /app/
# Build the React app
RUN VITE_TDM_FACTORY_HOST="" npm run build
#######################################################
# Stage 1 - Building Stage: Build the back-office application
FROM node:18.19-bullseye-slim AS back-office-build
# Switch to the main working directory
WORKDIR /app
# Copy both package.json and package-lock.json files
COPY tdm-admin/package*.json /app/
# Install dependency
RUN npm ci
# Copy the front-end source code into the build container
COPY tdm-admin /app/
# Build the React app
RUN VITE_TDM_FACTORY_HOST="" npm run build
#######################################################
# Stage 1 - Building Stage: Build back-end application
FROM node:18.19-bullseye-slim AS express-build
# Switch to the main working directory
WORKDIR /app
# Copy package.json, package-lock.json and tsconfig.json files
COPY tdm-be/package*.json tdm-be/ts*.json /app/
# Install dependency
RUN npm ci --omit=dev
# Copy the back-end source code into the build container
COPY tdm-be /app/
#######################################################
# Stage 2 - Application Stage: Build the application image
FROM node:18.19-bullseye-slim AS application
# Add ezmaster config file
RUN echo '{ \
"httpPort": 3000, \
"configPath": "/app/config/production.json", \
"dataPath": "/app" \
}' > /etc/ezmaster.json
# Update npm folder write permision
WORKDIR /usr/sbin/.npm
RUN chmod -R a+rwx /usr/sbin/.npm
# Switch to the daemon user and main working directory
USER daemon
WORKDIR /app
# Copy back-end files from the build container
COPY --chown=daemon:daemon --from=express-build /app/package.json /app/
COPY --chown=daemon:daemon --from=express-build /app/package-lock.json /app/
COPY --chown=daemon:daemon --from=express-build /app/tsconfig.json /app/
COPY --chown=daemon:daemon --from=express-build /app/node_modules /app/node_modules/
COPY --chown=daemon:daemon --from=express-build /app/config/default.json /app/config/
COPY --chown=daemon:daemon --from=express-build /app/config/production.json /app/config/
COPY --chown=daemon:daemon --from=express-build /app/src /app/src
# Copy front-end files from the build container
COPY --chown=daemon:daemon --from=front-end-build /app/dist /app/public/
# Copy front-end files from the build container
COPY --chown=daemon:daemon --from=back-office-build /app/dist /app/public/admin/
# Create the required folder
RUN mkdir /app/public/downloads
RUN mkdir /app/uploads
RUN mkdir /app/logs
RUN mkdir /app/tmp
# Start the application
EXPOSE 3000
ENV NODE_ENV="production"
CMD ["npm", "start"]