generated from pieceowater-dev/openAPI-frontend-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
42 lines (28 loc) · 863 Bytes
/
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
# Stage 1: Build the React app
FROM node:18-alpine AS build
WORKDIR /app
# Copy package.json and package-lock.json
COPY package*.json ./
# Install Git
RUN apk add --no-cache git
# Install dependencies
RUN npm i
# Copy the source code
COPY . .
# Define a build mode variable based on the branch
ARG BUILD_MODE
ARG API_ADDRESS
ENV VITE_API_ADDRESS=$API_ADDRESS
# RUN if [ "$BUILD_MODE" = "dev" ]; then npm run build:dev; else npm run build:main; fi
RUN npm run build:$BUILD_MODE
# Stage 2: Serve the production-ready app
FROM node:18-alpine
WORKDIR /app
# Install serve (or http-server)
RUN npm install -g serve
# Copy the built app from the previous stage (the 'build' directory) to the working directory
COPY --from=build /app/dist .
# Expose port 80 (default for serve)
EXPOSE 80
# Start serve to serve the app
CMD ["serve", "-s", "-l", "80", "."]