messagebird / sachet

SMS alerts for Prometheus' Alertmanager

Home Page:https://www.messagebird.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dockerfile is broken

idsvandermolen opened this issue · comments

Trying to build an image returns this error:

go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/messagebird/sachet/cmd/...: exec: "git": executable file not found in $PATH

Basically the git package isn't installed, but used as name of the virtual package with --virtual git.
This patch fixes it:

diff --git a/Dockerfile b/Dockerfile
index 07363a4..8229163 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,9 +1,9 @@
 FROM golang:alpine

-RUN apk add --no-cache --virtual git openssl ca-certificates && \
+RUN apk add --no-cache --virtual build git openssl ca-certificates && \
     go get github.com/messagebird/sachet/cmd/... && \
     rm -rf src pkg && \
-    apk del git
+    apk del build

 COPY examples/config.yaml /etc/sachet/config.yaml

However, this still builds a 374MB image, which contains the golang environment. It's better to use this newer Dockerfile:

FROM golang:alpine AS build

RUN apk update && \
    apk add --no-cache git openssl ca-certificates && \
    go get github.com/messagebird/sachet/cmd/...

FROM alpine
COPY --from=build /go/bin/sachet /usr/local/bin
COPY examples/config.yaml /etc/sachet/config.yaml
RUN apk update && \
    apk add --no-cache ca-certificates

EXPOSE 9876
ENTRYPOINT ["sachet"]
CMD ["-config", "/etc/sachet/config.yaml"]

which builds a small 21.3MB image (assuming ca-certificates package is needed).

btw Sachet should not run as root, so it's best to also change COPY command and add USER:

COPY --chown=nobody examples/config.yaml /etc/sachet/config.yaml
USER nobody