Skip to content

Instantly share code, notes, and snippets.

@nenodias
Created March 26, 2024 22:22
Show Gist options
  • Save nenodias/cc701e6dfb91b9318b97ca7396fd3eda to your computer and use it in GitHub Desktop.
Save nenodias/cc701e6dfb91b9318b97ca7396fd3eda to your computer and use it in GitHub Desktop.

Revisions

  1. nenodias created this gist Mar 26, 2024.
    40 changes: 40 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    FROM debian:12-slim as builder

    RUN apt update && apt install -y --no-install-recommends \
    ca-certificates \
    git \
    wget \
    tar \
    gcc \
    g++ \
    make \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

    RUN wget https://go.dev/dl/go1.22.1.linux-amd64.tar.gz && tar -C /usr/local -xzf go1.22.1.linux-amd64.tar.gz && rm go1.22.1.linux-amd64.tar.gz
    ENV PATH=$PATH:/usr/local/go/bin

    WORKDIR /app

    RUN addgroup app
    RUN useradd -ms /bin/bash app -g app -d /app

    COPY ./src/ .

    RUN go mod tidy
    RUN go test ./...
    RUN go vet ./...
    RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o main .
    RUN chmod +x main

    FROM cgr.dev/chainguard/glibc-dynamic

    ENV LANG en_US.UTF-8
    ENV LANGUAGE en_US:en
    ENV LC_ALL en_US.UTF-8

    USER nonroot

    COPY --from=builder --chown=nonroot:nonroot /app/main /main

    CMD ["./main" ]