From f66ce030cf2179089bcaab4ecb85cba74fa735c4 Mon Sep 17 00:00:00 2001 From: Jarno Rankinen Date: Tue, 26 Mar 2024 21:57:15 +0200 Subject: [PATCH] Small tweaks to configuration flow, Dockerfile for running as a container --- Dockerfile | 13 +++++++++++++ cmd/hydroxide-push/Dockerfile | 8 -------- cmd/hydroxide-push/main.go | 18 ++++++++++++++---- ntfy/ntfy.go | 4 +++- 4 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 Dockerfile delete mode 100644 cmd/hydroxide-push/Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e347385 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM golang:1.22 as builder + +WORKDIR /src +COPY . /src +RUN CGO_ENABLED=0 go build -o /hydroxide-push ./cmd/hydroxide-push/ + +FROM alpine:latest +VOLUME /data +COPY --from=builder /hydroxide-push / +ENV HOME=/data +WORKDIR /data +ENTRYPOINT ["/hydroxide-push"] +CMD ["notify"] \ No newline at end of file diff --git a/cmd/hydroxide-push/Dockerfile b/cmd/hydroxide-push/Dockerfile deleted file mode 100644 index 0183c87..0000000 --- a/cmd/hydroxide-push/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM scratch - -COPY hydroxide-push / -ENV HOME=/data -ENV HYDROXIDE_BRIDGE_PASS="supersecretpassword" -WORKDIR /data -ENTRYPOINT ["/hydroxide-push"] -CMD ["notify"] \ No newline at end of file diff --git a/cmd/hydroxide-push/main.go b/cmd/hydroxide-push/main.go index f147604..aabca5b 100644 --- a/cmd/hydroxide-push/main.go +++ b/cmd/hydroxide-push/main.go @@ -229,20 +229,30 @@ func main() { } case "setup-ntfy": + err = cfg.Read() + if err != nil { + fmt.Println(err) + } + var new string + if cfg.URL != "" && cfg.Topic != "" { + fmt.Printf("Current push endpoint: %s\n", cfg.String()) + new = "new " + } scanner := bufio.NewScanner(os.Stdin) - fmt.Printf("Input push server URL (e.g. 'http://ntfy.sh') : ") + fmt.Printf("Input %spush server URL (e.g. 'http://ntfy.sh') : ", new) scanner.Scan() cfg.URL = scanner.Text() scanner = bufio.NewScanner(os.Stdin) - fmt.Printf("Input push topic (e.g. my-proton-notifications)\nLeave blank to generate a random one: ") + fmt.Printf("Input push topic (e.g. my-proton-notifications): ") scanner.Scan() cfg.Topic = scanner.Text() fmt.Printf("Using URL %s\n", cfg.String()) err = cfg.Save() if err != nil { - log.Fatal(err) + fmt.Println(err) + os.Exit(1) } - log.Println("Notification configuration saved") + fmt.Println("Notification configuration saved") case "notify": authManager := auth.NewManager(newClient) eventsManager := events.NewManager() diff --git a/ntfy/ntfy.go b/ntfy/ntfy.go index 8388e1c..01e3432 100644 --- a/ntfy/ntfy.go +++ b/ntfy/ntfy.go @@ -87,7 +87,9 @@ func Login(cfg *NtfyConfig, be backend.Backend) { log.Println("login first using " + executable + " auth ") log.Fatalln("then setup ntfy using " + executable + "setup-ntfy") } - cfg.BridgePw = os.Getenv("HYDROXIDE_BRIDGE_PASSWORD") + if cfg.BridgePw == "" { + cfg.BridgePw = os.Getenv("HYDROXIDE_BRIDGE_PASSWORD") + } if cfg.BridgePw == "" { scanner := bufio.NewScanner(os.Stdin) fmt.Printf("Bridge password: ")