diff options
| author | bndw <ben@bdw.to> | 2026-01-25 08:06:56 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-01-25 08:06:56 -0800 |
| commit | 85e97bf1ebe339513ab0661f6cc1ab1ff17a46cb (patch) | |
| tree | bd65f952b632375d0512aaf32ce17fd79ae1b262 /internal | |
| parent | 8a3cff0dd7eb88cadb73a6df4e14f85450d63317 (diff) | |
Add CPU and memory limits for apps
Adds --memory and --cpu flags to set systemd resource limits:
ship --binary ./app --memory 512M --cpu 100%
Also adds config update mode - use --name without --binary to
update an existing app's config without redeploying the binary:
ship --name myapp --cpu 50%
ship --name myapp --memory 256M --env DEBUG=true
Limits are stored in state and preserved on redeploy.
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/state/state.go | 12 | ||||
| -rw-r--r-- | internal/templates/templates.go | 6 |
2 files changed, 13 insertions, 5 deletions
diff --git a/internal/state/state.go b/internal/state/state.go index c6de34a..38657cb 100644 --- a/internal/state/state.go +++ b/internal/state/state.go | |||
| @@ -22,12 +22,14 @@ type Host struct { | |||
| 22 | 22 | ||
| 23 | // App represents a deployed application or static site | 23 | // App represents a deployed application or static site |
| 24 | type App struct { | 24 | type App struct { |
| 25 | Type string `json:"type"` // "app" or "static" | 25 | Type string `json:"type"` // "app" or "static" |
| 26 | Domain string `json:"domain"` | 26 | Domain string `json:"domain"` |
| 27 | Port int `json:"port,omitempty"` // only for type="app" | 27 | Port int `json:"port,omitempty"` // only for type="app" |
| 28 | Env map[string]string `json:"env,omitempty"` // only for type="app" | 28 | Env map[string]string `json:"env,omitempty"` // only for type="app" |
| 29 | Args string `json:"args,omitempty"` // only for type="app" | 29 | Args string `json:"args,omitempty"` // only for type="app" |
| 30 | Files []string `json:"files,omitempty"` // only for type="app" | 30 | Files []string `json:"files,omitempty"` // only for type="app" |
| 31 | Memory string `json:"memory,omitempty"` // only for type="app" | ||
| 32 | CPU string `json:"cpu,omitempty"` // only for type="app" | ||
| 31 | } | 33 | } |
| 32 | 34 | ||
| 33 | const ( | 35 | const ( |
diff --git a/internal/templates/templates.go b/internal/templates/templates.go index feb6c10..ce1cbe5 100644 --- a/internal/templates/templates.go +++ b/internal/templates/templates.go | |||
| @@ -19,6 +19,12 @@ Restart=always | |||
| 19 | RestartSec=5s | 19 | RestartSec=5s |
| 20 | NoNewPrivileges=true | 20 | NoNewPrivileges=true |
| 21 | PrivateTmp=true | 21 | PrivateTmp=true |
| 22 | {{- if .Memory}} | ||
| 23 | MemoryMax={{.Memory}} | ||
| 24 | {{- end}} | ||
| 25 | {{- if .CPU}} | ||
| 26 | CPUQuota={{.CPU}} | ||
| 27 | {{- end}} | ||
| 22 | 28 | ||
| 23 | [Install] | 29 | [Install] |
| 24 | WantedBy=multi-user.target | 30 | WantedBy=multi-user.target |
