Files
junhong_cmp_fiber/Dockerfile.worker
huang 41bd3f5866
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Failing after 3s
修复架构问题:显式指定 linux/amd64 平台
问题:
- 私有仓库缓存了 ARM64 镜像(从 Mac M1/M2/M3 推送)
- 服务器是 AMD64 架构,导致 exec format error

解决:
- 在所有 FROM 指令中添加 --platform=linux/amd64
- 强制使用 AMD64 镜像,避免架构不匹配
- 适用于 Dockerfile.api 和 Dockerfile.worker
2026-01-20 10:20:12 +08:00

66 lines
1.5 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ================================
# 阶段 1: 构建阶段
# ================================
FROM --platform=linux/amd64 registry.boss160.cn/base/golang:1.25.6-alpine AS builder
# 使用阿里云镜像源加速
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 设置工作目录
WORKDIR /build
# 设置 Go 代理(必须在所有 go 命令前)
ENV GOPROXY=https://goproxy.cn,direct \
GO111MODULE=on \
CGO_ENABLED=0
# 安装必要的构建工具
RUN apk add --no-cache git ca-certificates tzdata
# 复制 go.mod 和 go.sum利用 Docker 缓存)
COPY go.mod go.sum ./
RUN go mod download
# 复制源代码
COPY . .
# 编译 Worker 服务(静态链接,使用并行编译)
RUN GOOS=linux GOARCH=amd64 go build \
-ldflags="-w -s" \
-o /build/worker \
./cmd/worker
# ================================
# 阶段 2: 运行阶段
# ================================
FROM --platform=linux/amd64 registry.boss160.cn/base/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
# 设置时区
ENV TZ=Asia/Shanghai
# 创建非 root 用户
RUN addgroup -g 1000 appuser && \
adduser -D -u 1000 -G appuser appuser
# 设置工作目录
WORKDIR /app
# 从构建阶段复制二进制文件
COPY --from=builder /build/worker /app/worker
# 复制配置文件
COPY configs /app/configs
# 切换到非 root 用户
USER appuser
# 启动命令
CMD ["/app/worker"]