From 8258160f95d0029f00cc0042110893adf3ac5751 Mon Sep 17 00:00:00 2001 From: Admin Date: Thu, 16 Jul 2026 10:33:23 +0000 Subject: [PATCH] fix: simplify CI/CD and Dockerfile - Use github.actor instead of gitea.actor - Add act-latest container for Gitea Actions - Simplify Dockerfile to use alpine - Remove CGO dependencies - Fix frontend build path --- .gitea/workflows/build.yml | 35 ++++++++++++----------------------- Dockerfile | 29 +++++------------------------ 2 files changed, 17 insertions(+), 47 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index bda8a7f..45d10ce 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -10,49 +10,39 @@ on: jobs: build: runs-on: ubuntu-latest + container: + image: catthehacker/ubuntu:act-latest steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20' - - name: Install frontend dependencies - working-directory: ./web - run: npm install - - name: Build frontend working-directory: ./web - run: npm run build + run: | + npm install + npm run build - - name: Set up Docker Buildx + - name: Setup Docker uses: docker/setup-buildx-action@v3 - - name: Login to Gitea Registry + - name: Login to Registry uses: docker/login-action@v3 with: registry: git.viaeon.com - username: ${{ gitea.actor }} + username: ${{ github.actor }} password: ${{ secrets.TOKEN }} - - name: Extract metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: git.viaeon.com/admin/anticaptcha - tags: | - type=ref,event=branch - type=semver,pattern={{version}} - type=sha - - name: Build and push uses: docker/build-push-action@v5 with: context: . push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + tags: git.viaeon.com/admin/anticaptcha:latest deploy: runs-on: ubuntu-latest @@ -68,5 +58,4 @@ jobs: script: | cd /opt/anticaptcha docker-compose pull - docker-compose up -d - docker image prune -f \ No newline at end of file + docker-compose up -d \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 7f7dad9..56d3105 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,19 @@ # 构建阶段 -FROM golang:1.22-bookworm AS builder - -# 安装构建依赖 -RUN apt-get update && apt-get install -y \ - git \ - gcc \ - g++ \ - make \ - libopencv-dev \ - && rm -rf /var/lib/apt/lists/* +FROM golang:1.22-alpine AS builder WORKDIR /app -# 复制 Go 模块文件 -COPY go.mod ./ - # 复制源代码 COPY . . -# 下载依赖 +# 构建 RUN go mod download || true - -# 构建(纯 Go 版本,暂不启用 CGO) RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o anticaptcha ./cmd/server # 运行阶段 -FROM debian:bookworm-slim +FROM alpine:3.20 -# 安装运行时依赖 -RUN apt-get update && apt-get install -y \ - ca-certificates \ - tzdata \ - libgomp1 \ - && rm -rf /var/lib/apt/lists/* +RUN apk add --no-cache ca-certificates tzdata WORKDIR /app @@ -40,7 +21,7 @@ WORKDIR /app COPY --from=builder /app/anticaptcha . COPY --from=builder /app/web/dist ./web/dist -# 创建数据目录 +# 创建目录 RUN mkdir -p /app/data /app/models ENV GIN_MODE=release