Initial commit: TaskPool React panel
- React frontend with route-level code splitting - Backend rebranded from Baihu to TaskPool - DB brand migration script and local compatibility
This commit is contained in:
@@ -0,0 +1,180 @@
|
||||
ARG BASE_TAG=base
|
||||
# ================================
|
||||
# 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 using cache mount for npm
|
||||
RUN --mount=type=cache,target=/root/.npm \
|
||||
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.26 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
|
||||
# Using Go build cache mount can significantly speed up consecutive builds
|
||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
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 (Optional: better to commit docs and only copy, but if needed, install once)
|
||||
# If openapi_docs exists, just use it, otherwise generate.
|
||||
# Here we avoid go run @latest by copying it if you have it locally.
|
||||
# If you don't, we install it once to the image.
|
||||
RUN go install github.com/swaggo/swag/cmd/swag@latest
|
||||
RUN swag init -g main.go -o ./openapi_docs
|
||||
|
||||
# Build Go binary using cache mounts for faster builds
|
||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
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/taskpool/internal/constant.Version=${VERSION_VAL} -X 'github.com/engigu/taskpool/internal/constant.BuildTime=${BUILD_TIME_VAL}'" \
|
||||
-o taskpool .
|
||||
|
||||
# ================================
|
||||
# Stage 3: Build Agent (all platforms)
|
||||
# ================================
|
||||
FROM --platform=$BUILDPLATFORM golang:1.26 AS agent-builder
|
||||
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy build info
|
||||
COPY --from=build-info /build-info /build-info
|
||||
|
||||
# Using Go build cache mount
|
||||
COPY go.mod go.sum ./
|
||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
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
|
||||
|
||||
# Build agent with parallel-aware logic or just cache mount
|
||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
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 && \
|
||||
# Helper to build and compress
|
||||
build_agent() { \
|
||||
local os=$1; local arch=$2; local suffix=$3; \
|
||||
local tmpdir="build-$os-$arch"; \
|
||||
mkdir -p $tmpdir && cp config.example.ini $tmpdir/ && \
|
||||
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -ldflags="${LDFLAGS}" -o $tmpdir/taskpool-agent$suffix . && \
|
||||
(cd $tmpdir && tar -czvf /opt/agent/taskpool-agent-$os-$arch.tar.gz taskpool-agent$suffix config.example.ini) && \
|
||||
rm -rf $tmpdir; \
|
||||
} ; \
|
||||
build_agent linux amd64 "" & pid1=$!; \
|
||||
build_agent linux arm64 "" & pid2=$!; \
|
||||
build_agent android arm64 "" & pid3=$!; \
|
||||
build_agent darwin amd64 "" & pid4=$!; \
|
||||
build_agent darwin arm64 "" & pid5=$!; \
|
||||
wait $pid1 && wait $pid2 && wait $pid3 && wait $pid4 && wait $pid5 && \
|
||||
echo "Agent build completed for all platforms"
|
||||
# ================================
|
||||
# Stage 4: Final image
|
||||
# ================================
|
||||
ARG BASE_TAG
|
||||
FROM ghcr.io/engigu/taskpool:${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"
|
||||
|
||||
# # 安装必要系统工具 + 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/taskpool .
|
||||
|
||||
# Copy frontend assets to /www/taskpool (No embed in Docker)
|
||||
COPY --from=frontend-builder /app/web/dist /www/taskpool
|
||||
|
||||
# Copy configs and entrypoint
|
||||
COPY --from=backend-builder /app/configs ./configs
|
||||
COPY --from=backend-builder /app/example ./example
|
||||
COPY builtin/ /www/builtin
|
||||
COPY docker/docker-entrypoint.sh .
|
||||
|
||||
|
||||
|
||||
# Copy agent binaries to /opt/agent
|
||||
COPY --from=agent-builder /opt/agent /opt/agent
|
||||
|
||||
COPY docker/mise-hook.sh /etc/profile.d/mise-hook.sh
|
||||
|
||||
RUN chmod +x docker-entrypoint.sh \
|
||||
&& cat /etc/profile.d/mise-hook.sh >> /etc/bash.bashrc \
|
||||
&& echo "set encoding=utf-8" >> /etc/vim/vimrc \
|
||||
&& ln -sf /app/taskpool /usr/local/bin/taskpool
|
||||
|
||||
ENV MISE_TRUSTED_CONFIG_PATHS=/app/data/scripts
|
||||
|
||||
EXPOSE 8052
|
||||
|
||||
ENTRYPOINT ["./docker-entrypoint.sh"]
|
||||
@@ -0,0 +1,26 @@
|
||||
FROM alpine:3.19
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
ENV NODE_VERSION=23.11.1
|
||||
ENV PYTHON_VERSION=3.13.12
|
||||
ENV MISE_DATA_DIR=/opt/mise-base
|
||||
ENV MISE_CONFIG_DIR=/opt/mise-base
|
||||
ENV PATH="/opt/mise-base/shims:/opt/mise-base/bin:$PATH"
|
||||
|
||||
# 安装必要系统工具
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \
|
||||
&& apk add --no-cache \
|
||||
tzdata git bash curl wget vim htop ca-certificates rsync openssh-client \
|
||||
&& BUILD_DEPS="build-base libffi-dev openssl-dev bzip2-dev zlib-dev readline-dev sqlite-dev ncurses-dev xz-dev" \
|
||||
&& apk add --no-cache $BUILD_DEPS \
|
||||
&& curl https://mise.run | MISE_INSTALL_PATH=/usr/local/bin/mise sh \
|
||||
&& MISE_DATA_DIR=/opt/mise-base MISE_CONFIG_DIR=/opt/mise-base MISE_HTTP_TIMEOUT=300 \
|
||||
PYTHON_BUILD_MIRROR_URL=https://pyenv.pages.dev/api/mirror/binaries \
|
||||
mise use -g node@${NODE_VERSION} python@${PYTHON_VERSION} \
|
||||
&& mise prune -- -f \
|
||||
&& apk del $BUILD_DEPS \
|
||||
&& ln -sf /usr/bin/python3 /usr/bin/python \
|
||||
&& cp /usr/share/zoneinfo/${TZ} /etc/localtime \
|
||||
&& echo "${TZ}" > /etc/timezone \
|
||||
&& rm -rf /var/cache/apk/* \
|
||||
&& rm -rf /root/.cache/mise /root/.cache/pip /opt/mise-base/cache/*
|
||||
@@ -0,0 +1,29 @@
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
ENV NODE_VERSION=23.11.1
|
||||
ENV PYTHON_VERSION=3.13.12
|
||||
ENV MISE_DATA_DIR=/opt/mise-base
|
||||
ENV MISE_CONFIG_DIR=/opt/mise-base
|
||||
ENV PATH="/opt/mise-base/shims:/opt/mise-base/bin:$PATH"
|
||||
|
||||
# 安装必要系统工具
|
||||
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 curl wget vim htop ca-certificates rsync openssh-client \
|
||||
&& BUILD_DEPS="gcc build-essential libssl-dev zlib1g-dev libbz2-dev \
|
||||
libreadline-dev libsqlite3-dev libncursesw5-dev \
|
||||
xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev" \
|
||||
&& apt-get install -y --no-install-recommends $BUILD_DEPS \
|
||||
&& curl https://mise.run | MISE_INSTALL_PATH=/usr/local/bin/mise sh \
|
||||
&& MISE_DATA_DIR=/opt/mise-base MISE_CONFIG_DIR=/opt/mise-base MISE_HTTP_TIMEOUT=300 \
|
||||
PYTHON_BUILD_MIRROR_URL=https://pyenv.pages.dev/api/mirror/binaries \
|
||||
mise use -g node@${NODE_VERSION} python@${PYTHON_VERSION} \
|
||||
&& mise prune -- -f \
|
||||
&& apt-get purge -y --auto-remove $BUILD_DEPS \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& rm -rf /root/.cache/mise /root/.cache/pip /opt/mise-base/cache/*
|
||||
@@ -0,0 +1,30 @@
|
||||
FROM debian:trixie-slim
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
ENV NODE_VERSION=23.11.1
|
||||
ENV PYTHON_VERSION=3.13.12
|
||||
ENV MISE_DATA_DIR=/opt/mise-base
|
||||
ENV MISE_CONFIG_DIR=/opt/mise-base
|
||||
ENV PATH="/opt/mise-base/shims:/opt/mise-base/bin:$PATH"
|
||||
|
||||
# 安装必要系统工具
|
||||
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 curl wget vim htop ca-certificates rsync openssh-client \
|
||||
&& BUILD_DEPS="gcc build-essential libssl-dev zlib1g-dev libbz2-dev \
|
||||
libreadline-dev libsqlite3-dev libncursesw5-dev \
|
||||
xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev" \
|
||||
&& apt-get install -y --no-install-recommends $BUILD_DEPS \
|
||||
&& curl https://mise.run | MISE_INSTALL_PATH=/usr/local/bin/mise sh \
|
||||
&& MISE_DATA_DIR=/opt/mise-base MISE_CONFIG_DIR=/opt/mise-base MISE_HTTP_TIMEOUT=300 \
|
||||
PYTHON_BUILD_MIRROR_URL=https://pyenv.pages.dev/api/mirror/binaries \
|
||||
mise use -g node@${NODE_VERSION} python@${PYTHON_VERSION} \
|
||||
&& mise prune -- -f \
|
||||
&& apt-get purge -y --auto-remove $BUILD_DEPS \
|
||||
&& ln -sf /usr/bin/python3 /usr/bin/python \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& rm -rf /root/.cache/mise /root/.cache/pip /opt/mise-base/cache/*
|
||||
@@ -0,0 +1,19 @@
|
||||
FROM debian:trixie-slim
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
ENV MISE_DATA_DIR=/opt/mise-base
|
||||
ENV MISE_CONFIG_DIR=/opt/mise-base
|
||||
ENV PATH="/opt/mise-base/shims:/opt/mise-base/bin:$PATH"
|
||||
|
||||
# 安装必要系统工具并仅预装 mise
|
||||
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 curl wget vim htop ca-certificates rsync openssh-client \
|
||||
&& curl https://mise.run | MISE_INSTALL_PATH=/usr/local/bin/mise sh \
|
||||
&& mkdir -p /opt/mise-base \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& rm -rf /root/.cache/mise /opt/mise-base/cache/*
|
||||
@@ -0,0 +1,53 @@
|
||||
FROM golang:1.26-trixie
|
||||
|
||||
ENV TZ=Asia/Shanghai
|
||||
ENV LANG=C.UTF-8
|
||||
ENV LC_ALL=C.UTF-8
|
||||
|
||||
ENV NODE_VERSION=23.11.1
|
||||
ENV PYTHON_VERSION=3.13.12
|
||||
|
||||
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 \
|
||||
sudo gosu tzdata git curl wget vim htop ca-certificates rsync openssh-client \
|
||||
&& BUILD_DEPS="gcc build-essential libssl-dev zlib1g-dev libbz2-dev \
|
||||
libreadline-dev libsqlite3-dev libncursesw5-dev \
|
||||
xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev" \
|
||||
&& apt-get install -y --no-install-recommends $BUILD_DEPS \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY docker/mise-hook.sh /etc/profile.d/mise-hook.sh
|
||||
RUN cat /etc/profile.d/mise-hook.sh >> /etc/bash.bashrc
|
||||
|
||||
RUN go env -w GOPROXY=https://goproxy.cn,direct
|
||||
|
||||
ENV MISE_GLOBAL_DIR=/opt/mise-dev
|
||||
ENV PATH="/opt/mise-dev/shims:/opt/mise-dev/bin:$PATH"
|
||||
RUN curl https://mise.run | MISE_INSTALL_PATH=/usr/local/bin/mise sh \
|
||||
&& MISE_DATA_DIR=/opt/mise-dev MISE_CONFIG_DIR=/opt/mise-dev MISE_HTTP_TIMEOUT=300 \
|
||||
PYTHON_BUILD_MIRROR_URL=https://pyenv.pages.dev/api/mirror/binaries \
|
||||
mise use -g node@${NODE_VERSION} python@${PYTHON_VERSION} \
|
||||
&& mise prune -- -f
|
||||
|
||||
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"
|
||||
|
||||
ENV NPM_CONFIG_CACHE=/var/cache/npm
|
||||
|
||||
COPY docker/docker-entrypoint-dev.sh /usr/local/bin/
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint-dev.sh
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ENV MISE_TRUSTED_CONFIG_PATHS=/app/data/scripts
|
||||
|
||||
EXPOSE 8052 5173
|
||||
|
||||
ENTRYPOINT ["docker-entrypoint-dev.sh"]
|
||||
|
||||
CMD ["make", "dev"]
|
||||
@@ -0,0 +1,147 @@
|
||||
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.26 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/taskpool/internal/constant.Version=${VERSION_VAL} -X 'github.com/engigu/taskpool/internal/constant.BuildTime=${BUILD_TIME_VAL}'" \
|
||||
-o taskpool .
|
||||
|
||||
# ================================
|
||||
# Stage 3: Build Agent (all platforms)
|
||||
# ================================
|
||||
FROM --platform=$BUILDPLATFORM golang:1.26 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 taskpool-agent$suffix . && \
|
||||
tar -czvf /opt/agent/taskpool-agent-$os-$arch.tar.gz taskpool-agent$suffix config.example.ini && \
|
||||
rm taskpool-agent$suffix; \
|
||||
} && \
|
||||
build_agent linux amd64 "" && \
|
||||
build_agent linux arm64 "" && \
|
||||
build_agent android arm64 "" && \
|
||||
build_agent darwin amd64 "" && \
|
||||
build_agent darwin arm64 ""
|
||||
|
||||
# ================================
|
||||
# Stage 4: Final image
|
||||
# ================================
|
||||
FROM ghcr.io/engigu/taskpool:${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/taskpool .
|
||||
|
||||
# Copy frontend assets
|
||||
COPY --from=frontend-builder /app/web/dist /www/taskpool
|
||||
|
||||
# Copy configs and entrypoint
|
||||
COPY --from=backend-builder /app/configs ./configs
|
||||
COPY --from=backend-builder /app/example ./example
|
||||
COPY builtin/ /www/builtin
|
||||
COPY docker/docker-entrypoint.minimal.sh ./docker-entrypoint.sh
|
||||
|
||||
# Copy agent binaries
|
||||
COPY --from=agent-builder /opt/agent /opt/agent
|
||||
|
||||
COPY docker/mise-hook.sh /etc/profile.d/mise-hook.sh
|
||||
|
||||
RUN chmod +x docker-entrypoint.sh \
|
||||
&& cat /etc/profile.d/mise-hook.sh >> /etc/bash.bashrc \
|
||||
&& echo "set encoding=utf-8" >> /etc/vim/vimrc \
|
||||
&& ln -sf /app/taskpool /usr/local/bin/taskpool
|
||||
|
||||
ENV MISE_TRUSTED_CONFIG_PATHS=/app/data/scripts
|
||||
|
||||
EXPOSE 8052
|
||||
|
||||
ENTRYPOINT ["./docker-entrypoint.sh"]
|
||||
@@ -0,0 +1,93 @@
|
||||
#!/bin/bash
|
||||
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"
|
||||
}
|
||||
|
||||
ensure_cache_ownership() {
|
||||
local dir="$1"
|
||||
local target_uid="$2"
|
||||
local target_gid="$3"
|
||||
if [ ! -d "$dir" ]; then
|
||||
mkdir -p "$dir"
|
||||
chown "$target_uid:$target_gid" "$dir"
|
||||
return
|
||||
fi
|
||||
local current_uid=$(stat -c '%u' "$dir")
|
||||
local dirty_file=$(find "$dir" -mindepth 1 ! -uid "$target_uid" -print -quit 2>/dev/null)
|
||||
if [ "$current_uid" == "$target_uid" ] && [ -z "$dirty_file" ]; then
|
||||
log "Cache hit: $dir owned by $target_uid. Reusing."
|
||||
else
|
||||
if [ -n "$dirty_file" ]; then
|
||||
log "Dirty cache detected in $dir (Found root-owned files like $dirty_file)."
|
||||
else
|
||||
log "User changed ($current_uid -> $target_uid). Resetting cache in $dir..."
|
||||
fi
|
||||
|
||||
log "Nuking directory to ensure clean state..."
|
||||
|
||||
find "$dir" -mindepth 1 -delete 2>/dev/null || rm -rf "$dir"/*
|
||||
|
||||
chown "$target_uid:$target_gid" "$dir"
|
||||
log "Cache reset complete. Ownership transferred to $target_uid."
|
||||
fi
|
||||
}
|
||||
|
||||
log "Initializing Development Environment..."
|
||||
|
||||
DEV_UID=${DEV_UID:-1000}
|
||||
DEV_GID=${DEV_GID:-1000}
|
||||
|
||||
EXISTING_USER=$(getent passwd "$DEV_UID" | cut -d: -f1 | head -n 1)
|
||||
|
||||
if [ -n "$EXISTING_USER" ]; then
|
||||
TARGET_USER="$EXISTING_USER"
|
||||
log "UID $DEV_UID already exists as user '$TARGET_USER'. Using existing user."
|
||||
else
|
||||
TARGET_USER="devuser"
|
||||
log "Creating user '$TARGET_USER' (UID: $DEV_UID, GID: $DEV_GID)..."
|
||||
groupadd -o -g "$DEV_GID" devgroup
|
||||
useradd -o -u "$DEV_UID" -g "$DEV_GID" -m -s /bin/bash "$TARGET_USER"
|
||||
fi
|
||||
|
||||
if [ "$TARGET_USER" != "root" ]; then
|
||||
echo "$TARGET_USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$TARGET_USER
|
||||
chmod 0440 /etc/sudoers.d/$TARGET_USER
|
||||
fi
|
||||
|
||||
export npm_config_cache=/var/cache/npm
|
||||
mkdir -p /var/cache/npm /app/web/node_modules
|
||||
chown "$DEV_UID:$DEV_GID" /var/cache/npm /app/web/node_modules
|
||||
|
||||
if [ "$DEV_UID" != "0" ]; then
|
||||
ensure_cache_ownership "/app/envs" "$DEV_UID" "$DEV_GID"
|
||||
ensure_cache_ownership "/app/web/node_modules" "$DEV_UID" "$DEV_GID"
|
||||
ensure_cache_ownership "/var/cache/npm" "$DEV_UID" "$DEV_GID"
|
||||
ensure_cache_ownership "/go" "$DEV_UID" "$DEV_GID"
|
||||
fi
|
||||
|
||||
MISE_DIR="/app/envs/mise"
|
||||
mkdir -p "$MISE_DIR"
|
||||
log "Syncing mise environment from base..."
|
||||
rsync -a --chown="$DEV_UID:$DEV_GID" --ignore-existing /opt/mise-dev/ "$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"
|
||||
|
||||
export PIP_INDEX_URL=${PIP_INDEX_URL:-https://pypi.org/simple}
|
||||
|
||||
log "mise version: $(mise --version 2>/dev/null | head -n 1)"
|
||||
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)"
|
||||
|
||||
log "Environment ready! Starting command as user '$TARGET_USER' (UID: $DEV_UID)..."
|
||||
exec gosu "$DEV_UID:$DEV_GID" "$@"
|
||||
@@ -0,0 +1,80 @@
|
||||
#!/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
|
||||
|
||||
if [ -d "/app/example" ]; then
|
||||
mkdir -p /app/data/scripts/example
|
||||
rsync -a --ignore-existing /app/example/ /app/data/scripts/example/ || true
|
||||
log "Example scripts synced to /app/data/scripts/example"
|
||||
else
|
||||
log "No example directory found, skipping example sync"
|
||||
fi
|
||||
|
||||
# ============================
|
||||
# Mise 环境初始化
|
||||
# ============================
|
||||
mkdir -p "$MISE_DIR"
|
||||
if [ -d "/opt/mise-base" ]; then
|
||||
log "Syncing mise environment from base..."
|
||||
rsync -a --ignore-existing /opt/mise-base/ "$MISE_DIR/" || true
|
||||
log "Mise environment synced"
|
||||
else
|
||||
log "No base mise environment found, skipping sync"
|
||||
fi
|
||||
|
||||
# ============================
|
||||
# 环境变量注入
|
||||
# ============================
|
||||
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"
|
||||
|
||||
# ============================
|
||||
# 将 taskpool 注册到全局命令
|
||||
# ============================
|
||||
ln -sf /app/taskpool /usr/local/bin/taskpool
|
||||
|
||||
# ============================
|
||||
# 启动应用
|
||||
# ============================
|
||||
printf "\n\033[1;32m>>> Environment setup complete. Starting TaskPool Server...\033[0m\n\n"
|
||||
|
||||
cd /app
|
||||
exec taskpool server
|
||||
@@ -0,0 +1,91 @@
|
||||
#!/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..."
|
||||
|
||||
# ============================
|
||||
# 创建基础目录
|
||||
# ============================
|
||||
mkdir -p \
|
||||
/app/data \
|
||||
/app/data/scripts \
|
||||
/app/configs \
|
||||
/app/envs
|
||||
|
||||
if [ -d "/app/example" ]; then
|
||||
mkdir -p /app/data/scripts/example
|
||||
rsync -a --ignore-existing /app/example/ /app/data/scripts/example/ || true
|
||||
log "Example scripts synced to /app/data/scripts/example"
|
||||
else
|
||||
log "No example directory found, skipping example sync"
|
||||
fi
|
||||
|
||||
# ============================
|
||||
# Mise 环境初始化
|
||||
# ============================
|
||||
# 始终尝试同步基础环境(以补充用户挂载卷中可能缺失的文件,如 config.toml)
|
||||
mkdir -p "$MISE_DIR"
|
||||
if [ -d "/opt/mise-base" ]; then
|
||||
log "Syncing mise environment from base..."
|
||||
# 使用 rsync 同步: -a 归档模式, --ignore-existing 不覆盖已存在文件
|
||||
rsync -a --ignore-existing /opt/mise-base/ "$MISE_DIR/" || true
|
||||
log "Mise environment synced"
|
||||
else
|
||||
log "No base mise environment found, skipping sync"
|
||||
fi
|
||||
|
||||
# ============================
|
||||
# 环境变量注入
|
||||
# ============================
|
||||
export MISE_DATA_DIR="$MISE_DIR"
|
||||
export MISE_CONFIG_DIR="$MISE_DIR"
|
||||
export PATH="$MISE_DIR/shims:$MISE_DIR/bin:$PATH"
|
||||
|
||||
log "Mise PATH configured, verifying runtimes..."
|
||||
|
||||
# 默认启用 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 "Checking mise..."
|
||||
log " - mise: $(mise --version 2>/dev/null | head -n 1 || echo "not found")"
|
||||
|
||||
log "Checking python..."
|
||||
log " - python: $(python --version 2>&1 | head -n 1 || echo "not found")"
|
||||
|
||||
log "Checking node..."
|
||||
log " - node: $(node --version 2>&1 | head -n 1 || echo "not found")"
|
||||
|
||||
log "Checking npm..."
|
||||
log " - npm: $(npm --version 2>&1 | head -n 1 || echo "not found")"
|
||||
|
||||
# ============================
|
||||
# 将 taskpool 注册到全局命令
|
||||
# ============================
|
||||
ln -sf /app/taskpool /usr/local/bin/taskpool
|
||||
|
||||
# ============================
|
||||
# 启动应用
|
||||
# ============================
|
||||
printf "\n\033[1;32m>>> Environment setup complete. Starting TaskPool Server...\033[0m\n\n"
|
||||
|
||||
cd /app
|
||||
exec taskpool server
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 面向终端的交互式 Hook 拦截器
|
||||
# 目的是为了在终端执行 node 相关任务时具有与 Go 系统底层相同的 NODE_PATH 环境
|
||||
#
|
||||
# 支持以下各种执行场景:
|
||||
# 1. mise exec node@23.11.1 -- node index.js (指明具体版本)
|
||||
# 2. mise exec python@3 node@23 -- node index.js (混合语言注入)
|
||||
# 3. mise exec node -- node index.js (显式指定环境但使用默认版本)
|
||||
# 4. mise exec -- node index.js (完全隐式环境,由项目配置决定)
|
||||
mise() {
|
||||
if [[ "$1" == "exec" || "$1" == "x" ]]; then
|
||||
local node_spec=""
|
||||
# 优先从命令行参数中提取指定的 node 版本(如 node@23...)
|
||||
for arg in "$@"; do
|
||||
if [[ "$arg" == "--" ]]; then
|
||||
break
|
||||
elif [[ "$arg" == "node" || "$arg" == node@* ]]; then
|
||||
node_spec="$arg"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# 如果命令行参数中没写,则尝试检测该环境下是否有已激活的默认 node
|
||||
if [[ -z "$node_spec" ]]; then
|
||||
if command mise which node >/dev/null 2>&1; then
|
||||
node_spec="node"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "$node_spec" ]]; then
|
||||
local node_dir=$(command mise where "$node_spec" 2>/dev/null)
|
||||
if [[ -n "$node_dir" ]]; then
|
||||
NODE_PATH="$node_dir/lib/node_modules" command mise "$@"
|
||||
return $?
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
# 非 Node 场景或拦截失败,正常向下执行
|
||||
command mise "$@"
|
||||
}
|
||||
|
||||
# 导出此函数,供所有子环境继承使用
|
||||
export -f mise
|
||||
Reference in New Issue
Block a user