first commit

This commit is contained in:
shutkin.k 2025-11-22 19:49:46 +03:00
commit 429e2c2a42
4 changed files with 55 additions and 0 deletions

3
.dockerignore Normal file
View File

@ -0,0 +1,3 @@
# Ignore everything
*
!/main.go

13
distroless/Dockerfile Normal file
View File

@ -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"]

26
main.go Normal file
View File

@ -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))
}

13
scratch/Dockerfile Normal file
View File

@ -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"]