chore: adjust minial build files
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
ARG BASE_TAG=base-minimal
|
||||
# ================================
|
||||
# Stage 1: Build frontend
|
||||
# ================================
|
||||
FROM --platform=$BUILDPLATFORM node:20-alpine AS frontend-builder
|
||||
|
||||
WORKDIR /app/web
|
||||
|
||||
# Copy package files
|
||||
COPY web/package*.json ./
|
||||
|
||||
# Install dependencies
|
||||
RUN npm ci
|
||||
|
||||
# Copy frontend source
|
||||
COPY web/ ./
|
||||
|
||||
# Build frontend
|
||||
RUN npm run build
|
||||
|
||||
# ================================
|
||||
# Stage 0: Generate build info
|
||||
# ================================
|
||||
FROM alpine:3.19 AS build-info
|
||||
|
||||
ARG VERSION
|
||||
ARG BUILD_TIME
|
||||
|
||||
# 生成版本信息文件
|
||||
RUN VERSION_VAL="${VERSION:-dev-$(TZ=Asia/Shanghai date '+%Y%m%d%H%M%S')}" && \
|
||||
BUILD_TIME_VAL="${BUILD_TIME:-$(TZ=Asia/Shanghai date '+%Y-%m-%d %H:%M:%S')}" && \
|
||||
mkdir -p /build-info && \
|
||||
echo "${VERSION_VAL}" > /build-info/version.txt && \
|
||||
echo "${BUILD_TIME_VAL}" > /build-info/build_time.txt
|
||||
|
||||
# ================================
|
||||
# Stage 2: Build backend
|
||||
# ================================
|
||||
FROM --platform=$BUILDPLATFORM golang:1.25 AS backend-builder
|
||||
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy build info
|
||||
COPY --from=build-info /build-info /build-info
|
||||
|
||||
# Go mod files
|
||||
COPY go.mod go.sum ./
|
||||
RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod download
|
||||
|
||||
# Copy backend source
|
||||
COPY . .
|
||||
|
||||
# Copy frontend dist (needed for embedding)
|
||||
COPY --from=frontend-builder /app/web/dist ./internal/static/dist
|
||||
|
||||
# Generate Swagger
|
||||
RUN go run github.com/swaggo/swag/cmd/swag@latest init -g main.go -o ./openapi_docs
|
||||
|
||||
# Build Go binary
|
||||
RUN VERSION_VAL=$(cat /build-info/version.txt) && \
|
||||
BUILD_TIME_VAL=$(cat /build-info/build_time.txt) && \
|
||||
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
|
||||
go build -ldflags="-s -w -X github.com/engigu/baihu-panel/internal/constant.Version=${VERSION_VAL} -X 'github.com/engigu/baihu-panel/internal/constant.BuildTime=${BUILD_TIME_VAL}'" \
|
||||
-o baihu .
|
||||
|
||||
# ================================
|
||||
# Stage 3: Build Agent (all platforms)
|
||||
# ================================
|
||||
FROM --platform=$BUILDPLATFORM golang:1.25 AS agent-builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy build info
|
||||
COPY --from=build-info /build-info /build-info
|
||||
|
||||
# Go mod files
|
||||
COPY go.mod go.sum ./
|
||||
RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod download
|
||||
|
||||
# Copy source needed for agent
|
||||
COPY internal/ ./internal/
|
||||
COPY agent/ ./agent/
|
||||
|
||||
# Build agent for all platforms and package as tar.gz
|
||||
WORKDIR /app/agent
|
||||
|
||||
RUN VERSION_VAL=$(cat /build-info/version.txt) && \
|
||||
BUILD_TIME_VAL=$(cat /build-info/build_time.txt) && \
|
||||
LDFLAGS="-s -w -X 'main.Version=${VERSION_VAL}' -X 'main.BuildTime=${BUILD_TIME_VAL}'" && \
|
||||
mkdir -p /opt/agent && \
|
||||
echo "${VERSION_VAL}" > /opt/agent/version.txt && \
|
||||
build_agent() { \
|
||||
local os=$1; local arch=$2; local suffix=$3; \
|
||||
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -ldflags="${LDFLAGS}" -o baihu-agent$suffix . && \
|
||||
tar -czvf /opt/agent/baihu-agent-$os-$arch.tar.gz baihu-agent$suffix config.example.ini && \
|
||||
rm baihu-agent$suffix; \
|
||||
} && \
|
||||
build_agent linux amd64 "" && \
|
||||
build_agent linux arm64 "" && \
|
||||
build_agent darwin amd64 "" && \
|
||||
build_agent darwin arm64 ""
|
||||
|
||||
# ================================
|
||||
# Stage 4: Final image
|
||||
# ================================
|
||||
FROM ghcr.io/engigu/baihu:${BASE_TAG}
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
ENV LANG=C.UTF-8
|
||||
ENV LC_ALL=C.UTF-8
|
||||
ENV MISE_DATA_DIR=/app/envs/mise
|
||||
ENV MISE_CONFIG_DIR=/app/envs/mise
|
||||
ENV PATH="/app/envs/mise/shims:/app/envs/mise/bin:$PATH"
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy Go binary
|
||||
COPY --from=backend-builder /app/baihu .
|
||||
|
||||
# Copy frontend assets
|
||||
COPY --from=frontend-builder /app/web/dist /www/baihu
|
||||
|
||||
# Copy configs and entrypoint
|
||||
COPY --from=backend-builder /app/configs ./configs
|
||||
COPY docker/docker-entrypoint.minimal.sh ./docker-entrypoint.sh
|
||||
|
||||
# Copy agent binaries
|
||||
COPY --from=agent-builder /opt/agent /opt/agent
|
||||
|
||||
RUN chmod +x docker-entrypoint.sh \
|
||||
&& echo "set encoding=utf-8" >> /etc/vim/vimrc \
|
||||
&& ln -sf /app/baihu /usr/local/bin/baihu
|
||||
|
||||
EXPOSE 8052
|
||||
|
||||
ENTRYPOINT ["./docker-entrypoint.sh"]
|
||||
@@ -0,0 +1,68 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
export LANG=C.UTF-8
|
||||
export LC_ALL=C.UTF-8
|
||||
|
||||
export MISE_HIDE_UPDATE_WARNING=1
|
||||
|
||||
# 日志输出格式
|
||||
COLOR_PREFIX="\033[1;36m[Entrypoint]\033[0m"
|
||||
log() {
|
||||
printf "${COLOR_PREFIX} %s\n" "$1"
|
||||
}
|
||||
|
||||
MISE_DIR="/app/envs/mise"
|
||||
|
||||
log "Starting environment initialization (Minimal Mode)..."
|
||||
|
||||
# ============================
|
||||
# 创建基础目录
|
||||
# ============================
|
||||
mkdir -p \
|
||||
/app/data \
|
||||
/app/data/scripts \
|
||||
/app/configs \
|
||||
/app/envs
|
||||
|
||||
# ============================
|
||||
# Mise 环境初始化
|
||||
# ============================
|
||||
log "Syncing mise environment from base..."
|
||||
mkdir -p "$MISE_DIR"
|
||||
rsync -a --ignore-existing /opt/mise-base/ "$MISE_DIR/" || true
|
||||
log "Mise environment synced"
|
||||
|
||||
# ============================
|
||||
# 环境变量注入
|
||||
# ============================
|
||||
export MISE_DATA_DIR="$MISE_DIR"
|
||||
export MISE_CONFIG_DIR="$MISE_DIR"
|
||||
export PATH="$MISE_DIR/shims:$MISE_DIR/bin:$PATH"
|
||||
|
||||
# 默认启用 Python 镜像源
|
||||
export PIP_INDEX_URL=${PIP_INDEX_URL:-https://pypi.org/simple}
|
||||
|
||||
# Node 内存限制
|
||||
export NODE_OPTIONS="--max-old-space-size=256"
|
||||
export PYTHONPATH=/app/data/scripts:$PYTHONPATH
|
||||
|
||||
# ============================
|
||||
# 打印确认
|
||||
# ============================
|
||||
log "mise version: $(mise --version 2>/dev/null | head -n 1)"
|
||||
[ -x "$(command -v python)" ] && log "python: $(python --version 2>&1 | head -n 1) at $(which python)" || log "python: not installed"
|
||||
[ -x "$(command -v node)" ] && log "node: $(node --version 2>&1 | head -n 1) at $(which node)" || log "node: not installed"
|
||||
[ -x "$(command -v npm)" ] && log "npm: $(npm --version 2>&1 | head -n 1) at $(which npm)" || log "npm: not installed"
|
||||
|
||||
# ============================
|
||||
# 将 baihu 注册到全局命令
|
||||
# ============================
|
||||
ln -sf /app/baihu /usr/local/bin/baihu
|
||||
|
||||
# ============================
|
||||
# 启动应用
|
||||
# ============================
|
||||
printf "\n\033[1;32m>>> Environment setup complete. Starting Baihu Server...\033[0m\n\n"
|
||||
|
||||
cd /app
|
||||
exec ./baihu server
|
||||
@@ -41,10 +41,8 @@ export MISE_DATA_DIR="$MISE_DIR"
|
||||
export MISE_CONFIG_DIR="$MISE_DIR"
|
||||
export PATH="$MISE_DIR/shims:$MISE_DIR/bin:$PATH"
|
||||
|
||||
# 使 Node.js 运行脚本时能够自动找到全局安装的模块 (仅当 npm 存在时执行)
|
||||
if command -v npm >/dev/null 2>&1; then
|
||||
export NODE_PATH=$(npm root -g 2>/dev/null)
|
||||
fi
|
||||
# 使 Node.js 运行脚本时能够自动找到全局安装的模块 (类似 Python site-packages 行为)
|
||||
export NODE_PATH=$(npm root -g 2>/dev/null)
|
||||
|
||||
# 默认启用 Python 镜像源
|
||||
export PIP_INDEX_URL=${PIP_INDEX_URL:-https://pypi.org/simple}
|
||||
@@ -57,9 +55,9 @@ export PYTHONPATH=/app/data/scripts:$PYTHONPATH
|
||||
# 打印确认
|
||||
# ============================
|
||||
log "mise version: $(mise --version 2>/dev/null | head -n 1)"
|
||||
[ -x "$(command -v python)" ] && log "python: $(python --version 2>&1 | head -n 1) at $(which python)" || log "python: not installed"
|
||||
[ -x "$(command -v node)" ] && log "node: $(node --version 2>&1 | head -n 1) at $(which node)" || log "node: not installed"
|
||||
[ -x "$(command -v npm)" ] && log "npm: $(npm --version 2>&1 | head -n 1) at $(which npm)" || log "npm: not installed"
|
||||
log "python: $(python --version 2>&1 | head -n 1) at $(which python)"
|
||||
log "node: $(node --version 2>&1 | head -n 1) at $(which node)"
|
||||
log "npm: $(npm --version 2>&1 | head -n 1) at $(which npm)"
|
||||
|
||||
# ============================
|
||||
# 将 baihu 注册到全局命令
|
||||
|
||||
Reference in New Issue
Block a user