-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
45 lines (33 loc) · 1.2 KB
/
Dockerfile
File metadata and controls
45 lines (33 loc) · 1.2 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
# Multi-stage Dockerfile to produce a Linux-native pingcli binary
# Builder stage: compile the Go binary for the target platform
FROM golang:1.25.1-alpine AS builder
WORKDIR /src
# Install build deps
RUN apk add --no-cache git build-base
# Leverage Docker layer caching for dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the source
COPY . .
# Build for the target platform provided by BuildKit (or default to linux/amd64)
ARG TARGETOS=linux
ARG TARGETARCH=amd64
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
go build -ldflags="-s -w" -trimpath -o /out/pingcli-terraformer .
# Runtime stage: minimal image with CA certificates
FROM alpine:3.19
RUN apk add --no-cache ca-certificates
# Create non-root user for security
RUN addgroup -g 1000 terraformer && \
adduser -D -u 1000 -G terraformer terraformer
# Copy the compiled binary from the builder
COPY --from=builder /out/pingcli-terraformer /usr/local/bin/pingcli-terraformer
# Create output directory with proper permissions
RUN mkdir /output && chown terraformer:terraformer /output
# Switch to non-root user
USER terraformer
WORKDIR /output
# Set the entry point
ENTRYPOINT ["pingcli-terraformer"]
# Allow subcommands
CMD []