Commit 2bc31c5f by zhangxingmin

push

parent d4134b1d
# Dockerfile (位于项目根目录)
# 第一阶段:构建环境
FROM ubuntu:20.04 AS builder
# 设置时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 使用阿里云镜像源
RUN sed -i 's@archive.ubuntu.com@mirrors.aliyun.com@g' /etc/apt/sources.list && \
sed -i 's@security.ubuntu.com@mirrors.aliyun.com@g' /etc/apt/sources.list
# 安装基础依赖
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
wget \
gnupg2 \
build-essential \
libglib2.0-0 \
libnss3 \
libatk1.0-0 \
libcups2 \
libdrm2 \
libxkbcommon0 \
libxcomposite1 \
libxdamage1 \
libxrandr2 \
libgbm1 \
libgtk-3-0 \
libpango-1.0-0 \
libcairo2 \
libasound2 \
libx11-xcb1 \
libxshmfence1 \
libxcb-dri3-0 \
libqt5core5a \
libqt5gui5 \
libqt5network5 \
libqt5widgets5 \
libqt5svg5 \
libqt5websockets5 \
libicu66 \
&& rm -rf /var/lib/apt/lists/*
# 安装 Node.js
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs
# 安装 HBuilderX
ARG HBUILDER_VERSION=3.8.12
RUN wget -O HBuilderX.tar.gz https://download1.dcloud.net.cn/download/HBuilderX.${HBUILDER_VERSION}.linux-x64.tar.gz && \
tar -xzf HBuilderX.tar.gz -C /opt && \
rm HBuilderX.tar.gz && \
chmod 755 /opt/HBuilderX/cli && \
chmod 755 /opt/HBuilderX/HBuilderX
# 设置工作目录
WORKDIR /app
# 复制项目文件
#COPY jenkins .
# 配置 npm 镜像源
RUN npm config set registry https://registry.npmmirror.com && \
npm config set disturl https://npmmirror.com/dist && \
npm config set sass_binary_site https://npmmirror.com/mirrors/node-sass/
# 安装项目依赖
RUN npm install --no-audit
# 登录 HBuilderX (注意:实际使用时请使用更安全的方式管理凭证)
RUN /opt/HBuilderX/cli user login --username 15026705202 --password Wo7320017
# 构建项目
RUN /opt/HBuilderX/cli publish --platform h5 --project . --output dist
# 第二阶段:运行环境
FROM nginx:1.25-alpine
# 删除默认配置
RUN rm /etc/nginx/conf.d/default.conf
# 复制自定义 Nginx 配置
COPY nginx.conf /etc/nginx/conf.d/app.conf
# 从构建阶段复制构建产物
COPY --from=builder /app/dist /usr/share/nginx/html
# 暴露端口
EXPOSE 8333
# 启动 Nginx
CMD ["nginx", "-g", "daemon off;"]
# 使用官方Nginx镜像
FROM nginx:alpine
# 删除默认配置
RUN rm /etc/nginx/conf.d/default.conf
# 复制自定义Nginx配置
COPY jenkins/nginx.conf /etc/nginx/conf.d/app.conf
# 复制H5构建产物
COPY dist /usr/share/nginx/html
# 暴露端口
EXPOSE 8333
# 启动Nginx(非后台模式)
CMD ["nginx", "-g", "daemon off;"]
# nginx.conf
server {
listen 8333;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html; # 支持Vue路由History模式
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires 0;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 1y;
add_header Cache-Control "public";
}
# 可选:API代理
location /api {
proxy_pass http://backend-service;
proxy_set_header Host $host;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment