From e7af71676b0e3d151262a7e3181382c7db4694ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Aubr=C3=A9e?= Date: Tue, 1 Dec 2026 23:32:35 +0000 Subject: [PATCH 1/7] feat(deploy): deploy a swarm stack that has nothing to build An infrastructure stack such as a shared Redis and RabbitMQ is made only of published images, and every swarm deploy refused it with 'no services with build'. When every service pins its image by digest, the deploy now skips the builder, the build runner and the registry tunnel and applies the signed stack with those digests. A service without a digest is still refused, by name. Refs DEV-DEPL-65 Co-Authored-By: Claude Opus 5.5 --- app/go-cli/internal/cli/infra_test.go | 3 +- app/go-cli/internal/cli/swarm_deploy.go | 37 +++++++++++++++++++++---- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/app/go-cli/internal/cli/infra_test.go b/app/go-cli/internal/cli/infra_test.go index 3d8205d..0033613 100644 --- a/app/go-cli/internal/cli/infra_test.go +++ b/app/go-cli/internal/cli/infra_test.go @@ -93,7 +93,8 @@ func TestRecreateRefusesWhatTheDeployWouldRefuseBeforeDestruction(t *testing.T) {"global section", web + "volumes:\n data: {driver_opts: {type: nfs}}\n", "volume data"}, {"profile", web + " profiles: [debug]\n", "profiles"}, {"legacy secrets file", web + " env_file: .env.secrets\n", ".env.secrets"}, - {"nothing to build", "services:\n web:\n image: demo\n healthcheck:\n test: [\"CMD\", \"true\"]\n", "no services with build"}, + {"nothing to build, image not pinned", "services:\n web:\n image: demo\n healthcheck:\n test: [\"CMD\", \"true\"]\n", "service web has no image pinned by digest"}, + {"nothing to build, images pinned", "services:\n redis:\n image: redis:7-alpine@sha256:57e4255cc971b1c8d6f8a6ca283ac01bc3ecdd914273ef6bfaede87aaecd6541\n healthcheck:\n test: [\"CMD\", \"redis-cli\", \"ping\"]\n", ""}, {"no healthcheck", "services:\n web:\n build: .\n", "healthcheck"}, {"privileged", web + " privileged: true\n", "privileged"}, {"bind mount", web + " volumes: [\"./data:/data\"]\n", "volume"}, diff --git a/app/go-cli/internal/cli/swarm_deploy.go b/app/go-cli/internal/cli/swarm_deploy.go index 68858ed..42e6cc1 100644 --- a/app/go-cli/internal/cli/swarm_deploy.go +++ b/app/go-cli/internal/cli/swarm_deploy.go @@ -210,8 +210,16 @@ func deploySwarm(cfg *config.Config, skipBuild bool, dryRun bool, memoryPolicy m return err } parsed, secretNames, secretPayload, buildServices := inputs.parsed, inputs.secretNames, inputs.secretPayload, inputs.buildServices - - output.Header("Found %d services to build: %s", len(buildServices), strings.Join(buildServices, ", ")) + // Nothing to build means nothing to push either: no builder, no build + // runner and no registry tunnel. The deploy goes straight to the signed + // stack, whose images are the digests the compose file names. + imageOnly := len(buildServices) == 0 + if imageOnly { + skipBuild = true + output.Header("No services to build: every image is pinned by digest") + } else { + output.Header("Found %d services to build: %s", len(buildServices), strings.Join(buildServices, ", ")) + } output.Detail("Strategy: swarm (docker stack deploy with rolling updates)") // Advice, never a refusal: a budget the project wrote itself that is too short // for this stack's own healthchecks. The shipped defaults never trigger it. @@ -225,7 +233,7 @@ func deploySwarm(cfg *config.Config, skipBuild bool, dryRun bool, memoryPolicy m return err } var remoteBuild *ssh.BuildRunner - if cfg.Build.UsesSSH() { + if cfg.Build.UsesSSH() && !imageOnly { remoteBuild, err = newSSHBuildRunner(cfg, group, host) if err != nil { return err @@ -339,7 +347,7 @@ func deploySwarm(cfg *config.Config, skipBuild bool, dryRun bool, memoryPolicy m } } registryAddr := "127.0.0.1:5000" - if !dryRun { + if !dryRun && !imageOnly { localRegistryPort, err := allocateLoopbackPort() if err != nil { return fmt.Errorf("allocate registry tunnel port: %w", err) @@ -412,7 +420,11 @@ func deploySwarm(cfg *config.Config, skipBuild bool, dryRun bool, memoryPolicy m return err } } - fmt.Println("\n[dry-run] Would build, push through a verified SSH tunnel, and deploy via Swarm") + if imageOnly { + fmt.Println("\n[dry-run] Would deploy the pinned images via Swarm (nothing to build or push)") + } else { + fmt.Println("\n[dry-run] Would build, push through a verified SSH tunnel, and deploy via Swarm") + } fmt.Printf("[dry-run] Version: %s\n", version) // The printed stack is the stack a real deploy would apply: the derived // secret names are in it, and no value ever is. @@ -1109,8 +1121,21 @@ func checkDeployInputs(cfg *config.Config) (deployInputs, error) { if len(cfg.Build.Services) > 0 { buildServices = configuredBuildServices(cfg.Build) } + // An application made only of published images (an infrastructure stack + // such as Redis plus RabbitMQ) has nothing to build. It is deployable when + // every service names its image by digest: that digest is then the release + // identity a build would otherwise produce. if len(buildServices) == 0 { - return deployInputs{}, fmt.Errorf("no services with build: found in %s", deployComposeFiles(cfg)[0]) + names := make([]string, 0, len(parsed.Services)) + for name := range parsed.Services { + names = append(names, name) + } + sort.Strings(names) + for _, name := range names { + if !digestImage.MatchString(strings.TrimSpace(parsed.Services[name].Image)) { + return deployInputs{}, fmt.Errorf("no services with build: found in %s, and service %s has no image pinned by digest (image@sha256:...)", deployComposeFiles(cfg)[0], name) + } + } } return deployInputs{parsed: parsed, secretNames: secretNames, secretPayload: secretPayload, buildServices: buildServices}, nil } From c21fe30e4dcfadbffbdbf0cd4b3db797aec316bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Aubr=C3=A9e?= Date: Tue, 1 Dec 2026 23:12:47 +0000 Subject: [PATCH 2/7] fix(config): let an internal app's primary service update stop-first The published service may not use stop-first because it is the one behind Caddy. An expose: internal application publishes nothing, yet every app must name a primary service, so a stack whose only services are a single RabbitMQ and a single Redis could not avoid two tasks on one data volume. Refs DEV-DEPL-65 Co-Authored-By: Claude Opus 5.5 --- app/go-cli/internal/config/config.go | 10 +++++++++- app/go-cli/internal/config/update_order_test.go | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/go-cli/internal/config/config.go b/app/go-cli/internal/config/config.go index fdb8ffd..0f65841 100644 --- a/app/go-cli/internal/config/config.go +++ b/app/go-cli/internal/config/config.go @@ -1554,11 +1554,19 @@ func validate(cfg *Config) error { if web.Healthcheck.Path == "" || !strings.HasPrefix(web.Healthcheck.Path, "/") || strings.ContainsAny(web.Healthcheck.Path, "\r\n") { return fmt.Errorf("services.%s.healthcheck.path must be an absolute HTTP path", primary) } + // An internal application publishes nothing: its primary service is not + // behind Caddy, so stop-first there leaves no route without an answer. It + // is what a single-instance stateful service (Redis, RabbitMQ) needs to + // never run two tasks on one data volume. + published := primary + if cfg.IsInternal() { + published = "" + } for _, name := range sortedServiceNames(cfg.Services) { if err := validateServiceResources(name, cfg.Services[name]); err != nil { return err } - if err := validateServiceUpdateOrder(name, cfg.Services[name], primary); err != nil { + if err := validateServiceUpdateOrder(name, cfg.Services[name], published); err != nil { return err } if err := validateServiceUpdateParallelism(name, cfg.Services[name]); err != nil { diff --git a/app/go-cli/internal/config/update_order_test.go b/app/go-cli/internal/config/update_order_test.go index 0d8db21..0a86dbc 100644 --- a/app/go-cli/internal/config/update_order_test.go +++ b/app/go-cli/internal/config/update_order_test.go @@ -46,6 +46,22 @@ func TestValidateRejectsStopFirstOnThePublishedService(t *testing.T) { } } +// An internal application has no service behind Caddy. Its primary service may +// step aside before its replacement starts, which a single-instance stateful +// service (RabbitMQ, Redis on one data volume) needs. +func TestValidateAcceptsStopFirstOnTheInternalPrimaryService(t *testing.T) { + cfg := internalFixture() + service := cfg.Services["agent-next"] + service.UpdateOrder = UpdateOrderStopFirst + cfg.Services["agent-next"] = service + + // Like TestInternalApplicationNeedsNoDomain, validate() goes on to the + // server block the fixture omits; it must not stop on the update order. + if err := validate(cfg); err != nil && strings.Contains(err.Error(), "update_order") { + t.Fatalf("stop-first on the primary service of an internal application: %v", err) + } +} + // The override is an exception, not a knob: unset means the zero-downtime // default, including for services with no entry in the configuration at all. func TestUpdateOrderResolvesTheDefault(t *testing.T) { From 73af42adc239cdd3708fde2e20de44e3095f8437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Aubr=C3=A9e?= Date: Tue, 1 Dec 2026 23:12:47 +0000 Subject: [PATCH 3/7] fix(compose): accept the map form of a service's networks Compose writes a service's networks as a map to give them aliases, and the typed parse expected a list, so the whole compose file failed to load. Only the network keys are read; the raw document keeps the aliases. Refs DEV-DEPL-65 Co-Authored-By: Claude Opus 5.5 --- app/go-cli/internal/cli/compose_deploy.go | 26 ++++++++++++++++++- .../internal/cli/promotion_hooks_test.go | 10 +++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/go-cli/internal/cli/compose_deploy.go b/app/go-cli/internal/cli/compose_deploy.go index fc969bb..cdc1e03 100644 --- a/app/go-cli/internal/cli/compose_deploy.go +++ b/app/go-cli/internal/cli/compose_deploy.go @@ -6,6 +6,7 @@ import ( "os" "os/exec" "path/filepath" + "sort" "strings" "github.com/dev-toolings/shuttle/app/go-cli/internal/config" @@ -82,6 +83,29 @@ type composeFile struct { Raw map[string]any `yaml:"-"` } +// serviceNetworks is the list of network keys a service joins. Compose writes +// it either as a list or as a map whose values carry per-network settings such +// as aliases; only the keys matter here, and the raw document keeps the rest. +type serviceNetworks []string + +func (networks *serviceNetworks) UnmarshalYAML(node *yaml.Node) error { + if node.Kind == yaml.MappingNode { + keys := make([]string, 0, len(node.Content)/2) + for i := 0; i < len(node.Content); i += 2 { + keys = append(keys, node.Content[i].Value) + } + sort.Strings(keys) + *networks = keys + return nil + } + var list []string + if err := node.Decode(&list); err != nil { + return err + } + *networks = list + return nil +} + type composeService struct { Build any `yaml:"build,omitempty"` Image string `yaml:"image,omitempty"` @@ -92,7 +116,7 @@ type composeService struct { Ports []any `yaml:"ports,omitempty"` DependsOn any `yaml:"depends_on,omitempty"` Restart string `yaml:"restart,omitempty"` - Networks []string `yaml:"networks,omitempty"` + Networks serviceNetworks `yaml:"networks,omitempty"` EnvFile any `yaml:"env_file,omitempty"` Labels map[string]string `yaml:"labels,omitempty"` Command any `yaml:"command,omitempty"` diff --git a/app/go-cli/internal/cli/promotion_hooks_test.go b/app/go-cli/internal/cli/promotion_hooks_test.go index 32001f2..4c43437 100644 --- a/app/go-cli/internal/cli/promotion_hooks_test.go +++ b/app/go-cli/internal/cli/promotion_hooks_test.go @@ -43,6 +43,16 @@ func TestPreDeployAttachesEveryServiceNetwork(t *testing.T) { } } +// Compose also writes a service's networks as a map, which is the only way to +// give it aliases. That form used to fail the parse of the whole compose file. +func TestComposeServiceNetworksAcceptTheMapFormWithAliases(t *testing.T) { + parsed := parseComposeString(t, "services:\n redis:\n image: redis\n networks:\n caddy_network:\n aliases: [redis, cache]\n default: {}\nnetworks:\n caddy_network:\n external: true\n name: caddy_network\n") + got := strings.Join(preDeployNetworks("shared", "redis", parsed), " ") + if got != "caddy_network shared_default" { + t.Fatalf("map-form networks resolved to %q", got) + } +} + func TestPreDeployServiceCreateUsesAOneShotJob(t *testing.T) { args, err := preDeployServiceCreateArgs(rootplan.PreDeployOperation{ App: "api-core", From 6fdef0b56616dcec24b5228c69b7cdb47f04057a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Aubr=C3=A9e?= Date: Tue, 1 Dec 2026 23:12:47 +0000 Subject: [PATCH 4/7] docs: document image-only stacks and stop-first on internal primaries Refs DEV-DEPL-65 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 13 +++++++++++++ docs/configuration.md | 19 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43230fd..6ff454a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # Shuttle: active changes +## Une application sans build peut être déployée (DEV-DEPL-65) + +- Un stack fait uniquement d'images publiées, par exemple Redis et RabbitMQ, + se déploie sous `deploy.strategy: swarm` si chaque service fixe son image + par digest. Le déploiement ne lance ni builder, ni tunnel vers le registre, + ni push. Un service sans digest reste refusé, avec son nom dans le message. +- Le service principal d'une application `expose: internal` peut utiliser + `update_order: stop-first`. Rien n'est publié derrière Caddy, et un RabbitMQ + ou un Redis seul sur un volume ne doit jamais tourner à côté de sa + relève. Le service publié d'une application publique reste refusé. +- Les `networks` d'un service peuvent s'écrire sous forme de map, avec + `aliases`. Cette forme faisait échouer la lecture du fichier compose. + ## L'export public omettait le point d'entrée de Shuttle - L'export ajoute tous les fichiers suivis qui ont passé son filtrage. La règle diff --git a/docs/configuration.md b/docs/configuration.md index 98e4196..9e0ca4c 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -776,6 +776,21 @@ reachable is a configuration whose answer you cannot trust. Every other hardening still applies: read-only root filesystem, dropped capabilities, resource limits, healthchecks and digest-pinned images. +## Applications with nothing to build + +A stack made only of published images, such as an infrastructure stack with +Redis and RabbitMQ, has no `build:` section. Under `deploy.strategy: swarm` it +deploys when every service names its image by digest +(`image: redis:7-alpine@sha256:...`); a service without a digest is refused +before anything runs. Such a deploy starts no builder, opens no registry tunnel +and pushes nothing: the signed stack runs the digests the compose file names. + +A service named `redis` or `rabbitmq` is checked by the helper as the +application's data service: it must run as the image's account (`999:1000`, +`100:101`) and mount the volume whose key and name are `_redis_data` or +`_rabbitmq_data`. A service's `networks` may use the map form, for example +to keep network `aliases` that other stacks resolve. + ## Task limits Every service gets `cpus: 1.0` and `memory: 768M` unless it says otherwise. That @@ -823,7 +838,9 @@ during a rollback would recreate the overlap at the worst possible moment. **The published service may not opt out.** It is the one behind Caddy, and stop-first there creates a window with nothing answering. Configuration is -refused rather than discovered mid-promotion. +refused rather than discovered mid-promotion. An `expose: internal` application +publishes nothing, so its primary service may use `stop-first`: a single +RabbitMQ or Redis on one data volume must never run beside its replacement. ## Where the secret values live From 8f2db4b506f4661333319cf91b8650501e73f91e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Aubr=C3=A9e?= Date: Tue, 1 Dec 2026 23:16:58 +0000 Subject: [PATCH 5/7] fix(deploy): refuse before any operation what the helper would refuse Review of the image-only deploy: a compose service named redis or rabbitmq without its data account or __data volume key passed the client checks and was refused by the helper only, which left the operation in recovery_required (seen on the DEV-DEPL-65 recipe) and let infra recreate destroy the guest first. The same checks now run in checkDeployInputs. An internal app's compose may no longer carry dev.shuttle.domain, which would publish the service that may update stop-first, and a pre-deploy hook on a service that is not built uses the image its compose file pins. The stop-first test now proves validation went past the update order. Refs DEV-DEPL-65 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 9 +++ app/go-cli/internal/cli/infra_test.go | 4 +- app/go-cli/internal/cli/promotion_hooks.go | 6 +- .../internal/cli/promotion_hooks_test.go | 34 +++++++++ app/go-cli/internal/cli/swarm_deploy.go | 72 +++++++++++++++++++ .../internal/config/update_order_test.go | 6 +- 6 files changed, 126 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ff454a..62ec285 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,15 @@ relève. Le service publié d'une application publique reste refusé. - Les `networks` d'un service peuvent s'écrire sous forme de map, avec `aliases`. Cette forme faisait échouer la lecture du fichier compose. +- Un service compose nommé `redis` ou `rabbitmq` est vérifié avant toute + opération : compte du volume de données et volume `__data`. + Seul le helper le refusait, après la réservation de l'opération, ce qui + laissait `recovery_required`, ou après la destruction de l'invité pour + `infra recreate`. +- Une application `expose: internal` refuse un label `dev.shuttle.domain` + écrit dans son fichier compose : il la publierait derrière Caddy. +- `deploy.pre_deploy` sur un service non construit utilise l'image que le + fichier compose fixe par digest. ## L'export public omettait le point d'entrée de Shuttle diff --git a/app/go-cli/internal/cli/infra_test.go b/app/go-cli/internal/cli/infra_test.go index 0033613..fe0b9a6 100644 --- a/app/go-cli/internal/cli/infra_test.go +++ b/app/go-cli/internal/cli/infra_test.go @@ -94,7 +94,9 @@ func TestRecreateRefusesWhatTheDeployWouldRefuseBeforeDestruction(t *testing.T) {"profile", web + " profiles: [debug]\n", "profiles"}, {"legacy secrets file", web + " env_file: .env.secrets\n", ".env.secrets"}, {"nothing to build, image not pinned", "services:\n web:\n image: demo\n healthcheck:\n test: [\"CMD\", \"true\"]\n", "service web has no image pinned by digest"}, - {"nothing to build, images pinned", "services:\n redis:\n image: redis:7-alpine@sha256:57e4255cc971b1c8d6f8a6ca283ac01bc3ecdd914273ef6bfaede87aaecd6541\n healthcheck:\n test: [\"CMD\", \"redis-cli\", \"ping\"]\n", ""}, + {"nothing to build, images pinned", "services:\n redis:\n image: redis:7-alpine@sha256:57e4255cc971b1c8d6f8a6ca283ac01bc3ecdd914273ef6bfaede87aaecd6541\n user: \"999:1000\"\n volumes: [\"demo_redis_data:/data\"]\n healthcheck:\n test: [\"CMD\", \"redis-cli\", \"ping\"]\n", ""}, + {"redis without its data account", "services:\n redis:\n image: redis:7-alpine@sha256:57e4255cc971b1c8d6f8a6ca283ac01bc3ecdd914273ef6bfaede87aaecd6541\n volumes: [\"demo_redis_data:/data\"]\n healthcheck:\n test: [\"CMD\", \"redis-cli\", \"ping\"]\n", "service redis must run as \"999:1000\""}, + {"redis without its data volume key", "services:\n redis:\n image: redis:7-alpine@sha256:57e4255cc971b1c8d6f8a6ca283ac01bc3ecdd914273ef6bfaede87aaecd6541\n user: \"999:1000\"\n volumes: [\"redis_data:/data\"]\n healthcheck:\n test: [\"CMD\", \"redis-cli\", \"ping\"]\nvolumes:\n redis_data:\n name: demo_redis_data\n", "must mount the volume keyed demo_redis_data at /data"}, {"no healthcheck", "services:\n web:\n build: .\n", "healthcheck"}, {"privileged", web + " privileged: true\n", "privileged"}, {"bind mount", web + " volumes: [\"./data:/data\"]\n", "volume"}, diff --git a/app/go-cli/internal/cli/promotion_hooks.go b/app/go-cli/internal/cli/promotion_hooks.go index d5f62e6..4768d35 100644 --- a/app/go-cli/internal/cli/promotion_hooks.go +++ b/app/go-cli/internal/cli/promotion_hooks.go @@ -135,7 +135,11 @@ func runPreDeployHook(cfg *config.Config, client *ssh.Client, identity trustedHo return nil } image := strings.TrimSpace(images[hook.Service]) - if !strings.Contains(image, "@sha256:") { + // A service Shuttle does not build runs the image its compose file pins. + if image == "" && parsed != nil { + image = strings.TrimSpace(parsed.Services[hook.Service].Image) + } + if !digestImage.MatchString(image) { return fmt.Errorf("deploy.pre_deploy.service %s has no pushed image digest", hook.Service) } var sources []string diff --git a/app/go-cli/internal/cli/promotion_hooks_test.go b/app/go-cli/internal/cli/promotion_hooks_test.go index 4c43437..869958d 100644 --- a/app/go-cli/internal/cli/promotion_hooks_test.go +++ b/app/go-cli/internal/cli/promotion_hooks_test.go @@ -4,6 +4,7 @@ import ( "strings" "testing" + "github.com/dev-toolings/shuttle/app/go-cli/internal/config" "github.com/dev-toolings/shuttle/app/go-cli/internal/rootplan" ) @@ -53,6 +54,39 @@ func TestComposeServiceNetworksAcceptTheMapFormWithAliases(t *testing.T) { } } +// A pre-deploy on a service Shuttle does not build used to fail with "no pushed +// image digest" although the compose file pins its image. +func TestPreDeployUsesThePinnedImageOfAServiceThatIsNotBuilt(t *testing.T) { + const pinned = "services:\n redis:\n image: redis:7-alpine@sha256:57e4255cc971b1c8d6f8a6ca283ac01bc3ecdd914273ef6bfaede87aaecd6541\n" + cfg := &config.Config{App: "shared", Deploy: config.Deploy{PreDeploy: &config.PreDeploy{Service: "redis", Command: []string{"true"}}}} + // No signing key: the hook stops at Sign, after the image was chosen. + err := runPreDeployHook(cfg, nil, trustedHostIdentity{}, nil, "", map[string]string{}, secretManifest{}, parseComposeString(t, pinned)) + if err == nil || strings.Contains(err.Error(), "no pushed image digest") { + t.Fatalf("the pinned compose image was not used: %v", err) + } + err = runPreDeployHook(cfg, nil, trustedHostIdentity{}, nil, "", map[string]string{}, secretManifest{}, parseComposeString(t, "services:\n redis:\n image: redis:7-alpine\n")) + if err == nil || !strings.Contains(err.Error(), "no pushed image digest") { + t.Fatalf("an image without a digest must still be refused, got %v", err) + } +} + +// The root helper builds a Caddy route from a dev.shuttle.domain deploy label +// alone; written in an internal application's compose file, it would publish +// the application its configuration declares unreachable. +func TestInternalStackRefusesARouteLabel(t *testing.T) { + cfg := &config.Config{App: "shared", Expose: config.ExposeInternal} + for _, labels := range []string{"{dev.shuttle.domain: shared.example.com}", "[\"dev.shuttle.domain=shared.example.com\"]"} { + parsed := parseComposeString(t, "services:\n rabbitmq:\n image: rabbitmq\n deploy:\n labels: "+labels+"\n") + if err := validateInternalStackHasNoRoute(parsed, cfg); err == nil || !strings.Contains(err.Error(), "dev.shuttle.domain") { + t.Fatalf("labels %s were not refused: %v", labels, err) + } + } + parsed := parseComposeString(t, "services:\n rabbitmq:\n image: rabbitmq\n deploy:\n labels: {team: infra}\n") + if err := validateInternalStackHasNoRoute(parsed, cfg); err != nil { + t.Fatalf("an unrelated label was refused: %v", err) + } +} + func TestPreDeployServiceCreateUsesAOneShotJob(t *testing.T) { args, err := preDeployServiceCreateArgs(rootplan.PreDeployOperation{ App: "api-core", diff --git a/app/go-cli/internal/cli/swarm_deploy.go b/app/go-cli/internal/cli/swarm_deploy.go index 42e6cc1..52dd798 100644 --- a/app/go-cli/internal/cli/swarm_deploy.go +++ b/app/go-cli/internal/cli/swarm_deploy.go @@ -1071,6 +1071,72 @@ type deployInputs struct { // `infra recreate` calls it before destroying the guest, so a refusal added // here protects both paths; one added after it in deploySwarm leaves recreate // with no retained stack to roll back to. +// validateDeclaredInfrastructureServices runs, before anything is reserved or +// destroyed, the account and data volume rules the root helper applies to a +// compose service named redis or rabbitmq (infrastructureVolumes). Refused only +// by the helper, such a stack left the operation in recovery_required, and +// `infra recreate` refused it after the guest was already destroyed. A service +// generated by production.redis or production.rabbitmq replaces the declared +// one and is skipped. +func validateDeclaredInfrastructureServices(parsed *composeFile, cfg *config.Config) error { + services, _ := parsed.Raw["services"].(map[string]any) + for _, runtime := range infrastructureRuntimes { + if runtime.service == "redis" && cfg.Production.Redis || runtime.service == "rabbitmq" && cfg.Production.RabbitMQ { + continue + } + raw, declared := services[runtime.service] + if !declared { + continue + } + service, _ := raw.(map[string]any) + if strings.TrimSpace(fmt.Sprint(service["user"])) != runtime.user() { + return fmt.Errorf("service %s must run as %q, the account that owns its data volume", runtime.service, runtime.user()) + } + volume := cfg.App + "_" + runtime.service + "_data" + volumes, _ := service["volumes"].([]any) + mounted := false + for _, entry := range volumes { + if source, target, valid := rootVolumeSourceTarget(entry); valid && source == volume && target == runtime.target { + mounted = true + break + } + } + if !mounted { + return fmt.Errorf("service %s must mount the volume keyed %s at %s", runtime.service, volume, runtime.target) + } + } + return nil +} + +// validateInternalStackHasNoRoute keeps "publishes nothing" true for an +// internal application: the root helper builds a Caddy route from a +// dev.shuttle.domain deploy label alone, so one written in the compose file +// would publish the service the configuration says is unreachable, and which +// may update stop-first for that reason. +func validateInternalStackHasNoRoute(parsed *composeFile, cfg *config.Config) error { + if !cfg.IsInternal() { + return nil + } + services, _ := parsed.Raw["services"].(map[string]any) + for name, raw := range services { + service, _ := raw.(map[string]any) + deploy, _ := service["deploy"].(map[string]any) + switch labels := deploy["labels"].(type) { + case map[string]any: + if _, present := labels["dev.shuttle.domain"]; present { + return fmt.Errorf("service %s declares dev.shuttle.domain, which would publish an internal application", name) + } + case []any: + for _, label := range labels { + if key, _, _ := strings.Cut(fmt.Sprint(label), "="); strings.TrimSpace(key) == "dev.shuttle.domain" { + return fmt.Errorf("service %s declares dev.shuttle.domain, which would publish an internal application", name) + } + } + } + } + return nil +} + func checkDeployInputs(cfg *config.Config) (deployInputs, error) { if err := validateDeployEnvironment(cfg); err != nil { return deployInputs{}, err @@ -1087,6 +1153,12 @@ func checkDeployInputs(cfg *config.Config) (deployInputs, error) { if err := validateConfiguredSecretServices(parsed, cfg); err != nil { return deployInputs{}, err } + if err := validateDeclaredInfrastructureServices(parsed, cfg); err != nil { + return deployInputs{}, err + } + if err := validateInternalStackHasNoRoute(parsed, cfg); err != nil { + return deployInputs{}, err + } // Swarm mounts files; it does not export them. Custom images used to fail // at startup without any explanation here. Neither a preset name nor a // Dockerfile proves the runtime image's behaviour (including --skip-build), diff --git a/app/go-cli/internal/config/update_order_test.go b/app/go-cli/internal/config/update_order_test.go index 0a86dbc..2a14449 100644 --- a/app/go-cli/internal/config/update_order_test.go +++ b/app/go-cli/internal/config/update_order_test.go @@ -55,9 +55,9 @@ func TestValidateAcceptsStopFirstOnTheInternalPrimaryService(t *testing.T) { service.UpdateOrder = UpdateOrderStopFirst cfg.Services["agent-next"] = service - // Like TestInternalApplicationNeedsNoDomain, validate() goes on to the - // server block the fixture omits; it must not stop on the update order. - if err := validate(cfg); err != nil && strings.Contains(err.Error(), "update_order") { + // The fixture omits the server block, which validate() checks after the + // update order: reaching that error proves the update order was accepted. + if err := validate(cfg); err == nil || !strings.Contains(err.Error(), "singular server block") { t.Fatalf("stop-first on the primary service of an internal application: %v", err) } } From 37c30f504901e2f5e826602b7ddb7e64b2fbd170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Aubr=C3=A9e?= Date: Tue, 1 Dec 2026 23:19:20 +0000 Subject: [PATCH 6/7] fix(deploy): keep the pre-deploy hook off a replaced service's compose image Round 2 of the review: with production.redis or production.rabbitmq, the generated service replaces the compose one, so the hook must not run the compose image. The route-label test now goes through the infra recreate preparation, which shares checkDeployInputs with deploy, and fails if that check is unplugged. Refs DEV-DEPL-65 Co-Authored-By: Claude Opus 5.5 --- app/go-cli/internal/cli/promotion_hooks.go | 7 ++- .../internal/cli/promotion_hooks_test.go | 43 ++++++++++++++----- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/app/go-cli/internal/cli/promotion_hooks.go b/app/go-cli/internal/cli/promotion_hooks.go index 4768d35..1613e8d 100644 --- a/app/go-cli/internal/cli/promotion_hooks.go +++ b/app/go-cli/internal/cli/promotion_hooks.go @@ -135,8 +135,11 @@ func runPreDeployHook(cfg *config.Config, client *ssh.Client, identity trustedHo return nil } image := strings.TrimSpace(images[hook.Service]) - // A service Shuttle does not build runs the image its compose file pins. - if image == "" && parsed != nil { + // A service Shuttle does not build runs the image its compose file pins, + // unless production.redis or production.rabbitmq replaces that service with + // the generated one, whose image is not the compose file's. + generated := hook.Service == "redis" && cfg.Production.Redis || hook.Service == "rabbitmq" && cfg.Production.RabbitMQ + if image == "" && parsed != nil && !generated { image = strings.TrimSpace(parsed.Services[hook.Service].Image) } if !digestImage.MatchString(image) { diff --git a/app/go-cli/internal/cli/promotion_hooks_test.go b/app/go-cli/internal/cli/promotion_hooks_test.go index 869958d..c7d19b1 100644 --- a/app/go-cli/internal/cli/promotion_hooks_test.go +++ b/app/go-cli/internal/cli/promotion_hooks_test.go @@ -1,6 +1,8 @@ package cli import ( + "os" + "path/filepath" "strings" "testing" @@ -68,22 +70,43 @@ func TestPreDeployUsesThePinnedImageOfAServiceThatIsNotBuilt(t *testing.T) { if err == nil || !strings.Contains(err.Error(), "no pushed image digest") { t.Fatalf("an image without a digest must still be refused, got %v", err) } + // production.redis replaces the compose service with the generated one: + // its image is not the compose file's, so the hook must not run that one. + cfg.Production.Redis = true + err = runPreDeployHook(cfg, nil, trustedHostIdentity{}, nil, "", map[string]string{}, secretManifest{}, parseComposeString(t, pinned)) + if err == nil || !strings.Contains(err.Error(), "no pushed image digest") { + t.Fatalf("the compose image of a generated service was used: %v", err) + } } // The root helper builds a Caddy route from a dev.shuttle.domain deploy label // alone; written in an internal application's compose file, it would publish -// the application its configuration declares unreachable. +// the application its configuration declares unreachable. Checked through the +// preparation infra recreate runs, which shares checkDeployInputs with deploy. func TestInternalStackRefusesARouteLabel(t *testing.T) { - cfg := &config.Config{App: "shared", Expose: config.ExposeInternal} - for _, labels := range []string{"{dev.shuttle.domain: shared.example.com}", "[\"dev.shuttle.domain=shared.example.com\"]"} { - parsed := parseComposeString(t, "services:\n rabbitmq:\n image: rabbitmq\n deploy:\n labels: "+labels+"\n") - if err := validateInternalStackHasNoRoute(parsed, cfg); err == nil || !strings.Contains(err.Error(), "dev.shuttle.domain") { - t.Fatalf("labels %s were not refused: %v", labels, err) + const service = "services:\n web:\n build: .\n healthcheck:\n test: [\"CMD\", \"true\"]\n deploy:\n labels: " + for _, test := range []struct{ labels, want string }{ + {"{dev.shuttle.domain: shared.example.com}", "dev.shuttle.domain"}, + {"[\"dev.shuttle.domain=shared.example.com\"]", "dev.shuttle.domain"}, + {"{team: infra}", ""}, + } { + project := infraProject{cfg: adoptionApplyConfig(t)} + project.cfg.Expose = config.ExposeInternal + project.cfg.Infrastructure.PublicKey = writeOperatorPublicKey(t) + project.cfg.Setup.OperatorUser = "ops" + project.cfg.Setup.OperatorPublicKey = writeOperatorPublicKey(t) + compose := filepath.Join(t.TempDir(), "docker-compose.yml") + project.cfg.Deploy.ComposeFiles = []string{compose} + if err := os.WriteFile(compose, []byte(service+test.labels+"\n"), 0o600); err != nil { + t.Fatal(err) + } + _, err := prepareInfraRecreate(project) + if test.want == "" && err != nil { + t.Fatalf("labels %s were refused: %v", test.labels, err) + } + if test.want != "" && (err == nil || !strings.Contains(err.Error(), test.want)) { + t.Fatalf("labels %s were not refused: %v", test.labels, err) } - } - parsed := parseComposeString(t, "services:\n rabbitmq:\n image: rabbitmq\n deploy:\n labels: {team: infra}\n") - if err := validateInternalStackHasNoRoute(parsed, cfg); err != nil { - t.Fatalf("an unrelated label was refused: %v", err) } } From 33861bd539ec66d19011d9a99d8cabc76c642781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Aubr=C3=A9e?= Date: Tue, 1 Dec 2026 23:20:48 +0000 Subject: [PATCH 7/7] test(deploy): cover the generated RabbitMQ in the pre-deploy image choice Round 3 of the review: the generated-service guard covers both names, the test only covered Redis. Refs DEV-DEPL-65 Co-Authored-By: Claude Opus 5.5 --- app/go-cli/internal/cli/promotion_hooks_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/go-cli/internal/cli/promotion_hooks_test.go b/app/go-cli/internal/cli/promotion_hooks_test.go index c7d19b1..c070ed2 100644 --- a/app/go-cli/internal/cli/promotion_hooks_test.go +++ b/app/go-cli/internal/cli/promotion_hooks_test.go @@ -77,6 +77,11 @@ func TestPreDeployUsesThePinnedImageOfAServiceThatIsNotBuilt(t *testing.T) { if err == nil || !strings.Contains(err.Error(), "no pushed image digest") { t.Fatalf("the compose image of a generated service was used: %v", err) } + rabbit := &config.Config{App: "shared", Production: config.ProductionConfig{RabbitMQ: true}, Deploy: config.Deploy{PreDeploy: &config.PreDeploy{Service: "rabbitmq", Command: []string{"true"}}}} + err = runPreDeployHook(rabbit, nil, trustedHostIdentity{}, nil, "", map[string]string{}, secretManifest{}, parseComposeString(t, "services:\n rabbitmq:\n image: rabbitmq:4-management-alpine@sha256:0452ee3fd3b9a74160b251e693338616b464f22df4d4ba43304c101bebdca292\n")) + if err == nil || !strings.Contains(err.Error(), "no pushed image digest") { + t.Fatalf("the compose image of the generated RabbitMQ was used: %v", err) + } } // The root helper builds a Caddy route from a dev.shuttle.domain deploy label