-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
58 lines (43 loc) · 1.44 KB
/
Copy pathDockerfile
File metadata and controls
58 lines (43 loc) · 1.44 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
# Build the kubeftpd binary
FROM golang:1.26.5-alpine AS builder
ARG TARGETOS
ARG TARGETARCH
ARG VERSION=v0.6.10
ARG COMMIT=unknown
ARG DATE=unknown
# Install git and ca-certificates for Go modules and TLS
RUN apk add --no-cache git ca-certificates
WORKDIR /workspace
# Copy go.mod and go.sum first for better caching
COPY go.mod go.mod
COPY go.sum go.sum
# Download dependencies
RUN go mod download
# Copy the source code
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/ internal/
COPY hack/ hack/
# Build the binary with optimizations and version information
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build \
-ldflags="-w -s -X 'main.version=${VERSION}' -X 'main.commit=${COMMIT}' -X 'main.date=${DATE}'" \
-a -installsuffix cgo \
-o kubeftpd \
cmd/main.go
# Use distroless as minimal base image to package the kubeftpd binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
# Copy the binary from the builder stage
COPY --from=builder /workspace/kubeftpd .
# Copy ca-certificates for TLS connections to backends
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Use nonroot user for security
USER 65532:65532
# Expose FTP control port
EXPOSE 21
# Expose passive port range for FTP data connections
EXPOSE 30000-30100
# Expose HTTP port (metrics, health checks, status)
EXPOSE 8080
ENTRYPOINT ["/kubeftpd"]