-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
26 lines (19 loc) · 722 Bytes
/
Dockerfile
File metadata and controls
26 lines (19 loc) · 722 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
# Dockerfile
FROM golang:1.26.1 AS builder
WORKDIR /app
# Define build arguments for version, commit, and date.
ARG VERSION=$(git describe --tags --abbrev=0 || echo "0.0.0")
ARG COMMIT=$(git rev-parse --short HEAD || echo "none")
ARG DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
# Copy dependency files and download modules.
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code and compile the gcx binary using ldflags.
COPY . .
RUN CGO_ENABLED=0 go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.buildDate=${DATE}" -v -o ./bin/gcx ./cmd/gcx
FROM golang:1.26.1
ENV GOTOOLCHAIN=auto
ENV GOROOT=/usr/local/go
WORKDIR /app
COPY --from=builder /app/bin/gcx /usr/bin/
CMD ["gcx"]