Files
TaskPool/Dockerfile
T

82 lines
2.2 KiB
Docker
Raw Normal View History

2025-12-23 10:59:38 +08:00
# ================================
2025-12-20 09:30:16 +08:00
# Stage 1: Build frontend
2025-12-23 10:59:38 +08:00
# ================================
2025-12-20 09:30:16 +08:00
FROM 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
2025-12-23 10:59:38 +08:00
# ================================
2025-12-20 09:30:16 +08:00
# Stage 2: Build backend
2025-12-23 10:59:38 +08:00
# ================================
2025-12-20 12:00:08 +08:00
FROM --platform=$BUILDPLATFORM golang:1.24-alpine AS backend-builder
ARG TARGETOS
ARG TARGETARCH
2025-12-23 10:59:38 +08:00
ARG VERSION=dev
ARG BUILD_TIME
2025-12-20 09:30:16 +08:00
WORKDIR /app
2025-12-23 11:07:59 +08:00
# Go mod files
2025-12-20 09:30:16 +08:00
COPY go.mod go.sum ./
RUN go env -w GOPROXY=https://goproxy.cn,direct && go mod download
2025-12-23 11:07:59 +08:00
# Copy backend source
2025-12-20 09:30:16 +08:00
COPY . .
2025-12-23 10:59:38 +08:00
# Copy frontend dist
2025-12-20 09:30:16 +08:00
COPY --from=frontend-builder /app/web/dist ./internal/static/dist
2025-12-23 10:59:38 +08:00
# Build Go binary
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -ldflags="-s -w -X baihu/internal/constant.Version=${VERSION} -X 'baihu/internal/constant.BuildTime=${BUILD_TIME}'" \
-o baihu .
2025-12-20 09:30:16 +08:00
2025-12-23 10:59:38 +08:00
# ================================
# Stage 3: Final image
# ================================
2025-12-20 09:30:16 +08:00
FROM debian:bookworm-slim
ENV TZ=Asia/Shanghai
2025-12-23 22:12:27 +08:00
ENV PATH="/app/envs/node/bin:/app/envs/python/bin:$PATH"
ENV NODE_PATH="/app/envs/node/lib/node_modules"
2025-12-20 09:30:16 +08:00
2025-12-23 10:59:38 +08:00
# 安装必要系统工具 + Node + Python
2025-12-23 11:10:05 +08:00
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 \
2025-12-20 09:30:16 +08:00
&& echo "${TZ}" > /etc/timezone \
&& ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime \
2025-12-23 10:59:38 +08:00
&& apt-get update \
&& apt-get install -y --no-install-recommends \
2025-12-23 18:33:54 +08:00
tzdata git gcc curl wget vim nodejs htop npm python3 python3-venv python3-pip \
2025-12-23 10:59:38 +08:00
&& rm -rf /var/lib/apt/lists/*
2025-12-20 09:30:16 +08:00
WORKDIR /app
2025-12-23 10:59:38 +08:00
# Copy Go binary
2025-12-20 09:30:16 +08:00
COPY --from=backend-builder /app/baihu .
2025-12-23 10:59:38 +08:00
# Copy frontend dist folder
COPY --from=frontend-builder /app/web/dist ./internal/static/dist
2025-12-20 09:30:16 +08:00
2025-12-23 10:59:38 +08:00
# Copy configs and entrypoint
COPY --from=backend-builder /app/configs ./configs
2025-12-21 10:23:25 +08:00
COPY docker-entrypoint.sh .
2025-12-23 11:27:31 +08:00
RUN chmod +x docker-entrypoint.sh && touch "dont-not-delete-anythings|不要删除这里的任何东西"
2025-12-20 09:30:16 +08:00
EXPOSE 8052
2025-12-23 11:07:59 +08:00
ENTRYPOINT ["./docker-entrypoint.sh"]