Compare commits

...

1 Commits

Author SHA1 Message Date
15aaba77ef rc2
All checks were successful
release-tag / release-image (push) Successful in 1m46s
2026-01-12 14:29:46 +01:00
3 changed files with 66 additions and 39 deletions

View File

@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1 # syntax=docker/dockerfile:1
# Build Go binary # Build Go binary
FROM golang:1.25-alpine AS builder FROM golang:1.22-alpine AS builder
WORKDIR /src WORKDIR /src
RUN apk add --no-cache ca-certificates tzdata RUN apk add --no-cache ca-certificates tzdata
COPY go.mod ./ COPY go.mod ./
@@ -13,7 +13,7 @@ RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/ntfywui ./cmd/ntfy
FROM binwiederhier/ntfy:latest AS ntfy FROM binwiederhier/ntfy:latest AS ntfy
# Runtime # Runtime
FROM alpine:3.23 FROM alpine:3.20
RUN apk add --no-cache ca-certificates tzdata \ RUN apk add --no-cache ca-certificates tzdata \
&& addgroup -S ntfywui && adduser -S -G ntfywui -h /home/ntfywui ntfywui && addgroup -S ntfywui && adduser -S -G ntfywui -h /home/ntfywui ntfywui
WORKDIR /app WORKDIR /app

View File

@@ -5,6 +5,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"os"
"os/exec" "os/exec"
"regexp" "regexp"
"strings" "strings"
@@ -45,16 +46,25 @@ func (c *Client) Run(ctx context.Context, args []string, env map[string]string,
if c.Bin == "" { if c.Bin == "" {
return "", "", 0, errors.New("ntfy binary not set") return "", "", 0, errors.New("ntfy binary not set")
} }
// Many (newer) ntfy versions support `--config/-c` for server-side commands
// (serve/user/access/token). Some older builds do not. We try with --config
// first (if configured) and fall back to running without it if the binary
// rejects the flag.
withConfig := args
if c.Config != "" { if c.Config != "" {
args = append([]string{"--config", c.Config}, args...) withConfig = append([]string{"--config", c.Config}, args...)
} }
tctx := ctx tctx := ctx
var cancel context.CancelFunc var cancel context.CancelFunc
if c.Timeout > 0 { if c.Timeout > 0 {
tctx, cancel = context.WithTimeout(ctx, c.Timeout) tctx, cancel = context.WithTimeout(ctx, c.Timeout)
defer cancel() defer cancel()
} }
cmd := exec.CommandContext(tctx, c.Bin, args...) // helper to execute once
runOnce := func(a []string) (string, string, int, error) {
cmd := exec.CommandContext(tctx, c.Bin, a...)
if stdin != "" { if stdin != "" {
cmd.Stdin = strings.NewReader(stdin) cmd.Stdin = strings.NewReader(stdin)
} }
@@ -62,7 +72,8 @@ func (c *Client) Run(ctx context.Context, args []string, env map[string]string,
cmd.Stdout = &outb cmd.Stdout = &outb
cmd.Stderr = &errb cmd.Stderr = &errb
if env != nil { if env != nil {
// inherit env automatically // inherit env + add/override provided vars
cmd.Env = append([]string{}, os.Environ()...)
for k, v := range env { for k, v := range env {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, v)) cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, v))
} }
@@ -80,6 +91,22 @@ func (c *Client) Run(ctx context.Context, args []string, env map[string]string,
} }
} }
return outb.String(), errb.String(), exit, nil return outb.String(), errb.String(), exit, nil
}
// first attempt (maybe with --config)
out, errOut, exit, err := runOnce(withConfig)
if c.Config == "" {
return out, errOut, exit, err
}
// fallback for older ntfy binaries that don't know --config
if exit != 0 {
errTrim := strings.TrimSpace(errOut)
if strings.Contains(errTrim, "flag provided but not defined: -config") ||
strings.Contains(errTrim, "unknown flag") && strings.Contains(errTrim, "config") {
return runOnce(args)
}
}
return out, errOut, exit, err
} }
func (c *Client) ListUsers(ctx context.Context) ([]User, error) { func (c *Client) ListUsers(ctx context.Context) ([]User, error) {