From 2336b140ccf0c03847c9250d90915889f218334d Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 20 Jan 2026 09:33:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20Docker=20=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=EF=BC=9A=E5=90=AF=E7=94=A8=20BuildKit=20+=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E9=98=BF=E9=87=8C=E4=BA=91=20Alpine=20=E9=95=9C?= =?UTF-8?q?=E5=83=8F=E6=BA=90=E5=8A=A0=E9=80=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy.yaml | 4 ++-- Dockerfile.api | 9 ++++++--- Dockerfile.worker | 3 +++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 633ce33..6ecaa51 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -42,12 +42,12 @@ jobs: - name: 构建 API 镜像 run: | - docker build -f Dockerfile.api -t ${{ env.API_IMAGE }}:${{ steps.tag.outputs.tag }} . + DOCKER_BUILDKIT=1 docker build -f Dockerfile.api -t ${{ env.API_IMAGE }}:${{ steps.tag.outputs.tag }} . docker tag ${{ env.API_IMAGE }}:${{ steps.tag.outputs.tag }} ${{ env.API_IMAGE }}:${{ github.sha }} - name: 构建 Worker 镜像 run: | - docker build -f Dockerfile.worker -t ${{ env.WORKER_IMAGE }}:${{ steps.tag.outputs.tag }} . + DOCKER_BUILDKIT=1 docker build -f Dockerfile.worker -t ${{ env.WORKER_IMAGE }}:${{ steps.tag.outputs.tag }} . docker tag ${{ env.WORKER_IMAGE }}:${{ steps.tag.outputs.tag }} ${{ env.WORKER_IMAGE }}:${{ github.sha }} - name: 推送镜像到 Registry diff --git a/Dockerfile.api b/Dockerfile.api index 6f8b8a6..13f85a4 100644 --- a/Dockerfile.api +++ b/Dockerfile.api @@ -34,8 +34,11 @@ RUN go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate # ================================ FROM alpine:3.19 +# 使用阿里云镜像源加速 +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories + # 安装运行时依赖 -RUN apk add --no-cache ca-certificates tzdata bash curl +RUN apk add --no-cache ca-certificates tzdata bash # 设置时区 ENV TZ=Asia/Shanghai @@ -65,9 +68,9 @@ USER appuser # 暴露端口 EXPOSE 8088 -# 健康检查 +# 健康检查(使用 Alpine 自带的 wget) HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \ - CMD curl -f http://localhost:8088/health || exit 1 + CMD wget --no-verbose --tries=1 --spider http://localhost:8088/health || exit 1 # 启动命令 ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/Dockerfile.worker b/Dockerfile.worker index acb3a57..448317a 100644 --- a/Dockerfile.worker +++ b/Dockerfile.worker @@ -31,6 +31,9 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ # ================================ FROM alpine:3.19 +# 使用阿里云镜像源加速 +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories + # 安装运行时依赖 RUN apk add --no-cache ca-certificates tzdata bash