-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
37 lines (25 loc) · 721 Bytes
/
Dockerfile
File metadata and controls
37 lines (25 loc) · 721 Bytes
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
FROM golang:1.24-alpine AS builder
WORKDIR /build
# Install git for version detection
RUN apk add --no-cache git
# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build the binary
ARG VERSION=dev
ARG BUILDTIME=unknown
RUN CGO_ENABLED=0 go build -trimpath \
-ldflags "-s -w -X github.com/samzong/gmc/cmd.Version=${VERSION} -X github.com/samzong/gmc/cmd.BuildTime=${BUILDTIME}" \
-o gmc .
FROM alpine:3.19
RUN apk --no-cache add ca-certificates git
WORKDIR /root
# Copy the binary from builder
COPY --from=builder /build/gmc /usr/local/bin/gmc
# Make sure gmc is executable
RUN chmod +x /usr/local/bin/gmc
# Set the entrypoint
ENTRYPOINT ["gmc"]
CMD ["--help"]