commit 429e2c2a4290bf9087c31fdf50cd435d43abcbc0 Author: shutkin.k Date: Sat Nov 22 19:49:46 2025 +0300 first commit diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..eae94d7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +# Ignore everything +* +!/main.go diff --git a/distroless/Dockerfile b/distroless/Dockerfile new file mode 100644 index 0000000..6d30d6f --- /dev/null +++ b/distroless/Dockerfile @@ -0,0 +1,13 @@ +# Build stage +FROM golang:1.21-alpine AS builder +WORKDIR /app +COPY main.go . +ENV GOOS=linux +ENV GOARCH=amd64 +RUN go build -ldflags='-w -s -extldflags "-static"' -o myapp main.go + +# Final stage with distroless +FROM gcr.io/distroless/static-debian12 +COPY --from=builder /app/myapp / +USER 65532 +CMD ["/myapp"] diff --git a/main.go b/main.go new file mode 100644 index 0000000..de997c7 --- /dev/null +++ b/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "io" + "net/http" + "os" +) + +func main() { + resp, err := http.Get("https://example.com") + if err != nil { + fmt.Printf("Error: %v\n", err) + os.Exit(1) + } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + fmt.Printf("Error reading response: %v\n", err) + os.Exit(1) + } + + fmt.Printf("Status: %s\n", resp.Status) + fmt.Printf("Response length: %d bytes\n", len(body)) +} diff --git a/scratch/Dockerfile b/scratch/Dockerfile new file mode 100644 index 0000000..9c0d953 --- /dev/null +++ b/scratch/Dockerfile @@ -0,0 +1,13 @@ +# Build stage +FROM golang:1.21-alpine AS builder +WORKDIR /app +COPY main.go . +ENV GOOS=linux +ENV GOARCH=amd64 +RUN go build -ldflags='-w -s -extldflags "-static"' -o myapp main.go + +# Final stage with scratch +FROM scratch +COPY --from=builder /app/myapp / +USER 65532 +CMD ["/myapp"]