fix(docker): 优化 Dockerfile.base 减少构建阶段复杂度

- 合并构建和运行环境,移除多阶段构建
- 统一设置环境变量,优化时区配置为 Asia/Shanghai
- 替换 Alpine 镜像源为阿里云镜像提升下载速度
- 在运行环境安装所有必需依赖(含 git、curl、tzdata)
- 保证 Go 依赖下载并校验完整性,提升构建可靠性
- 删除冗余注释和步骤,简化 Dockerfile 结构
This commit is contained in:
danial
2025-11-09 15:43:14 +08:00
parent c605f763c5
commit 006853af10

View File

@@ -1,47 +1,28 @@
# Base Image for kami-gateway applications
# Contains Go 1.25 build environment and Alpine runtime
FROM golang:1.25-alpine AS builder
FROM golang:1.25-alpine
# Set environment variables for building
ENV GO111MODULE=on \
# Set environment variables
ENV TZ=Asia/Shanghai \
GO111MODULE=on \
GOPROXY=https://goproxy.cn,direct \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
# Install build dependencies
RUN apk add --no-cache \
git \
ca-certificates \
tzdata
# Create application directory
WORKDIR /build
# Copy Go modules files for caching
COPY go.mod go.sum* ./
# Download dependencies (this layer will be cached unless go.mod changes)
RUN go mod download && go mod verify
# Create runtime stage
FROM alpine:latest
# Set environment variables
ENV TZ=Asia/Shanghai
# Set up Alpine repositories (use China mirror for faster downloads)
RUN echo "https://mirrors.aliyun.com/alpine/v3.22/main/" > /etc/apk/repositories && \
echo "https://mirrors.aliyun.com/alpine/v3.22/community/" >> /etc/apk/repositories
# Install runtime dependencies
# Install all dependencies
RUN apk update && \
apk upgrade && \
apk add --no-cache \
tzdata \
curl \
ca-certificates && \
ca-certificates \
git && \
# Set timezone
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone && \
@@ -74,7 +55,7 @@ WORKDIR /app
COPY --chown=appuser:appuser go.mod go.sum* ./
# Pre-download Go dependencies for faster builds
RUN go mod download
RUN go mod download && go mod verify
# Label the image
LABEL maintainer="kami-gateway-team" \