Created
March 26, 2024 22:22
-
-
Save nenodias/cc701e6dfb91b9318b97ca7396fd3eda to your computer and use it in GitHub Desktop.
Golang DockerFile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment