Compare commits
1 Commits
feature/ba
...
feature/cu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2522f2017 |
@@ -8,7 +8,7 @@ A simple self-hosted PaaS that auto-deploys Docker containers from Git repositor
|
|||||||
- Per-app SSH keypairs for read-only deploy keys
|
- Per-app SSH keypairs for read-only deploy keys
|
||||||
- Per-app UUID-based webhook URLs for Gitea integration
|
- Per-app UUID-based webhook URLs for Gitea integration
|
||||||
- Branch filtering - only deploy on configured branch changes
|
- Branch filtering - only deploy on configured branch changes
|
||||||
- Environment variables, labels, and volume mounts per app
|
- Environment variables, labels, volume mounts, and custom health checks per app
|
||||||
- Docker builds via socket access
|
- Docker builds via socket access
|
||||||
- Notifications via ntfy and Slack-compatible webhooks
|
- Notifications via ntfy and Slack-compatible webhooks
|
||||||
- Simple server-rendered UI with Tailwind CSS
|
- Simple server-rendered UI with Tailwind CSS
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
-- Add custom health check command per app
|
||||||
|
ALTER TABLE apps ADD COLUMN healthcheck_command TEXT;
|
||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
dockertypes "github.com/docker/docker/api/types"
|
dockertypes "github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
@@ -145,6 +146,7 @@ type CreateContainerOptions struct {
|
|||||||
Volumes []VolumeMount
|
Volumes []VolumeMount
|
||||||
Ports []PortMapping
|
Ports []PortMapping
|
||||||
Network string
|
Network string
|
||||||
|
HealthcheckCommand string // Custom health check shell command (empty = use image default)
|
||||||
}
|
}
|
||||||
|
|
||||||
// VolumeMount represents a volume mount.
|
// VolumeMount represents a volume mount.
|
||||||
@@ -185,6 +187,29 @@ func buildPortConfig(ports []PortMapping) (nat.PortSet, nat.PortMap) {
|
|||||||
return exposedPorts, portBindings
|
return exposedPorts, portBindings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// healthcheckInterval is the time between health check attempts.
|
||||||
|
const healthcheckInterval = 30 * time.Second
|
||||||
|
|
||||||
|
// healthcheckTimeout is the maximum time a single health check can take.
|
||||||
|
const healthcheckTimeout = 10 * time.Second
|
||||||
|
|
||||||
|
// healthcheckStartPeriod is the grace period before health checks start counting failures.
|
||||||
|
const healthcheckStartPeriod = 15 * time.Second
|
||||||
|
|
||||||
|
// healthcheckRetries is the number of consecutive failures needed to mark unhealthy.
|
||||||
|
const healthcheckRetries = 3
|
||||||
|
|
||||||
|
// buildHealthcheck creates a Docker health check config from a shell command string.
|
||||||
|
func buildHealthcheck(command string) *container.HealthConfig {
|
||||||
|
return &container.HealthConfig{
|
||||||
|
Test: []string{"CMD-SHELL", command},
|
||||||
|
Interval: healthcheckInterval,
|
||||||
|
Timeout: healthcheckTimeout,
|
||||||
|
StartPeriod: healthcheckStartPeriod,
|
||||||
|
Retries: healthcheckRetries,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// CreateContainer creates a new container.
|
// CreateContainer creates a new container.
|
||||||
func (c *Client) CreateContainer(
|
func (c *Client) CreateContainer(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
@@ -218,14 +243,22 @@ func (c *Client) CreateContainer(
|
|||||||
// Convert ports to exposed ports and port bindings
|
// Convert ports to exposed ports and port bindings
|
||||||
exposedPorts, portBindings := buildPortConfig(opts.Ports)
|
exposedPorts, portBindings := buildPortConfig(opts.Ports)
|
||||||
|
|
||||||
// Create container
|
// Build container config
|
||||||
resp, err := c.docker.ContainerCreate(ctx,
|
containerConfig := &container.Config{
|
||||||
&container.Config{
|
|
||||||
Image: opts.Image,
|
Image: opts.Image,
|
||||||
Env: envSlice,
|
Env: envSlice,
|
||||||
Labels: opts.Labels,
|
Labels: opts.Labels,
|
||||||
ExposedPorts: exposedPorts,
|
ExposedPorts: exposedPorts,
|
||||||
},
|
}
|
||||||
|
|
||||||
|
// Apply custom health check if configured
|
||||||
|
if opts.HealthcheckCommand != "" {
|
||||||
|
containerConfig.Healthcheck = buildHealthcheck(opts.HealthcheckCommand)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create container
|
||||||
|
resp, err := c.docker.ContainerCreate(ctx,
|
||||||
|
containerConfig,
|
||||||
&container.HostConfig{
|
&container.HostConfig{
|
||||||
Mounts: mounts,
|
Mounts: mounts,
|
||||||
PortBindings: portBindings,
|
PortBindings: portBindings,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValidBranchRegex(t *testing.T) {
|
func TestValidBranchRegex(t *testing.T) {
|
||||||
@@ -146,3 +147,52 @@ func TestCloneRepoRejectsInjection(t *testing.T) { //nolint:funlen // table-driv
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildHealthcheck(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
t.Run("creates CMD-SHELL health check", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
cmd := "curl -f http://localhost:8080/healthz || exit 1"
|
||||||
|
hc := buildHealthcheck(cmd)
|
||||||
|
|
||||||
|
if len(hc.Test) != 2 {
|
||||||
|
t.Fatalf("expected 2 test elements, got %d", len(hc.Test))
|
||||||
|
}
|
||||||
|
|
||||||
|
if hc.Test[0] != "CMD-SHELL" {
|
||||||
|
t.Errorf("expected Test[0]=%q, got %q", "CMD-SHELL", hc.Test[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
if hc.Test[1] != cmd {
|
||||||
|
t.Errorf("expected Test[1]=%q, got %q", cmd, hc.Test[1])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("sets expected intervals", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
hc := buildHealthcheck("true")
|
||||||
|
|
||||||
|
expectedInterval := 30 * time.Second
|
||||||
|
if hc.Interval != expectedInterval {
|
||||||
|
t.Errorf("expected Interval=%v, got %v", expectedInterval, hc.Interval)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedTimeout := 10 * time.Second
|
||||||
|
if hc.Timeout != expectedTimeout {
|
||||||
|
t.Errorf("expected Timeout=%v, got %v", expectedTimeout, hc.Timeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedStartPeriod := 15 * time.Second
|
||||||
|
if hc.StartPeriod != expectedStartPeriod {
|
||||||
|
t.Errorf("expected StartPeriod=%v, got %v", expectedStartPeriod, hc.StartPeriod)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedRetries := 3
|
||||||
|
if hc.Retries != expectedRetries {
|
||||||
|
t.Errorf("expected Retries=%d, got %d", expectedRetries, hc.Retries)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ func (h *Handlers) HandleAppCreate() http.HandlerFunc { //nolint:funlen // valid
|
|||||||
dockerNetwork := request.FormValue("docker_network")
|
dockerNetwork := request.FormValue("docker_network")
|
||||||
ntfyTopic := request.FormValue("ntfy_topic")
|
ntfyTopic := request.FormValue("ntfy_topic")
|
||||||
slackWebhook := request.FormValue("slack_webhook")
|
slackWebhook := request.FormValue("slack_webhook")
|
||||||
|
healthcheckCommand := request.FormValue("healthcheck_command")
|
||||||
|
|
||||||
data := h.addGlobals(map[string]any{
|
data := h.addGlobals(map[string]any{
|
||||||
"Name": name,
|
"Name": name,
|
||||||
@@ -66,6 +67,7 @@ func (h *Handlers) HandleAppCreate() http.HandlerFunc { //nolint:funlen // valid
|
|||||||
"DockerNetwork": dockerNetwork,
|
"DockerNetwork": dockerNetwork,
|
||||||
"NtfyTopic": ntfyTopic,
|
"NtfyTopic": ntfyTopic,
|
||||||
"SlackWebhook": slackWebhook,
|
"SlackWebhook": slackWebhook,
|
||||||
|
"HealthcheckCommand": healthcheckCommand,
|
||||||
}, request)
|
}, request)
|
||||||
|
|
||||||
if name == "" || repoURL == "" {
|
if name == "" || repoURL == "" {
|
||||||
@@ -109,6 +111,7 @@ func (h *Handlers) HandleAppCreate() http.HandlerFunc { //nolint:funlen // valid
|
|||||||
DockerNetwork: dockerNetwork,
|
DockerNetwork: dockerNetwork,
|
||||||
NtfyTopic: ntfyTopic,
|
NtfyTopic: ntfyTopic,
|
||||||
SlackWebhook: slackWebhook,
|
SlackWebhook: slackWebhook,
|
||||||
|
HealthcheckCommand: healthcheckCommand,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if createErr != nil {
|
if createErr != nil {
|
||||||
@@ -208,6 +211,11 @@ func (h *Handlers) HandleAppEdit() http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// optionalNullString returns a valid NullString if the value is non-empty, or an empty NullString.
|
||||||
|
func optionalNullString(value string) sql.NullString {
|
||||||
|
return sql.NullString{String: value, Valid: value != ""}
|
||||||
|
}
|
||||||
|
|
||||||
// HandleAppUpdate handles app updates.
|
// HandleAppUpdate handles app updates.
|
||||||
func (h *Handlers) HandleAppUpdate() http.HandlerFunc { //nolint:funlen // validation adds necessary length
|
func (h *Handlers) HandleAppUpdate() http.HandlerFunc { //nolint:funlen // validation adds necessary length
|
||||||
tmpl := templates.GetParsed()
|
tmpl := templates.GetParsed()
|
||||||
@@ -257,24 +265,10 @@ func (h *Handlers) HandleAppUpdate() http.HandlerFunc { //nolint:funlen // valid
|
|||||||
application.RepoURL = request.FormValue("repo_url")
|
application.RepoURL = request.FormValue("repo_url")
|
||||||
application.Branch = request.FormValue("branch")
|
application.Branch = request.FormValue("branch")
|
||||||
application.DockerfilePath = request.FormValue("dockerfile_path")
|
application.DockerfilePath = request.FormValue("dockerfile_path")
|
||||||
|
application.DockerNetwork = optionalNullString(request.FormValue("docker_network"))
|
||||||
if network := request.FormValue("docker_network"); network != "" {
|
application.NtfyTopic = optionalNullString(request.FormValue("ntfy_topic"))
|
||||||
application.DockerNetwork = sql.NullString{String: network, Valid: true}
|
application.SlackWebhook = optionalNullString(request.FormValue("slack_webhook"))
|
||||||
} else {
|
application.HealthcheckCommand = optionalNullString(request.FormValue("healthcheck_command"))
|
||||||
application.DockerNetwork = sql.NullString{}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ntfy := request.FormValue("ntfy_topic"); ntfy != "" {
|
|
||||||
application.NtfyTopic = sql.NullString{String: ntfy, Valid: true}
|
|
||||||
} else {
|
|
||||||
application.NtfyTopic = sql.NullString{}
|
|
||||||
}
|
|
||||||
|
|
||||||
if slack := request.FormValue("slack_webhook"); slack != "" {
|
|
||||||
application.SlackWebhook = sql.NullString{String: slack, Valid: true}
|
|
||||||
} else {
|
|
||||||
application.SlackWebhook = sql.NullString{}
|
|
||||||
}
|
|
||||||
|
|
||||||
saveErr := application.Save(request.Context())
|
saveErr := application.Save(request.Context())
|
||||||
if saveErr != nil {
|
if saveErr != nil {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
const appColumns = `id, name, repo_url, branch, dockerfile_path, webhook_secret,
|
const appColumns = `id, name, repo_url, branch, dockerfile_path, webhook_secret,
|
||||||
ssh_private_key, ssh_public_key, image_id, status,
|
ssh_private_key, ssh_public_key, image_id, status,
|
||||||
docker_network, ntfy_topic, slack_webhook, webhook_secret_hash,
|
docker_network, ntfy_topic, slack_webhook, webhook_secret_hash,
|
||||||
previous_image_id, created_at, updated_at`
|
previous_image_id, healthcheck_command, created_at, updated_at`
|
||||||
|
|
||||||
// AppStatus represents the status of an app.
|
// AppStatus represents the status of an app.
|
||||||
type AppStatus string
|
type AppStatus string
|
||||||
@@ -47,6 +47,7 @@ type App struct {
|
|||||||
DockerNetwork sql.NullString
|
DockerNetwork sql.NullString
|
||||||
NtfyTopic sql.NullString
|
NtfyTopic sql.NullString
|
||||||
SlackWebhook sql.NullString
|
SlackWebhook sql.NullString
|
||||||
|
HealthcheckCommand sql.NullString
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
}
|
}
|
||||||
@@ -142,14 +143,14 @@ func (a *App) insert(ctx context.Context) error {
|
|||||||
id, name, repo_url, branch, dockerfile_path, webhook_secret,
|
id, name, repo_url, branch, dockerfile_path, webhook_secret,
|
||||||
ssh_private_key, ssh_public_key, image_id, status,
|
ssh_private_key, ssh_public_key, image_id, status,
|
||||||
docker_network, ntfy_topic, slack_webhook, webhook_secret_hash,
|
docker_network, ntfy_topic, slack_webhook, webhook_secret_hash,
|
||||||
previous_image_id
|
previous_image_id, healthcheck_command
|
||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||||
|
|
||||||
_, err := a.db.Exec(ctx, query,
|
_, err := a.db.Exec(ctx, query,
|
||||||
a.ID, a.Name, a.RepoURL, a.Branch, a.DockerfilePath, a.WebhookSecret,
|
a.ID, a.Name, a.RepoURL, a.Branch, a.DockerfilePath, a.WebhookSecret,
|
||||||
a.SSHPrivateKey, a.SSHPublicKey, a.ImageID, a.Status,
|
a.SSHPrivateKey, a.SSHPublicKey, a.ImageID, a.Status,
|
||||||
a.DockerNetwork, a.NtfyTopic, a.SlackWebhook, a.WebhookSecretHash,
|
a.DockerNetwork, a.NtfyTopic, a.SlackWebhook, a.WebhookSecretHash,
|
||||||
a.PreviousImageID,
|
a.PreviousImageID, a.HealthcheckCommand,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -164,7 +165,7 @@ func (a *App) update(ctx context.Context) error {
|
|||||||
name = ?, repo_url = ?, branch = ?, dockerfile_path = ?,
|
name = ?, repo_url = ?, branch = ?, dockerfile_path = ?,
|
||||||
image_id = ?, status = ?,
|
image_id = ?, status = ?,
|
||||||
docker_network = ?, ntfy_topic = ?, slack_webhook = ?,
|
docker_network = ?, ntfy_topic = ?, slack_webhook = ?,
|
||||||
previous_image_id = ?,
|
previous_image_id = ?, healthcheck_command = ?,
|
||||||
updated_at = CURRENT_TIMESTAMP
|
updated_at = CURRENT_TIMESTAMP
|
||||||
WHERE id = ?`
|
WHERE id = ?`
|
||||||
|
|
||||||
@@ -172,7 +173,7 @@ func (a *App) update(ctx context.Context) error {
|
|||||||
a.Name, a.RepoURL, a.Branch, a.DockerfilePath,
|
a.Name, a.RepoURL, a.Branch, a.DockerfilePath,
|
||||||
a.ImageID, a.Status,
|
a.ImageID, a.Status,
|
||||||
a.DockerNetwork, a.NtfyTopic, a.SlackWebhook,
|
a.DockerNetwork, a.NtfyTopic, a.SlackWebhook,
|
||||||
a.PreviousImageID,
|
a.PreviousImageID, a.HealthcheckCommand,
|
||||||
a.ID,
|
a.ID,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -187,7 +188,7 @@ func (a *App) scan(row *sql.Row) error {
|
|||||||
&a.ImageID, &a.Status,
|
&a.ImageID, &a.Status,
|
||||||
&a.DockerNetwork, &a.NtfyTopic, &a.SlackWebhook,
|
&a.DockerNetwork, &a.NtfyTopic, &a.SlackWebhook,
|
||||||
&a.WebhookSecretHash,
|
&a.WebhookSecretHash,
|
||||||
&a.PreviousImageID,
|
&a.PreviousImageID, &a.HealthcheckCommand,
|
||||||
&a.CreatedAt, &a.UpdatedAt,
|
&a.CreatedAt, &a.UpdatedAt,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -205,7 +206,7 @@ func scanApps(appDB *database.Database, rows *sql.Rows) ([]*App, error) {
|
|||||||
&app.ImageID, &app.Status,
|
&app.ImageID, &app.Status,
|
||||||
&app.DockerNetwork, &app.NtfyTopic, &app.SlackWebhook,
|
&app.DockerNetwork, &app.NtfyTopic, &app.SlackWebhook,
|
||||||
&app.WebhookSecretHash,
|
&app.WebhookSecretHash,
|
||||||
&app.PreviousImageID,
|
&app.PreviousImageID, &app.HealthcheckCommand,
|
||||||
&app.CreatedAt, &app.UpdatedAt,
|
&app.CreatedAt, &app.UpdatedAt,
|
||||||
)
|
)
|
||||||
if scanErr != nil {
|
if scanErr != nil {
|
||||||
|
|||||||
@@ -704,6 +704,72 @@ func TestAppGetWebhookEvents(t *testing.T) {
|
|||||||
assert.Len(t, events, 1)
|
assert.Len(t, events, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// App HealthcheckCommand Tests.
|
||||||
|
|
||||||
|
func TestAppHealthcheckCommand(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
t.Run("saves and loads healthcheck command", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
testDB, cleanup := setupTestDB(t)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
app := createTestApp(t, testDB)
|
||||||
|
app.HealthcheckCommand = sql.NullString{
|
||||||
|
String: "curl -f http://localhost:8080/healthz || exit 1",
|
||||||
|
Valid: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := app.Save(context.Background())
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
found, err := models.FindApp(context.Background(), testDB, app.ID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, found)
|
||||||
|
assert.True(t, found.HealthcheckCommand.Valid)
|
||||||
|
assert.Equal(t, "curl -f http://localhost:8080/healthz || exit 1", found.HealthcheckCommand.String)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("null when not set", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
testDB, cleanup := setupTestDB(t)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
app := createTestApp(t, testDB)
|
||||||
|
|
||||||
|
found, err := models.FindApp(context.Background(), testDB, app.ID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, found)
|
||||||
|
assert.False(t, found.HealthcheckCommand.Valid)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("can be cleared", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
testDB, cleanup := setupTestDB(t)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
app := createTestApp(t, testDB)
|
||||||
|
app.HealthcheckCommand = sql.NullString{String: "true", Valid: true}
|
||||||
|
|
||||||
|
err := app.Save(context.Background())
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Clear it
|
||||||
|
app.HealthcheckCommand = sql.NullString{}
|
||||||
|
|
||||||
|
err = app.Save(context.Background())
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
found, err := models.FindApp(context.Background(), testDB, app.ID)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, found)
|
||||||
|
assert.False(t, found.HealthcheckCommand.Valid)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Cascade Delete Tests.
|
// Cascade Delete Tests.
|
||||||
|
|
||||||
//nolint:funlen // Test function with many assertions - acceptable for integration tests
|
//nolint:funlen // Test function with many assertions - acceptable for integration tests
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ type CreateAppInput struct {
|
|||||||
DockerNetwork string
|
DockerNetwork string
|
||||||
NtfyTopic string
|
NtfyTopic string
|
||||||
SlackWebhook string
|
SlackWebhook string
|
||||||
|
HealthcheckCommand string
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateApp creates a new application with generated SSH keys and webhook secret.
|
// CreateApp creates a new application with generated SSH keys and webhook secret.
|
||||||
@@ -100,6 +101,10 @@ func (svc *Service) CreateApp(
|
|||||||
app.SlackWebhook = sql.NullString{String: input.SlackWebhook, Valid: true}
|
app.SlackWebhook = sql.NullString{String: input.SlackWebhook, Valid: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if input.HealthcheckCommand != "" {
|
||||||
|
app.HealthcheckCommand = sql.NullString{String: input.HealthcheckCommand, Valid: true}
|
||||||
|
}
|
||||||
|
|
||||||
saveErr := app.Save(ctx)
|
saveErr := app.Save(ctx)
|
||||||
if saveErr != nil {
|
if saveErr != nil {
|
||||||
return nil, fmt.Errorf("failed to save app: %w", saveErr)
|
return nil, fmt.Errorf("failed to save app: %w", saveErr)
|
||||||
@@ -119,6 +124,7 @@ type UpdateAppInput struct {
|
|||||||
DockerNetwork string
|
DockerNetwork string
|
||||||
NtfyTopic string
|
NtfyTopic string
|
||||||
SlackWebhook string
|
SlackWebhook string
|
||||||
|
HealthcheckCommand string
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateApp updates an existing application.
|
// UpdateApp updates an existing application.
|
||||||
@@ -144,6 +150,10 @@ func (svc *Service) UpdateApp(
|
|||||||
String: input.SlackWebhook,
|
String: input.SlackWebhook,
|
||||||
Valid: input.SlackWebhook != "",
|
Valid: input.SlackWebhook != "",
|
||||||
}
|
}
|
||||||
|
app.HealthcheckCommand = sql.NullString{
|
||||||
|
String: input.HealthcheckCommand,
|
||||||
|
Valid: input.HealthcheckCommand != "",
|
||||||
|
}
|
||||||
|
|
||||||
saveErr := app.Save(ctx)
|
saveErr := app.Save(ctx)
|
||||||
if saveErr != nil {
|
if saveErr != nil {
|
||||||
|
|||||||
@@ -1094,6 +1094,11 @@ func (svc *Service) buildContainerOptions(
|
|||||||
network = app.DockerNetwork.String
|
network = app.DockerNetwork.String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
healthcheckCmd := ""
|
||||||
|
if app.HealthcheckCommand.Valid {
|
||||||
|
healthcheckCmd = app.HealthcheckCommand.String
|
||||||
|
}
|
||||||
|
|
||||||
return docker.CreateContainerOptions{
|
return docker.CreateContainerOptions{
|
||||||
Name: "upaas-" + app.Name,
|
Name: "upaas-" + app.Name,
|
||||||
Image: imageID.String(),
|
Image: imageID.String(),
|
||||||
@@ -1102,6 +1107,7 @@ func (svc *Service) buildContainerOptions(
|
|||||||
Volumes: buildVolumeMounts(volumes),
|
Volumes: buildVolumeMounts(volumes),
|
||||||
Ports: buildPortMappings(ports),
|
Ports: buildPortMappings(ports),
|
||||||
Network: network,
|
Network: network,
|
||||||
|
HealthcheckCommand: healthcheckCmd,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package deploy_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -43,3 +44,64 @@ func TestBuildContainerOptionsUsesImageID(t *testing.T) {
|
|||||||
t.Errorf("expected Name=%q, got %q", "upaas-myapp", opts.Name)
|
t.Errorf("expected Name=%q, got %q", "upaas-myapp", opts.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildContainerOptionsHealthcheckSet(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
db := database.NewTestDatabase(t)
|
||||||
|
|
||||||
|
app := models.NewApp(db)
|
||||||
|
app.Name = "hc-app"
|
||||||
|
app.HealthcheckCommand = sql.NullString{
|
||||||
|
String: "curl -f http://localhost:8080/healthz || exit 1",
|
||||||
|
Valid: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
err := app.Save(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to save app: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
||||||
|
svc := deploy.NewTestService(log)
|
||||||
|
|
||||||
|
opts, err := svc.BuildContainerOptionsExported(
|
||||||
|
context.Background(), app, "sha256:test",
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("buildContainerOptions returned error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := "curl -f http://localhost:8080/healthz || exit 1"
|
||||||
|
if opts.HealthcheckCommand != expected {
|
||||||
|
t.Errorf("expected HealthcheckCommand=%q, got %q", expected, opts.HealthcheckCommand)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildContainerOptionsHealthcheckEmpty(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
db := database.NewTestDatabase(t)
|
||||||
|
|
||||||
|
app := models.NewApp(db)
|
||||||
|
app.Name = "no-hc-app"
|
||||||
|
|
||||||
|
err := app.Save(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to save app: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log := slog.New(slog.NewTextHandler(os.Stderr, nil))
|
||||||
|
svc := deploy.NewTestService(log)
|
||||||
|
|
||||||
|
opts, err := svc.BuildContainerOptionsExported(
|
||||||
|
context.Background(), app, "sha256:test",
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("buildContainerOptions returned error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.HealthcheckCommand != "" {
|
||||||
|
t.Errorf("expected empty HealthcheckCommand, got %q", opts.HealthcheckCommand)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -114,6 +114,19 @@
|
|||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="healthcheck_command" class="label">Health Check Command</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="healthcheck_command"
|
||||||
|
name="healthcheck_command"
|
||||||
|
value="{{if .App.HealthcheckCommand.Valid}}{{.App.HealthcheckCommand.String}}{{end}}"
|
||||||
|
class="input font-mono"
|
||||||
|
placeholder="curl -f http://localhost:8080/healthz || exit 1"
|
||||||
|
>
|
||||||
|
<p class="text-sm text-gray-500 mt-1">Custom shell command to check container health. Leave empty to use the image's default health check.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="flex justify-end gap-3 pt-4">
|
<div class="flex justify-end gap-3 pt-4">
|
||||||
<a href="/apps/{{.App.ID}}" class="btn-secondary">Cancel</a>
|
<a href="/apps/{{.App.ID}}" class="btn-secondary">Cancel</a>
|
||||||
<button type="submit" class="btn-primary">Save Changes</button>
|
<button type="submit" class="btn-primary">Save Changes</button>
|
||||||
|
|||||||
@@ -117,6 +117,19 @@
|
|||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="healthcheck_command" class="label">Health Check Command</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="healthcheck_command"
|
||||||
|
name="healthcheck_command"
|
||||||
|
value="{{.HealthcheckCommand}}"
|
||||||
|
class="input font-mono"
|
||||||
|
placeholder="curl -f http://localhost:8080/healthz || exit 1"
|
||||||
|
>
|
||||||
|
<p class="text-sm text-gray-500 mt-1">Custom shell command to check container health. Leave empty to use the image's default health check.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="flex justify-end gap-3 pt-4">
|
<div class="flex justify-end gap-3 pt-4">
|
||||||
<a href="/" class="btn-secondary">Cancel</a>
|
<a href="/" class="btn-secondary">Cancel</a>
|
||||||
<button type="submit" class="btn-primary">Create App</button>
|
<button type="submit" class="btn-primary">Create App</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user