first commit
This commit is contained in:
commit
429e2c2a42
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Ignore everything
|
||||||
|
*
|
||||||
|
!/main.go
|
||||||
|
|
@ -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"]
|
||||||
|
|
@ -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))
|
||||||
|
}
|
||||||
|
|
@ -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"]
|
||||||
Loading…
Reference in New Issue