-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile-Frontend
More file actions
45 lines (32 loc) · 1.11 KB
/
Dockerfile-Frontend
File metadata and controls
45 lines (32 loc) · 1.11 KB
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
# Dockerfile
# Stage 1: Build the application
FROM node:22-alpine AS build
ARG repo_path=/home/node/
ARG build_path=frontend/
ARG shared_path=shared/
# Copy package files and install shared dependencies
WORKDIR ${repo_path}${shared_path}
COPY ${shared_path}package*.json ./
RUN npm install
# Copy package files and install frontend dependencies
WORKDIR ${repo_path}${build_path}
COPY ${build_path}package*.json ./
RUN npm install
# Copy all source code
COPY ${build_path} .
# Copy shared resources
COPY ${shared_path} ${repo_path}${shared_path}
RUN npm run build # Assumes build files are generated in /app/dist or /app/build
# Stage 2: Serve the built app with Nginx
FROM nginx:alpine
ARG repo_path=/home/node/
ARG build_path=frontend/
ARG shared_path=shared/
# Copy built files from the previous stage
COPY --from=build ${repo_path}${build_path}/dist /usr/share/nginx/html
# Copy a custom Nginx configuration file to handle SPA routing (optional)
COPY ${build_path}nginx.conf /etc/nginx/conf.d/default.conf
# Expose Nginx's default HTTP port
EXPOSE 80
# Run Nginx in the foreground
CMD ["nginx", "-g", "daemon off;"]