chore: Refactor Dockerfile and build workflow for improved efficiency
All checks were successful
Build / build (push) Successful in 4m4s
Build / build-docker (push) Successful in 1m16s

- Removed the build stage from the Dockerfile, simplifying the image creation process.
- Updated the Dockerfile to directly copy the pre-built binary instead of using a multi-stage build.
- Modified the build workflow to eliminate unnecessary build arguments, streamlining the configuration.
This commit is contained in:
lafay
2026-01-10 05:21:45 +08:00
parent fd5a0e8405
commit 3e8b7d150d
2 changed files with 3 additions and 30 deletions

View File

@@ -1,33 +1,8 @@
# 构建阶段
FROM golang:1.25-alpine AS builder
# 安装必要的工具
RUN apk add --no-cache git ca-certificates tzdata
# 设置工作目录
WORKDIR /build
# 复制 go mod 文件
COPY go.mod go.sum ./
# 下载依赖
RUN go mod download
# 复制源代码
COPY . .
# 构建应用
ARG BINARY_NAME=mcauth-linux-amd64
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-w -s" \
-o /app/${BINARY_NAME} \
./cmd/server
# 运行阶段
FROM alpine:latest
# 安装必要的运行时依赖
RUN apk add --no-cache ca-certificates tzdata
RUN apk add --no-cache ca-certificates tzdata wget
# 创建非 root 用户
RUN addgroup -g 1000 appuser && \
@@ -36,9 +11,9 @@ RUN addgroup -g 1000 appuser && \
# 设置工作目录
WORKDIR /app
# 从构建阶段复制二进制文件
# 复制已经编译好的二进制文件
ARG BINARY_NAME=mcauth-linux-amd64
COPY --from=builder /app/${BINARY_NAME} /app/server
COPY ${BINARY_NAME} /app/server
# 复制配置文件(如果需要)
COPY configs/ /app/configs/