generated from duanshuwen/webapp-vue-frontend
更新dockerfile
This commit is contained in:
36
Dockerfile
36
Dockerfile
@@ -1,32 +1,8 @@
|
||||
# 构建阶段
|
||||
FROM node:18-alpine AS builder
|
||||
FROM alpine:3.18
|
||||
|
||||
WORKDIR /app
|
||||
# 安装 ossutil
|
||||
RUN wget -q https://gosspublic.alicdn.com/ossutil/1.7.19/ossutil64 \
|
||||
-O /usr/local/bin/ossutil \
|
||||
&& chmod +x /usr/local/bin/ossutil
|
||||
|
||||
# 先复制包管理文件,利用缓存层
|
||||
COPY package.json yarn.lock ./
|
||||
RUN yarn install --frozen-lockfile
|
||||
|
||||
# 复制源代码并构建
|
||||
COPY . .
|
||||
RUN yarn build:prod
|
||||
|
||||
# 提取 API 地址供运行阶段使用
|
||||
RUN grep '^VITE_BASE_API=' .env.production | sed 's/^VITE_BASE_API=[ \t]*//; s/[ \t]*$//; s/^"//; s/"$//' | tr -d '\r' > /app/.api_target
|
||||
|
||||
# 运行阶段:nginx 服务静态文件
|
||||
FROM nginx:stable-alpine
|
||||
|
||||
# 复制构建产物到 nginx 默认目录
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
|
||||
# 复制 API 目标地址文件和配置文件
|
||||
COPY --from=builder /app/.api_target /etc/nginx/.api_target
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
# 暴露 80 端口
|
||||
EXPOSE 80
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
ENTRYPOINT ["/bin/sh"]
|
||||
Reference in New Issue
Block a user