Skip to content

Commit

Permalink
Fix Dockerfile issues
Browse files Browse the repository at this point in the history
* Add ldflags to embed version at build time
* Revert to using scratch image instead of debian base to reduce size and build time
  • Loading branch information
jhalter committed Aug 10, 2024
1 parent 9810dfc commit aa8441b
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit aa8441b

Please sign in to comment.