feat(docker) 重构Docker构建流程,使用多阶段构建并优化CI配置

This commit is contained in:
wwg
2025-07-03 01:01:59 +08:00
parent 4ee4333bfe
commit 5c03784f9c
13 changed files with 90 additions and 136 deletions

View File

@@ -1,6 +0,0 @@
#/bin/bash
set -e
version=2.4.1
docker build -t orion-visor-adminer:${version} .
docker tag orion-visor-adminer:${version} registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-adminer:${version}
docker tag orion-visor-adminer:${version} registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-adminer:latest

View File

@@ -1,6 +0,0 @@
#/bin/bash
set -e
version=2.4.1
docker build -t orion-visor-guacd:${version} .
docker tag orion-visor-guacd:${version} registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-guacd:${version}
docker tag orion-visor-guacd:${version} registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-guacd:latest

View File

@@ -5,12 +5,9 @@ ARG TZ=Asia/Shanghai
RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime && \
echo '${TZ}' > /etc/timezone
# 复制配置
COPY ./my.cnf /etc/mysql/conf.d/my.cnf
COPY ./docker/mysql/my.cnf /etc/mysql/conf.d/my.cnf
# 复制初始化脚本
COPY ./sql/init-1-schema-databases.sql /tmp
COPY ./sql/init-2-schema-tables.sql /tmp
COPY ./sql/init-3-schema-quartz.sql /tmp
COPY ./sql/init-4-data.sql /tmp
COPY ./sql /tmp
# 设置初始化脚本
RUN cat /tmp/init-1-schema-databases.sql >> /tmp/init.sql && \
cat /tmp/init-2-schema-tables.sql >> /tmp/init.sql && \

View File

@@ -1,8 +0,0 @@
#/bin/bash
set -e
version=2.4.1
cp -r ../../sql ./sql
docker build -t orion-visor-mysql:${version} .
rm -rf ./sql
docker tag orion-visor-mysql:${version} registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-mysql:${version}
docker tag orion-visor-mysql:${version} registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-mysql:latest

View File

@@ -1,15 +0,0 @@
#/bin/bash
set -e
version=2.4.1
docker push registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-adminer:${version}
docker push registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-mysql:${version}
docker push registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-redis:${version}
docker push registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-guacd:${version}
docker push registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-service:${version}
docker push registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-ui:${version}
docker push registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-adminer:latest
docker push registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-mysql:latest
docker push registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-redis:latest
docker push registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-guacd:latest
docker push registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-service:latest
docker push registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-ui:latest

View File

@@ -11,5 +11,5 @@ RUN \
RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime && \
echo '${TZ}' > /etc/timezone
# redis 配置
COPY ./redis.conf /tmp
COPY ./docker/redis/redis.conf /tmp
RUN cat /tmp/redis.conf > /usr/local/redis.conf

View File

@@ -1,6 +0,0 @@
#/bin/bash
set -e
version=2.4.1
docker build -t orion-visor-redis:${version} .
docker tag orion-visor-redis:${version} registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-redis:${version}
docker tag orion-visor-redis:${version} registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-redis:latest

View File

@@ -1,3 +1,17 @@
# 第一阶段Maven构建阶段
FROM --platform=$BUILDPLATFORM maven:3.9.10-eclipse-temurin-8-alpine AS builder
# 设置阿里云镜像加速
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 复制POM文件先进行依赖下载利用Docker缓存
WORKDIR /build
COPY . .
RUN mvn dependency:go-offline
# 构建
RUN mvn clean package -DskipTests
FROM --platform=$BUILDPLATFORM openjdk:8-jdk-alpine
USER root
WORKDIR /app
@@ -14,7 +28,9 @@ RUN \
# 设置时区
RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime && \
echo '${TZ}' > /etc/timezone
# 复制包
COPY ./orion-visor-launch.jar /app/app.jar
# 从构建阶段复制jar包
COPY --from=builder /build/orion-visor-launch/target/orion-visor-launch.jar /app/app.jar
# 启动
CMD ["java", "-jar", "/app/app.jar"]
CMD ["java", "-jar", "/app/app.jar"]

View File

@@ -1,8 +0,0 @@
#/bin/bash
set -e
version=2.4.1
mv ../../orion-visor-launch/target/orion-visor-launch.jar ./orion-visor-launch.jar
docker build -t orion-visor-service:${version} .
rm -rf ./orion-visor-launch.jar
docker tag orion-visor-service:${version} registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-service:${version}
docker tag orion-visor-service:${version} registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-service:latest

View File

@@ -1,3 +1,25 @@
FROM --platform=$BUILDPLATFORM node:18-alpine AS builder
# 设置阿里云镜像加速
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 安装pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
# 复制项目文件包括package.json等
COPY ./orion-visor-ui/package.json ./orion-visor-ui/pnpm-lock.yaml* ./
# 安装依赖利用Docker缓存层
RUN pnpm install --frozen-lockfile
# 复制源代码
COPY ./orion-visor-ui/ .
# 构建项目
RUN pnpm build
FROM --platform=$BUILDPLATFORM nginx:alpine
# 系统时区
ARG TZ=Asia/Shanghai
@@ -12,7 +34,7 @@ RUN ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime && \
# 删除原 nginx 配置
RUN rm -rf /etc/nginx/conf.d/*
# 复制包
COPY ./dist /usr/share/nginx/html
COPY ./nginx.conf /etc/nginx/conf.d
COPY --from=builder /app/dist /usr/share/nginx/html
COPY ./docker/ui/nginx.conf /etc/nginx/conf.d
# 启动
CMD ["nginx", "-g", "daemon off;"]

View File

@@ -1,9 +0,0 @@
#/bin/bash
set -e
version=2.4.1
mv ../../orion-visor-ui/dist ./dist
docker build -t orion-visor-ui:${version} .
rm -rf ./orion-visor-launch.jar
rm -rf ./dist
docker tag orion-visor-ui:${version} registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-ui:${version}
docker tag orion-visor-ui:${version} registry.cn-hangzhou.aliyuncs.com/orionsec/orion-visor-ui:latest