Skip to content

Commit ca8b40e

Browse files
author
chendelin1982
committed
optimize build docker
1 parent d6f1574 commit ca8b40e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

.github/workflows/docker-build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
type=raw,value=latest,enable={{is_default_branch}}
5353
5454
- name: Build and push Docker image
55+
id: build
5556
uses: docker/build-push-action@v5
5657
with:
5758
context: .

docker/Dockerfile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
FROM golang:1.24-alpine AS builder
44

55
# Set GOPROXY for faster downloads
6-
ENV GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct
6+
ENV GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct \
7+
CGO_ENABLED=0 \
8+
GOOS=linux \
9+
GOARCH=amd64
710

811
WORKDIR /build
912

@@ -17,10 +20,12 @@ RUN go mod download
1720
# Copy source code
1821
COPY core/ ./
1922

20-
# Build static binary
21-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
22-
-a -installsuffix cgo \
23-
-ldflags '-extldflags "-static" -s -w' \
23+
# Build static binary with cache optimization
24+
RUN --mount=type=cache,target=/root/.cache/go-build \
25+
go build \
26+
-trimpath \
27+
-ldflags='-s -w -extldflags "-static"' \
28+
-p=$(nproc) \
2429
-o /apprun ./cmd/server/main.go
2530

2631
# Stage 2: Production - Minimal runtime image

0 commit comments

Comments
 (0)