diff options
| author | Claude <noreply@anthropic.com> | 2026-08-05 23:14:29 -0500 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-08-05 23:14:29 -0500 |
| commit | 9f7c9f2f31acd7bc544dd988af1c8c2fe63ec504 (patch) | |
| tree | 6d7ab2a965c3e138a56c625197658ef2b324b045 /internal/nginx | |
Initial commit of skiff scaffolding
Diffstat (limited to 'internal/nginx')
| -rw-r--r-- | internal/nginx/nginx.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/internal/nginx/nginx.go b/internal/nginx/nginx.go new file mode 100644 index 0000000..abdd4c9 --- /dev/null +++ b/internal/nginx/nginx.go @@ -0,0 +1,45 @@ +// Package nginx regenerates one vhost file per app and reloads. Skiff never +// touches nginx.conf itself - that just needs one `include skiff.d/*.conf;` +// line added once, by hand, when nginx is first set up. +package nginx + +import ( + "context" + "fmt" + "io" + "os" + + "skiff/internal/layout" + "skiff/internal/sh" + "skiff/internal/tmpl" +) + +// EnsureRoute writes app's vhost file and reloads nginx, but only if the +// rendered config actually changed - most deploys don't touch routing. +func EnsureRoute(ctx context.Context, out io.Writer, cfg layout.Config, app, ip string, port int, serverName string) error { + rendered, err := tmpl.NginxApp(tmpl.NginxAppData{ + Name: app, + IP: ip, + Port: port, + ServerName: serverName, + }) + if err != nil { + return err + } + + path := cfg.NginxConfPath(app) + existing, _ := os.ReadFile(path) + if string(existing) == rendered { + return nil + } + + if err := os.WriteFile(path, []byte(rendered), 0644); err != nil { + return fmt.Errorf("write nginx conf for %s: %w", app, err) + } + fmt.Fprintf(out, "==> nginx route changed for %s, reloading\n", app) + return Reload(ctx, out) +} + +func Reload(ctx context.Context, out io.Writer) error { + return sh.Run(ctx, out, "", "nginx", "-s", "reload") +} |
