diff --git a/.build.yml b/.build.yml index 698ed39..1e22572 100644 --- a/.build.yml +++ b/.build.yml @@ -11,6 +11,7 @@ sources: tasks: - test: | cd ntfy-alertmanager + go generate ./... go test -v ./... - lint: | cd ntfy-alertmanager diff --git a/.gitignore b/.gitignore index 6948ee2..2b0be1e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /ntfy-alertmanager +version.txt diff --git a/docker/Dockerfile-dev b/docker/Dockerfile-dev index 7040dd7..fe5031e 100644 --- a/docker/Dockerfile-dev +++ b/docker/Dockerfile-dev @@ -2,7 +2,8 @@ FROM golang:alpine as build WORKDIR /app COPY . . -RUN go build -o /app/ntfy-alertmanager +RUN apk add --no-cache git +RUN go generate ./... && go build -o /app/ntfy-alertmanager FROM alpine:latest diff --git a/main.go b/main.go index 7eab4a9..3c4de2c 100644 --- a/main.go +++ b/main.go @@ -4,11 +4,13 @@ package main import ( "crypto/sha512" "crypto/subtle" + _ "embed" "encoding/base64" "encoding/json" "flag" "fmt" "net/http" + "os" "strings" "time" @@ -17,6 +19,10 @@ import ( "golang.org/x/text/language" ) +//go:generate sh -c "git describe --long > version.txt" +//go:embed version.txt +var version string + type receiver struct { cfg *config logger *log.Logger @@ -205,8 +211,15 @@ func (rcv *receiver) basicAuthMiddleware(handler http.HandlerFunc) http.HandlerF func main() { var configPath string flag.StringVar(&configPath, "config", "/etc/ntfy-alertmanager/config", "config file path") + var showVersion bool + flag.BoolVar(&showVersion, "version", false, "Show version and exit") flag.Parse() + if showVersion { + fmt.Println(version) + os.Exit(0) + } + logger := log.NewDefaultLogger() cfg, err := readConfig(configPath) @@ -220,7 +233,7 @@ func main() { receiver := &receiver{cfg: cfg, logger: logger} - logger.Infof("Listening on %s", cfg.HTTPAddress) + logger.Infof("Listening on %s, ntfy-alertmanager %s", cfg.HTTPAddress, version) if cfg.User != "" && cfg.Password != "" { logger.Info("Enabling HTTP Basic Authentication")