-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
53 lines (42 loc) · 1.47 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
# -- build stage --
FROM node:21.5.0-alpine as build
WORKDIR /usr/src/react
COPY package*.json .
RUN yarn install --silent
COPY ./ .
RUN yarn build
# -- runtime stage --
FROM node:21.5.0-alpine as production
WORKDIR /usr/src/react
# copy static files
COPY --from=build /usr/src/react/dist dist/
# copy spa-env binary from official image
COPY --from=tcaty/spa-env /spa-env /spa-env
# WARNING:
# vite doesn't copy .env file to dist by default
# you should copy it manually
COPY .env.production ./dist
RUN yarn add serve --silent
ENV HOSTNAME="0.0.0.0" \
PORT="3000"
EXPOSE 3000
ENTRYPOINT [ \
# execute binary
"/spa-env", "replace", \
# specify workdir where built static is placed
"--workdir", "/usr/src/react/dist", \
# specify name of .env file for production mode
"--dotenv", ".env.production", \
# specify environment variables prefix which will be replaced
# variables without this prefix won't be affected
"--key-prefix", "VITE", \
# specify placeholder prefix to replace
# values without this prefix won't be replaced
"--placeholder-prefix", "PLACEHOLDER", \
# specify command which will be run after successfull replacement
"--cmd", "npx serve -s dist -l tcp://$HOSTNAME:$PORT", \
# specify in which form command will be run
# as you can see, command above uses environment variables $HOSTNAME and $PORT
# therefore, it must be run in shell form (by default command runs in exec form)
"--cmd-form", "shell" \
]