chore: Refactor Dockerfile and build workflow for improved efficiency
- 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:
@@ -67,8 +67,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: true
|
push: true
|
||||||
build-args: |
|
|
||||||
BINARY_NAME=mcauth-linux-amd64
|
|
||||||
tags: |
|
tags: |
|
||||||
code.littlelan.cn/carrotskin/mcauth:latest
|
code.littlelan.cn/carrotskin/mcauth:latest
|
||||||
code.littlelan.cn/carrotskin/mcauth:${{ github.sha }}
|
code.littlelan.cn/carrotskin/mcauth:${{ github.sha }}
|
||||||
|
|||||||
31
Dockerfile
31
Dockerfile
@@ -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
|
FROM alpine:latest
|
||||||
|
|
||||||
# 安装必要的运行时依赖
|
# 安装必要的运行时依赖
|
||||||
RUN apk add --no-cache ca-certificates tzdata
|
RUN apk add --no-cache ca-certificates tzdata wget
|
||||||
|
|
||||||
# 创建非 root 用户
|
# 创建非 root 用户
|
||||||
RUN addgroup -g 1000 appuser && \
|
RUN addgroup -g 1000 appuser && \
|
||||||
@@ -36,9 +11,9 @@ RUN addgroup -g 1000 appuser && \
|
|||||||
# 设置工作目录
|
# 设置工作目录
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# 从构建阶段复制二进制文件
|
# 复制已经编译好的二进制文件
|
||||||
ARG BINARY_NAME=mcauth-linux-amd64
|
ARG BINARY_NAME=mcauth-linux-amd64
|
||||||
COPY --from=builder /app/${BINARY_NAME} /app/server
|
COPY ${BINARY_NAME} /app/server
|
||||||
|
|
||||||
# 复制配置文件(如果需要)
|
# 复制配置文件(如果需要)
|
||||||
COPY configs/ /app/configs/
|
COPY configs/ /app/configs/
|
||||||
|
|||||||
Reference in New Issue
Block a user