feat: daemon entrypoint, YAML config and Dockerfile
- Add config loader with defaults and strict unknown-field rejection - Add cmd/parsimony wiring store, router, relay and LMTP server - Handle SIGINT and SIGTERM for graceful shutdown - Add Dockerfile and example config
This commit is contained in:
parent
87744a0d97
commit
28d22d51de
6 changed files with 114 additions and 0 deletions
11
Dockerfile
Normal file
11
Dockerfile
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
FROM golang:1.27 AS build
|
||||
WORKDIR /src
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
RUN CGO_ENABLED=0 go build -o /parsimony ./cmd/parsimony
|
||||
|
||||
FROM gcr.io/distroless/static-debian12
|
||||
COPY --from=build /parsimony /parsimony
|
||||
VOLUME /data
|
||||
ENTRYPOINT ["/parsimony", "-config", "/data/parsimony.yaml"]
|
||||
1
go.mod
1
go.mod
|
|
@ -5,6 +5,7 @@ go 1.27.1
|
|||
require (
|
||||
github.com/emersion/go-message v0.18.2
|
||||
github.com/emersion/go-smtp v0.25.1
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
modernc.org/sqlite v1.62.0
|
||||
)
|
||||
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -57,6 +57,10 @@ golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
|||
golang.org/x/tools v0.52.0 h1:ryxg4U63oaUYk7uOLTF37n43f4qgtGvqV4Ioit1BaEs=
|
||||
golang.org/x/tools v0.52.0/go.mod h1:ItcP5UNaVGG+Yc4eIYmaFLNJ4soEopkx5Y2d4lcEurs=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
modernc.org/cc/v4 v4.30.6-0.20261101114202-1b9d1a076f6b h1:WE5SLOURcNd8s6uPR/n4WV4weQxxYKi5OpEZkfNVvdE=
|
||||
modernc.org/cc/v4 v4.30.6-0.20261101114202-1b9d1a076f6b/go.mod h1:OnovgIhbbMXMu1aISnJ0wvVD1KnW+cAUJkIrAWh+kVI=
|
||||
modernc.org/ccgo/v4 v4.38.1 h1:wdxJVBuFT8JufZnnQyS6Bbz3NOWhViD0xJOGR96Bpd4=
|
||||
|
|
|
|||
43
internal/config/config.go
Normal file
43
internal/config/config.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// Package config loads the YAML configuration.
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// Config is the full daemon configuration.
|
||||
type Config struct {
|
||||
DB string `yaml:"db"` // SQLite path
|
||||
BaseURL string `yaml:"base_url"` // public web URL, enables one-click unsubscribe
|
||||
LMTP struct {
|
||||
Network string `yaml:"network"` // tcp or unix
|
||||
Addr string `yaml:"addr"`
|
||||
} `yaml:"lmtp"`
|
||||
Relay struct {
|
||||
Addr string `yaml:"addr"` // host:port of the outgoing SMTP relay
|
||||
} `yaml:"relay"`
|
||||
}
|
||||
|
||||
// Load reads path and applies defaults.
|
||||
func Load(path string) (Config, error) {
|
||||
var c Config
|
||||
c.DB = "parsimony.db"
|
||||
c.LMTP.Network = "tcp"
|
||||
c.LMTP.Addr = "127.0.0.1:2424"
|
||||
c.Relay.Addr = "127.0.0.1:25"
|
||||
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
dec := yaml.NewDecoder(bytes.NewReader(b))
|
||||
dec.KnownFields(true)
|
||||
if err := dec.Decode(&c); err != nil {
|
||||
return c, fmt.Errorf("parse %s: %w", path, err)
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
48
internal/config/config_test.go
Normal file
48
internal/config/config_test.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func write(t *testing.T, content string) string {
|
||||
t.Helper()
|
||||
p := filepath.Join(t.TempDir(), "c.yaml")
|
||||
if err := os.WriteFile(p, []byte(content), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func TestLoadDefaults(t *testing.T) {
|
||||
c, err := Load(write(t, "{}\n"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c.DB != "parsimony.db" || c.LMTP.Network != "tcp" || c.LMTP.Addr != "127.0.0.1:2424" || c.Relay.Addr != "127.0.0.1:25" {
|
||||
t.Fatalf("defaults: %+v", c)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadValues(t *testing.T) {
|
||||
c, err := Load(write(t, "db: /var/lib/p.db\nbase_url: https://l.example.org\nlmtp:\n network: unix\n addr: /run/p.sock\nrelay:\n addr: mx:587\n"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if c.DB != "/var/lib/p.db" || c.BaseURL != "https://l.example.org" || c.LMTP.Network != "unix" || c.LMTP.Addr != "/run/p.sock" || c.Relay.Addr != "mx:587" {
|
||||
t.Fatalf("values: %+v", c)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadMissingFile(t *testing.T) {
|
||||
if _, err := Load("/nonexistent.yaml"); err == nil {
|
||||
t.Fatal("want error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadUnknownField(t *testing.T) {
|
||||
if _, err := Load(write(t, "bogus: 1\n")); err == nil {
|
||||
t.Fatal("unknown fields must be rejected")
|
||||
}
|
||||
}
|
||||
7
parsimony.example.yaml
Normal file
7
parsimony.example.yaml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
db: /data/parsimony.db
|
||||
base_url: https://lists.example.org
|
||||
lmtp:
|
||||
network: tcp
|
||||
addr: 0.0.0.0:2424
|
||||
relay:
|
||||
addr: postfix:25
|
||||
Loading…
Reference in a new issue