【调整】优化Dockerfile,使用构建阶段构建应用程序,简化运行时依赖安装

This commit is contained in:
YANGJINZE
2026-01-14 17:45:54 +08:00
parent a0879bfb1c
commit 280571e42a

View File

@@ -1,10 +1,32 @@
# Build stage
FROM golang:1.24-alpine AS builder
WORKDIR /build
# Install build dependencies
RUN apk add --no-cache git make gcc musl-dev
# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build the application
RUN CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -o allinssl ./cmd/main.go
# Final stage
FROM frolvlad/alpine-glibc FROM frolvlad/alpine-glibc
WORKDIR /www/allinssl/ WORKDIR /www/allinssl/
RUN apk add --no-cache curl tzdata\ # Install runtime dependencies
&& curl https://node1.allinssl.com/bin/allinssl-$(uname -s)-$(uname -m).tar.gz | tar -xz -C /www/allinssl/ \ RUN apk add --no-cache tzdata
&& apk del curl
# Copy binary from builder
COPY --from=builder /build/allinssl /www/allinssl/allinssl
ENV TZ=Asia/Shanghai ENV TZ=Asia/Shanghai
RUN cat > /entrypoint.sh <<'EOF' RUN cat > /entrypoint.sh <<'EOF'
#!/bin/sh #!/bin/sh