From 1e24451cc94c9a9a8ccff9f6bc02d6d8cccf2f4c Mon Sep 17 00:00:00 2001 From: cmeng Date: Tue, 29 Aug 2023 11:48:57 +1200 Subject: [PATCH] fix(relative-path): not deploy git stack via unpacker EE-6043 (#10194) --- api/http/handler/stacks/stack_delete.go | 4 ++-- api/http/handler/stacks/stack_start.go | 4 ++-- api/http/handler/stacks/stack_stop.go | 4 ++-- api/stacks/deployments/deploy.go | 4 ++-- api/stacks/deployments/deployment_compose_config.go | 2 +- api/stacks/deployments/deployment_swarm_config.go | 2 +- api/stacks/stackutils/util.go | 7 +++++++ 7 files changed, 17 insertions(+), 10 deletions(-) diff --git a/api/http/handler/stacks/stack_delete.go b/api/http/handler/stacks/stack_delete.go index 840af0c72..947e0009c 100644 --- a/api/http/handler/stacks/stack_delete.go +++ b/api/http/handler/stacks/stack_delete.go @@ -190,7 +190,7 @@ func (handler *Handler) deleteStack(userID portainer.UserID, stack *portainer.St if stack.Type == portainer.DockerSwarmStack { stack.Name = handler.SwarmStackManager.NormalizeStackName(stack.Name) - if stackutils.IsGitStack(stack) { + if stackutils.IsRelativePathStack(stack) { return handler.StackDeployer.UndeployRemoteSwarmStack(stack, endpoint) } @@ -200,7 +200,7 @@ func (handler *Handler) deleteStack(userID portainer.UserID, stack *portainer.St if stack.Type == portainer.DockerComposeStack { stack.Name = handler.ComposeStackManager.NormalizeStackName(stack.Name) - if stackutils.IsGitStack(stack) { + if stackutils.IsRelativePathStack(stack) { return handler.StackDeployer.UndeployRemoteComposeStack(stack, endpoint) } diff --git a/api/http/handler/stacks/stack_start.go b/api/http/handler/stacks/stack_start.go index a5d45bb95..9cdefd7b0 100644 --- a/api/http/handler/stacks/stack_start.go +++ b/api/http/handler/stacks/stack_start.go @@ -145,7 +145,7 @@ func (handler *Handler) startStack( case portainer.DockerComposeStack: stack.Name = handler.ComposeStackManager.NormalizeStackName(stack.Name) - if stackutils.IsGitStack(stack) { + if stackutils.IsRelativePathStack(stack) { return handler.StackDeployer.StartRemoteComposeStack(stack, endpoint) } @@ -153,7 +153,7 @@ func (handler *Handler) startStack( case portainer.DockerSwarmStack: stack.Name = handler.SwarmStackManager.NormalizeStackName(stack.Name) - if stackutils.IsGitStack(stack) { + if stackutils.IsRelativePathStack(stack) { return handler.StackDeployer.StartRemoteSwarmStack(stack, endpoint) } diff --git a/api/http/handler/stacks/stack_stop.go b/api/http/handler/stacks/stack_stop.go index e395dc18e..b0dd44de1 100644 --- a/api/http/handler/stacks/stack_stop.go +++ b/api/http/handler/stacks/stack_stop.go @@ -125,7 +125,7 @@ func (handler *Handler) stopStack(stack *portainer.Stack, endpoint *portainer.En case portainer.DockerComposeStack: stack.Name = handler.ComposeStackManager.NormalizeStackName(stack.Name) - if stackutils.IsGitStack(stack) { + if stackutils.IsRelativePathStack(stack) { return handler.StackDeployer.StopRemoteComposeStack(stack, endpoint) } @@ -133,7 +133,7 @@ func (handler *Handler) stopStack(stack *portainer.Stack, endpoint *portainer.En case portainer.DockerSwarmStack: stack.Name = handler.SwarmStackManager.NormalizeStackName(stack.Name) - if stackutils.IsGitStack(stack) { + if stackutils.IsRelativePathStack(stack) { return handler.StackDeployer.StopRemoteSwarmStack(stack, endpoint) } diff --git a/api/stacks/deployments/deploy.go b/api/stacks/deployments/deploy.go index 8f2708415..491074ec4 100644 --- a/api/stacks/deployments/deploy.go +++ b/api/stacks/deployments/deploy.go @@ -85,7 +85,7 @@ func RedeployWhenChanged(stackID portainer.StackID, deployer StackDeployer, data switch stack.Type { case portainer.DockerComposeStack: - if stackutils.IsGitStack(stack) { + if stackutils.IsRelativePathStack(stack) { err = deployer.DeployRemoteComposeStack(stack, endpoint, registries, true, false) } else { err = deployer.DeployComposeStack(stack, endpoint, registries, true, false) @@ -95,7 +95,7 @@ func RedeployWhenChanged(stackID portainer.StackID, deployer StackDeployer, data return errors.WithMessagef(err, "failed to deploy a docker compose stack %v", stackID) } case portainer.DockerSwarmStack: - if stackutils.IsGitStack(stack) { + if stackutils.IsRelativePathStack(stack) { err = deployer.DeployRemoteSwarmStack(stack, endpoint, registries, true, true) } else { err = deployer.DeploySwarmStack(stack, endpoint, registries, true, true) diff --git a/api/stacks/deployments/deployment_compose_config.go b/api/stacks/deployments/deployment_compose_config.go index 8785a7590..199928a87 100644 --- a/api/stacks/deployments/deployment_compose_config.go +++ b/api/stacks/deployments/deployment_compose_config.go @@ -84,7 +84,7 @@ func (config *ComposeStackDeploymentConfig) Deploy() error { return err } } - if stackutils.IsGitStack(config.stack) { + if stackutils.IsRelativePathStack(config.stack) { return config.StackDeployer.DeployRemoteComposeStack(config.stack, config.endpoint, config.registries, config.forcePullImage, config.ForceCreate) } diff --git a/api/stacks/deployments/deployment_swarm_config.go b/api/stacks/deployments/deployment_swarm_config.go index 872f392d1..da0c6b8c1 100644 --- a/api/stacks/deployments/deployment_swarm_config.go +++ b/api/stacks/deployments/deployment_swarm_config.go @@ -78,7 +78,7 @@ func (config *SwarmStackDeploymentConfig) Deploy() error { } } - if stackutils.IsGitStack(config.stack) { + if stackutils.IsRelativePathStack(config.stack) { return config.StackDeployer.DeployRemoteSwarmStack(config.stack, config.endpoint, config.registries, config.prune, config.pullImage) } diff --git a/api/stacks/stackutils/util.go b/api/stacks/stackutils/util.go index a371e0ad0..91c9d464f 100644 --- a/api/stacks/stackutils/util.go +++ b/api/stacks/stackutils/util.go @@ -47,3 +47,10 @@ func SanitizeLabel(value string) string { func IsGitStack(stack *portainer.Stack) bool { return stack.GitConfig != nil && len(stack.GitConfig.URL) != 0 } + +// IsRelativePathStack checks if the stack is a git stack or not +func IsRelativePathStack(stack *portainer.Stack) bool { + // Always return false in CE + // This function is only for code consistency with EE + return false +}