commit to github

This commit is contained in:
2025-12-14 12:11:36 +08:00
parent 49aefba7e2
commit ace426898e
13 changed files with 34852 additions and 123 deletions
+28 -26
View File
@@ -31,19 +31,21 @@ DB_MIGRATION_VERSION=2.0.3
# --------------------------------------------
# 镜像仓库配置
# --------------------------------------------
# 本地私有 Registry(推送目标)
REGISTRY=localhost:15000/ljwx
PRIVATE_REGISTRY_HOST=localhost:15000
PRIVATE_REGISTRY_ENABLED=true
# 本地缓存 Registry(拉取加速)
CACHE_REGISTRY_HOST=localhost:15001
CACHE_REGISTRY_ENABLED=true
# Harbor 配置
HARBOR_HOST=127.0.0.1:8080
# Harbor 配置(主要推送目标)
HARBOR_HOST=harbor.omniverseai.net
HARBOR_PROJECT=health
HARBOR_USERNAME=admin
HARBOR_PASSWORD=admin123
HARBOR_INSECURE=false
# 镜像仓库地址(使用 Harbor)
REGISTRY=${HARBOR_HOST}/${HARBOR_PROJECT}
PRIVATE_REGISTRY_HOST=${HARBOR_HOST}
PRIVATE_REGISTRY_ENABLED=true
# 本地缓存 Registry(拉取加速 - 可选)
CACHE_REGISTRY_HOST=localhost:15001
CACHE_REGISTRY_ENABLED=false
# --------------------------------------------
# 构建配置
@@ -157,19 +159,19 @@ GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
# 6. 一键部署: ./build-and-push.sh -a
# ============================================
# v2.0 新增配置
# v2.0 配置总结
# ============================================
# Harbor 推送目标: ${HARBOR_HOST}/${HARBOR_PROJECT}
# 完整镜像格式: localhost:80/health/ljwx-boot:2.0.4
# Harbor 管理界面: http://localhost:80
#
# Docker insecure registry 配置(HTTP Harbor 必需):
# macOS: Docker Desktop -> Preferences -> Docker Engine
# {
# "insecure-registries": ["localhost:80"]
# }
#
# 使用示例:
# 1. 构建并推送到 Harbor: ./build-and-push-v2.sh -b -p
# 2. 查看镜像: http://localhost:80/harbor/projects/20/repositories
# ============================================
REGISTRY=localhost:15000/ljwx
PRIVATE_REGISTRY_HOST=localhost:15000
HOST_MYSQL_HOST=127.0.0.1
HOST_MYSQL_PORT=3306
HOST_MYSQL_USER=root
HOST_MYSQL_PASSWORD=123456
HOST_MYSQL_DATABASE=test
DB_MIGRATION_ENABLED=true
DB_MIGRATION_AUTO_APPLY=true
DB_MIGRATION_DIR=./docker/mysql/migrations
BOOT_PORT=9998
BIGSCREEN_PORT=5225
BIGSCREEN_EXTERNAL_PORT=8000
ADMIN_EXTERNAL_PORT=8080
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+80 -6
View File
@@ -98,19 +98,75 @@ check_docker() {
print_error "Docker未运行,请先启动Docker"
exit 1
fi
# 检查 insecure registry 配置
if [ "${HARBOR_INSECURE}" = "true" ] && [ "${PRIVATE_REGISTRY_ENABLED}" = "true" ]; then
local registry_host=${HARBOR_HOST:-localhost:80}
# 检查 Docker daemon 配置
if docker info 2>/dev/null | grep -q "Insecure Registries:" ; then
if ! docker info 2>/dev/null | grep -A 10 "Insecure Registries:" | grep -q "${registry_host}"; then
print_warning "Docker 未配置 insecure registry: ${registry_host}"
print_info "请添加以下配置到 Docker daemon.json:"
print_info ' "insecure-registries": ["'${registry_host}'"]'
print_info ""
print_info "macOS: Docker Desktop -> Preferences -> Docker Engine"
print_info "Linux: /etc/docker/daemon.json"
print_info ""
print_info "配置后需要重启 Docker"
echo ""
fi
fi
fi
}
# Harbor 登录
harbor_login() {
if [ "${PRIVATE_REGISTRY_ENABLED}" != "true" ]; then
return 0
fi
local harbor_host=${HARBOR_HOST:-localhost:80}
local harbor_user=${HARBOR_USERNAME:-admin}
local harbor_pass=${HARBOR_PASSWORD:-Harbor12345}
print_info "登录 Harbor: ${harbor_host}"
# Docker login to Harbor
echo "${harbor_pass}" | docker login "${harbor_host}" -u "${harbor_user}" --password-stdin 2>&1 | grep -v "WARNING"
if [ ${PIPESTATUS[1]} -eq 0 ]; then
print_success "Harbor 登录成功"
return 0
else
print_error "Harbor 登录失败"
return 1
fi
}
# 检查Registry是否可用
check_registry() {
local registry_host=${PRIVATE_REGISTRY_HOST:-localhost:15000}
local registry_host=${PRIVATE_REGISTRY_HOST:-localhost:80}
if [ "${PRIVATE_REGISTRY_ENABLED}" = "true" ]; then
if curl -f -s "http://${registry_host}/v2/_catalog" > /dev/null; then
print_success "本地私有 Registry 可用: $registry_host"
# 尝试 Harbor API v2.0
local protocol="http"
if [ "${HARBOR_INSECURE}" != "true" ]; then
protocol="https"
fi
# 检查 Harbor API
if curl -f -s -k "${protocol}://${registry_host}/api/v2.0/systeminfo" > /dev/null 2>&1; then
print_success "Harbor 可用: ${registry_host}"
return 0
# 回退到标准 Docker Registry API
elif curl -f -s "${protocol}://${registry_host}/v2/_catalog" > /dev/null 2>&1; then
print_success "Docker Registry 可用: ${registry_host}"
return 0
else
print_warning "本地私有 Registry 不可用: $registry_host"
print_info "可以手动启动 Registry 或禁用 PRIVATE_REGISTRY_ENABLED"
print_warning "Registry 不可用: ${registry_host}"
print_info "请确保 Harbor/Registry 已启动"
print_info "或禁用 PRIVATE_REGISTRY_ENABLED"
return 1
fi
fi
@@ -187,7 +243,7 @@ build_image() {
;;
ljwx-boot)
dockerfile="ljwx-boot/ljwx-boot-admin/Dockerfile.prod"
context="ljwx-boot"
context="."
;;
ljwx-bigscreen)
dockerfile="ljwx-bigscreen/bigscreen/Dockerfile.prod"
@@ -312,8 +368,12 @@ push_image() {
push_all() {
print_header "推送所有镜像到 ${REGISTRY}"
# 检查 Registry 可用性
check_registry || return 1
# 登录 Harbor
harbor_login || return 1
local components=(
"ljwx-mysql"
"ljwx-redis"
@@ -337,6 +397,7 @@ push_all() {
if [ ${#failed_components[@]} -eq 0 ]; then
print_success "所有镜像推送成功"
print_info "查看镜像: http://${HARBOR_HOST}/harbor/projects/${HARBOR_PROJECT}/repositories"
return 0
else
print_error "以下镜像推送失败: ${failed_components[*]}"
@@ -484,11 +545,21 @@ ${BLUE}LJWX 统一构建、推送、部署脚本 v2.0${NC}
配置文件: .env (从.env.unified复制)
版本号: ${LJWX_VERSION}
镜像仓库: ${REGISTRY}
Harbor地址: ${HARBOR_HOST}
Harbor项目: ${HARBOR_PROJECT}
Compose文件: ${COMPOSE_FILE}
Harbor 配置:
1. 确保 Harbor 已启动并可访问: http://${HARBOR_HOST}
2. 确认项目存在: ${HARBOR_PROJECT}
3. 如使用 HTTP Harbor,需配置 Docker insecure registry
macOS: Docker Desktop -> Preferences -> Docker Engine
添加: "insecure-registries": ["${HARBOR_HOST}"]
更多信息:
- 数据库迁移: ./db-migrate.sh help
- Docker Compose: docker-compose -f ${COMPOSE_FILE} --help
- Harbor 仓库: http://${HARBOR_HOST}/harbor/projects
EOF
}
@@ -595,6 +666,9 @@ fi
# 执行推送
if [ "$DO_PUSH" = true ]; then
# 登录 Harbor
harbor_login || exit 1
if [ -n "$COMPONENT" ]; then
push_image "$COMPONENT" "$VERSION" || exit 1
else
+117 -44
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+29 -2
View File
@@ -8,7 +8,22 @@
# ============================================
# ====== 构建阶段 ======
FROM localhost:15000/ljwx/python-base:3.12-slim AS builder
FROM python:3.12-slim AS builder
# 安装编译工具和运行时依赖
RUN apt-get update --fix-missing && \
apt-get install -y --no-install-recommends \
gcc \
g++ \
pkg-config \
default-libmysqlclient-dev \
default-mysql-client \
tzdata \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* && \
ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone && \
pip install --no-cache-dir --upgrade pip
WORKDIR /app
@@ -22,7 +37,19 @@ RUN --mount=type=cache,target=/root/.cache/pip \
pip install --user --no-cache-dir -r requirements-docker.txt
# ====== 运行阶段(最小化镜像)======
FROM localhost:15000/ljwx/python-base:3.12-slim
FROM python:3.12-slim
# 安装运行时依赖
RUN apt-get update --fix-missing && \
apt-get install -y --no-install-recommends \
default-libmysqlclient-dev \
default-mysql-client \
tzdata \
curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* && \
ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
WORKDIR /app
+6 -1
View File
@@ -11,10 +11,15 @@
# ====== 构建阶段 ======
# Docker buildx 会自动选择与目标平台匹配的基础镜像架构
# 基础镜像已支持 linux/amd64 和 linux/arm64
FROM localhost:15000/ljwx/java-maven-base:21-jdk-alpine AS builder
FROM eclipse-temurin:21-jdk-alpine AS builder
LABEL maintainer="[email protected]"
# 安装 Maven 和常用工具
RUN apk add --no-cache maven tzdata curl bash && \
ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone
WORKDIR /build
# ====== 第1层:下载 starter 依赖(独立缓存层)======