From aa8441bcb171ab0af3d9874ddb3c5e914994087e Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Fri, 9 Aug 2024 18:05:04 -0700 Subject: [PATCH] Fix Dockerfile issues * Add ldflags to embed version at build time * Revert to using scratch image instead of debian base to reduce size and build time --- Dockerfile | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index d3f5848..26430db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,24 +3,10 @@ FROM golang:1.22 AS builder WORKDIR /app COPY . . -RUN CGO_ENABLED=0 go build -o /app/mobius-hotline-bot . && chmod a+x /app/mobius-hotline-bot +RUN CGO_ENABLED=0 go build -ldflags "-X main.version=$(git describe --exact-match --tags)" -o /app/mobius-hotline-bot . && chmod a+x /app/mobius-hotline-bot -FROM debian:stable-slim - -# Change these as you see fit. This makes bind mounting easier so you don't have to edit bind mounted config files as root. -ARG USERNAME=hl-bot -ARG UID=1001 -ARG GUID=1001 - -RUN apt-get update \ - && apt-get install -y --no-install-recommends ca-certificates - -RUN update-ca-certificates +FROM scratch COPY --from=builder /app/mobius-hotline-bot /app/mobius-hotline-bot -RUN useradd -d /app -u ${UID} ${USERNAME} -RUN chown -R ${USERNAME}:${USERNAME} /app - -USER ${USERNAME} ENTRYPOINT ["/app/mobius-hotline-bot"]