forked from ziwon/gpu-scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
78 lines (62 loc) · 2.12 KB
/
Dockerfile
File metadata and controls
78 lines (62 loc) · 2.12 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# syntax=docker/dockerfile:1.7
# Build arguments
ARG GO_VERSION=1.24
ARG ALPINE_VERSION=3.21
# Build stage
FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS builder
# Install build dependencies
RUN apk add --no-cache \
ca-certificates \
git \
make
# Set working directory
WORKDIR /workspace
# Build arguments for component path and version info
ARG CMD_PATH=cmd/scheduler
ARG VERSION=dev
ARG COMMIT=unknown
ARG BUILD_DATE=unknown
# Copy go mod files first for better caching
COPY go.mod go.sum ./
# Download dependencies (cached if go.mod/go.sum unchanged)
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download && \
go mod verify
# Copy source code
COPY . .
# Build the binary with optimizations
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
go build \
-a \
-installsuffix cgo \
-ldflags="-w -s \
-X main.version=${VERSION} \
-X main.commit=${COMMIT} \
-X main.date=${BUILD_DATE} \
-extldflags '-static'" \
-trimpath \
-o /out/gpu-component \
"./${CMD_PATH}"
# Verify the binary
RUN /out/gpu-component --version || /out/gpu-component --help || echo "Binary built successfully"
# Runtime stage - distroless for minimal attack surface
FROM gcr.io/distroless/static-debian12:nonroot
# Metadata labels following OCI spec
LABEL org.opencontainers.image.title="GPU Scheduler Component" \
org.opencontainers.image.description="Kubernetes GPU scheduler component" \
org.opencontainers.image.url="https://github.com/restack/gpu-scheduler" \
org.opencontainers.image.source="https://github.com/restack/gpu-scheduler" \
org.opencontainers.image.vendor="restack" \
org.opencontainers.image.licenses="MIT"
# Copy binary from builder
COPY --from=builder --chown=65532:65532 /out/gpu-component /usr/local/bin/gpu-component
# Use non-root user (already default in distroless:nonroot, but explicit is better)
USER 65532:65532
# Set working directory
WORKDIR /
# Entrypoint
ENTRYPOINT ["/usr/local/bin/gpu-component"]