forked from nuwax-ai/nuwax
-
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.12 KB
/
Dockerfile
File metadata and controls
45 lines (33 loc) · 1.12 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
# 使用 Node.js 作为基础镜像
#FROM node:22
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/node:22.10.0
# 设置工作目录
WORKDIR /app
# 复制项目文件到容器中
COPY . .
# 安装项目依赖
RUN rm -rf ./node_modules
RUN npm cache clean --force
RUN echo "安装依赖start==="
RUN npm install -g cnpm --registry=https://registry.npmmirror.com
RUN cnpm install -g yarn
RUN yarn install --registry=https://registry.npmmirror.com
RUN echo "安装依赖end==="
# 构建前端应用
ENV NODE_ENV=production
RUN yarn build:prod
# 使用 Nginx 作为服务器
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:latest
WORKDIR /usr/share/nginx/html
# 复制 Nginx 配置模板文件
COPY ./k8s/default.conf.template /etc/nginx/conf.d/default.conf.template
COPY --from=0 /app/dist .
## 使用环境变量替换模板中的变量,这里修改对应域名
ENV SERVER_NAME=p1-front.space.com
ENV URI_NAME='$uri'
RUN envsubst '${SERVER_NAME},${URI_NAME}' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf
# 暴露 80 端口
EXPOSE 80
EXPOSE 443
# 启动 Nginx
CMD nginx -g 'daemon off;'