feat: add more image tag
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
# ================================
|
||||
# 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
|
||||
|
||||
# 生成版本信息文件,确保主服务和 Agent 使用相同的值(使用东八区时间)
|
||||
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.24 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
|
||||
COPY --from=frontend-builder /app/web/dist ./internal/static/dist
|
||||
|
||||
# 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.24 AS agent-builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy build info
|
||||
COPY --from=build-info /build-info /build-info
|
||||
|
||||
# Copy agent source and config example
|
||||
COPY agent/ ./agent/
|
||||
|
||||
# Download dependencies
|
||||
WORKDIR /app/agent
|
||||
RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod download
|
||||
|
||||
# Build agent for all platforms and package as tar.gz
|
||||
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 && \
|
||||
# Linux amd64
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o baihu-agent . && \
|
||||
tar -czvf /opt/agent/baihu-agent-linux-amd64.tar.gz baihu-agent config.example.ini && rm baihu-agent && \
|
||||
# Linux arm64
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o baihu-agent . && \
|
||||
tar -czvf /opt/agent/baihu-agent-linux-arm64.tar.gz baihu-agent config.example.ini && rm baihu-agent && \
|
||||
# macOS amd64
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o baihu-agent . && \
|
||||
tar -czvf /opt/agent/baihu-agent-darwin-amd64.tar.gz baihu-agent config.example.ini && rm baihu-agent && \
|
||||
# macOS arm64
|
||||
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o baihu-agent . && \
|
||||
tar -czvf /opt/agent/baihu-agent-darwin-arm64.tar.gz baihu-agent config.example.ini && rm baihu-agent && \
|
||||
# Windows amd64 (暂时注释)
|
||||
# CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o baihu-agent.exe . && \
|
||||
# tar -czvf /opt/agent/baihu-agent-windows-amd64.tar.gz baihu-agent.exe config.example.ini && rm baihu-agent.exe && \
|
||||
echo "Agent build completed for all platforms"
|
||||
# ================================
|
||||
# Stage 4: Final image
|
||||
# ================================
|
||||
FROM ghcr.io/engigu/baihu:base
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
ENV PATH="/app/envs/node/bin:/app/envs/python/bin:$PATH"
|
||||
ENV NODE_PATH="/app/envs/node/lib/node_modules"
|
||||
|
||||
# # 安装必要系统工具 + Node + Python
|
||||
# RUN sed -i 's@deb.debian.org@mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list.d/debian.sources \
|
||||
# && sed -i 's@security.debian.org@mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list.d/debian.sources \
|
||||
# && echo "${TZ}" > /etc/timezone \
|
||||
# && ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \
|
||||
# && apt-get update \
|
||||
# && apt-get install -y --no-install-recommends \
|
||||
# tzdata git gcc curl wget vim nodejs htop npm python3 python3-venv python3-pip \
|
||||
# && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy Go binary
|
||||
COPY --from=backend-builder /app/baihu .
|
||||
|
||||
# Copy frontend dist folder
|
||||
COPY --from=frontend-builder /app/web/dist ./internal/static/dist
|
||||
|
||||
# Copy configs and entrypoint
|
||||
COPY --from=backend-builder /app/configs ./configs
|
||||
COPY docker/docker-entrypoint.sh .
|
||||
|
||||
# Copy sync.py to /opt
|
||||
COPY custom/sync.py /opt/sync.py
|
||||
|
||||
# Copy agent binaries to /opt/agent
|
||||
COPY --from=agent-builder /opt/agent /opt/agent
|
||||
|
||||
RUN chmod +x /opt/sync.py \
|
||||
&& chmod +x docker-entrypoint.sh \
|
||||
&& touch "dont-not-delete-anythings" \
|
||||
&& echo "set encoding=utf-8" >> /etc/vim/vimrc
|
||||
|
||||
EXPOSE 8052
|
||||
|
||||
ENTRYPOINT ["./docker-entrypoint.sh"]
|
||||
@@ -0,0 +1,24 @@
|
||||
FROM alpine:3.19
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
ENV PATH="/app/envs/node/bin:/app/envs/python/bin:$PATH"
|
||||
ENV NODE_PATH="/app/envs/node/lib/node_modules"
|
||||
|
||||
# 安装必要系统工具 + Node + Python
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \
|
||||
&& apk add --no-cache \
|
||||
tzdata \
|
||||
git \
|
||||
gcc \
|
||||
musl-dev \
|
||||
curl \
|
||||
wget \
|
||||
vim \
|
||||
nodejs \
|
||||
npm \
|
||||
python3 \
|
||||
py3-pip \
|
||||
htop \
|
||||
&& cp /usr/share/zoneinfo/${TZ} /etc/localtime \
|
||||
&& echo "${TZ}" > /etc/timezone \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
@@ -0,0 +1,15 @@
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
ENV PATH="/app/envs/node/bin:/app/envs/python/bin:$PATH"
|
||||
ENV NODE_PATH="/app/envs/node/lib/node_modules"
|
||||
|
||||
# 安装必要系统工具 + Node + Python
|
||||
RUN sed -i 's@deb.debian.org@mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list.d/debian.sources \
|
||||
&& sed -i 's@security.debian.org@mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list.d/debian.sources \
|
||||
&& echo "${TZ}" > /etc/timezone \
|
||||
&& ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
tzdata git gcc curl wget vim nodejs htop npm python3 python3-venv python3-pip \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
@@ -0,0 +1,15 @@
|
||||
FROM debian:trixie-slim
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
ENV PATH="/app/envs/node/bin:/app/envs/python/bin:$PATH"
|
||||
ENV NODE_PATH="/app/envs/node/lib/node_modules"
|
||||
|
||||
# 安装必要系统工具 + Node + Python
|
||||
RUN sed -i 's@deb.debian.org@mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list.d/debian.sources \
|
||||
&& sed -i 's@security.debian.org@mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list.d/debian.sources \
|
||||
&& echo "${TZ}" > /etc/timezone \
|
||||
&& ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
tzdata git gcc curl wget vim nodejs htop npm python3 python3-venv python3-pip \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
|
||||
services:
|
||||
baihu:
|
||||
image: ghcr.io/engigu/baihu:latest
|
||||
container_name: baihu
|
||||
ports:
|
||||
- "8052:8052"
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
- ./configs:/app/configs
|
||||
- ./envs:/app/envs
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
# 以下环境变量可覆盖配置文件(可选)
|
||||
# - BH_SERVER_PORT=8052
|
||||
# - BH_SERVER_HOST=0.0.0.0
|
||||
# - BH_DB_TYPE=mysql
|
||||
# - BH_DB_HOST=localhost
|
||||
# - BH_DB_PORT=3306
|
||||
# - BH_DB_USER=root
|
||||
# - BH_DB_PASSWORD=password
|
||||
# - BH_DB_NAME=baihu
|
||||
# - BH_DB_TABLE_PREFIX=baihu_
|
||||
# - BH_SECRET=your_secret_key
|
||||
restart: unless-stopped
|
||||
@@ -0,0 +1,23 @@
|
||||
services:
|
||||
baihu:
|
||||
build: .
|
||||
ports:
|
||||
- "8052:8052"
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
- ./configs:/app/configs
|
||||
- ./envs:/app/envs
|
||||
environment:
|
||||
- TZ=Asia/Shanghai
|
||||
# 以下环境变量可覆盖配置文件(可选)
|
||||
# - BH_SERVER_PORT=8052
|
||||
# - BH_SERVER_HOST=0.0.0.0
|
||||
# - BH_DB_TYPE=mysql
|
||||
# - BH_DB_HOST=localhost
|
||||
# - BH_DB_PORT=3306
|
||||
# - BH_DB_USER=root
|
||||
# - BH_DB_PASSWORD=password
|
||||
# - BH_DB_NAME=baihu
|
||||
# - BH_DB_TABLE_PREFIX=baihu_
|
||||
# - BH_SECRET=your_secret_key
|
||||
restart: unless-stopped
|
||||
@@ -0,0 +1,81 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
PYTHON_VENV_DIR="/app/envs/python"
|
||||
NODE_ENV_DIR="/app/envs/node"
|
||||
|
||||
echo "[entrypoint] Starting environment initialization..."
|
||||
|
||||
# ============================
|
||||
# 创建基础目录
|
||||
# ============================
|
||||
mkdir -p \
|
||||
/app/data \
|
||||
/app/data/scripts \
|
||||
/app/configs \
|
||||
/app/envs \
|
||||
"$NODE_ENV_DIR"
|
||||
|
||||
# ============================
|
||||
# Python 虚拟环境(后台并行)
|
||||
# ============================
|
||||
(
|
||||
if [ ! -x "$PYTHON_VENV_DIR/bin/python" ]; then
|
||||
echo "[entrypoint][Python3] Creating Python virtual environment..."
|
||||
python3 -m venv "$PYTHON_VENV_DIR"
|
||||
"$PYTHON_VENV_DIR/bin/pip" config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
||||
"$PYTHON_VENV_DIR/bin/pip" install --upgrade pip setuptools wheel
|
||||
echo "[entrypoint][Python3] Python venv created"
|
||||
else
|
||||
echo "[entrypoint][Python3] Python venv exists"
|
||||
fi
|
||||
) &
|
||||
PYTHON_PID=$!
|
||||
|
||||
# ============================
|
||||
# Node 环境(后台并行)
|
||||
# ============================
|
||||
(
|
||||
echo "[entrypoint][Nodejs] Initializing Node npm prefix..."
|
||||
# npm 全局安装目录 → /app/envs/node
|
||||
npm config set prefix "$NODE_ENV_DIR"
|
||||
# npm 行为优化(防内存暴涨)
|
||||
npm config set registry https://registry.npmmirror.com
|
||||
npm config set audit false
|
||||
npm config set fund false
|
||||
npm config set progress false
|
||||
npm config set maxsockets 2
|
||||
echo "[entrypoint][Nodejs] Node npm configured"
|
||||
) &
|
||||
NODE_PID=$!
|
||||
|
||||
# 等待两个后台任务完成
|
||||
echo "[entrypoint] Waiting for environment initialization..."
|
||||
wait $PYTHON_PID
|
||||
wait $NODE_PID
|
||||
echo "[entrypoint] Environment initialization completed"
|
||||
|
||||
# Node 内存限制
|
||||
export NODE_OPTIONS="--max-old-space-size=256"
|
||||
|
||||
# ============================
|
||||
# 环境变量注入(等价 activate)
|
||||
# ============================
|
||||
export PATH="$PYTHON_VENV_DIR/bin:$NODE_ENV_DIR/bin:$PATH"
|
||||
export NODE_PATH="$NODE_ENV_DIR/lib/node_modules"
|
||||
export PYTHONPATH=/app/data/scripts:$PYTHONPATH
|
||||
|
||||
# ============================
|
||||
# 打印确认
|
||||
# ============================
|
||||
echo "[entrypoint][Python3] python: $(which python)"
|
||||
echo "[entrypoint][Python3] pip: $(which pip)"
|
||||
echo "[entrypoint][Nodejs] node: $(which node)"
|
||||
echo "[entrypoint][Nodejs] npm prefix: $(npm config get prefix)"
|
||||
echo "[entrypoint][Nodejs] npm root: $(npm root -g)"
|
||||
|
||||
# ============================
|
||||
# 启动应用
|
||||
# ============================
|
||||
cd /app
|
||||
exec ./baihu
|
||||
Reference in New Issue
Block a user