-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
44 lines (36 loc) · 1.29 KB
/
Dockerfile
File metadata and controls
44 lines (36 loc) · 1.29 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
# --------------------------------------------------
# Stage 1: dlv (cached)
# --------------------------------------------------
ARG GO_VERSION=1.26
FROM golang:${GO_VERSION}-alpine AS dlv
RUN apk add --no-cache ca-certificates
# Build Delve as a static binary
ENV CGO_ENABLED=0
RUN go install github.com/go-delve/delve/cmd/dlv@latest
# --------------------------------------------------
# Stage 2: build app
# --------------------------------------------------
FROM golang:${GO_VERSION}-alpine AS build
WORKDIR /src
RUN apk add --no-cache ca-certificates
# Copy dlv from cache layer
COPY --from=dlv /go/bin/dlv /usr/local/bin/dlv
# Cache go modules
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build binary with debug flags
RUN CGO_ENABLED=0 GOOS=linux go build -gcflags "all=-N -l" -o /out/bot .
# --------------------------------------------------
# Stage 3: final image
# --------------------------------------------------
FROM gcr.io/distroless/static:nonroot
WORKDIR /app
COPY --from=build /out/bot /app/bot
COPY --from=build /usr/local/bin/dlv /app/dlv
COPY emoji /app/emoji
USER nonroot:nonroot
EXPOSE 4000
# Delve as default CMD for debugging
CMD ["/app/dlv", "--listen=:4000", "--headless=true", "--log=true", "--accept-multiclient", "--api-version=2", "exec", "/app/bot"]