-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
49 lines (37 loc) · 1.27 KB
/
Dockerfile
File metadata and controls
49 lines (37 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# ============================================
# Build Stage
# ============================================
FROM golang:1.25.4 AS builder
WORKDIR /app
# 依存関係のキャッシュを最適化
COPY go.mod go.sum ./
RUN go mod download
# ソースコードをコピー
COPY . .
# generate が必要な場合は実行
# RUN go generate ./...
# バイナリをビルド
# CGO_ENABLED=0: 静的リンクでビルド(distrolessイメージで実行可能)
# -ldflags="-s -w": デバッグ情報を削除してバイナリサイズを削減
RUN CGO_ENABLED=0 GOOS=linux go build \
-trimpath \
-ldflags="-s -w" \
-o gobot \
.
# ============================================
# Runtime Stage (Distroless)
# ============================================
FROM gcr.io/distroless/static-debian12:nonroot AS runtime
WORKDIR /app
# ビルドステージからバイナリをコピー
COPY --from=builder /app/gobot .
# ランタイムに必要なファイルをコピー
COPY --from=builder /app/lang ./lang
COPY --from=builder /app/locales ./locales
# 非rootユーザーで実行(セキュリティベストプラクティス)
USER nonroot:nonroot
# pprofポートを公開
EXPOSE 6060
# エントリーポイント
ENTRYPOINT ["./gobot"]
CMD ["bot", "--pprof", "--debug"]