forked from mirovv/engineering-fundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
45 lines (33 loc) · 1.09 KB
/
Dockerfile
File metadata and controls
45 lines (33 loc) · 1.09 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
# Use an official Node.js runtime as the base image
FROM node:18-alpine AS build
# Set working directory
WORKDIR /app
# Copy package.json and package-lock.json
COPY package.json package-lock.json ./
# Install dependencies
RUN npm ci --ignore-scripts
# Copy the rest of the app's source code
COPY src ./src
COPY index.html ./index.html
COPY tsconfig.app.json ./tsconfig.app.json
COPY tsconfig.json ./tsconfig.json
COPY tsconfig.node.json ./tsconfig.node.json
COPY vite.config.ts ./vite.config.ts
# Build the React app
RUN npm run build
# Use a lightweight web server for static files
FROM node:18-alpine AS serve
# Create a non-root user and group for the serve stage
RUN npm install -g serve \
&& addgroup --system nodeapp \
&& adduser --system --ingroup nodeapp nodeapp
# Set working directory
WORKDIR /app
# Copy build artifacts from previous stage
COPY --from=build --chown=root:root --chmod=755 /app/dist .
# Switch to the non-root user for running the application
USER nodeapp
# Expose the port the app runs on
EXPOSE 3000
# Command to run the app
CMD ["serve", "-s", ".", "-l", "3000"]