feat(pre-deploy): add support for x-pre_deploy extension in Compose + e2e test

This commit is contained in:
Pasha Sviderski
2026-04-08 19:16:42 +10:00
parent 772b31b57f
commit 0e820f9c52
13 changed files with 371 additions and 4 deletions
+28 -1
View File
@@ -33,7 +33,7 @@ func ServiceSpecFromCompose(project *types.Project, serviceName string) (api.Ser
return api.ServiceSpec{}, fmt.Errorf("unsupported pull policy: '%s'", service.PullPolicy)
}
env := make(map[string]string, len(service.Environment))
env := make(api.EnvVars, len(service.Environment))
for k, v := range service.Environment {
if v == nil {
// nil value means the variable misses a value in the compose file, and it hasn't been resolved
@@ -142,6 +142,27 @@ func ServiceSpecFromCompose(project *types.Project, serviceName string) (api.Ser
spec.Configs = configSpecs
spec.Container.ConfigMounts = configMounts
if h, ok := service.Extensions[PreDeployHookExtensionKey].(PreDeployHook); ok {
hook := &api.PreDeployHook{
Command: h.Command,
Privileged: h.Privileged,
User: h.User,
}
if h.Environment != nil {
hook.Env = make(api.EnvVars)
for k, v := range h.Environment {
if v != nil {
hook.Env[k] = *v
}
}
}
if h.Timeout != nil {
d := time.Duration(*h.Timeout)
hook.Timeout = &d
}
spec.PreDeploy = hook
}
return spec, nil
}
@@ -418,6 +439,12 @@ func validateServicesExtensions(project *types.Project) error {
"Host mode ports in 'x-caddy' can be used with 'x-caddy'", service.Name)
}
}
if hook, ok := service.Extensions[PreDeployHookExtensionKey].(PreDeployHook); ok {
if err := hook.Validate(); err != nil {
return fmt.Errorf("service '%s': %w", service.Name, err)
}
}
}
return nil