Skip to content

Commit

Permalink
use docker run to deploy stack for agent upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
hookenz authored and Chaim Lev-Ari committed Jan 17, 2024
1 parent 304c4e0 commit f93c807
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
8 changes: 8 additions & 0 deletions edge/stack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ func (manager *StackManager) performActionOnStack(queueSleepInterval time.Durati
}
}

agentUpgrade := stack.EdgeUpdateID != 0
if agentUpgrade {
stack.EnvVars = append(stack.EnvVars, portainer.Pair{
Name: "_agentUpgrade",
Value: "true",
})
}

manager.deployStack(ctx, stack, stackName, stackFileLocation)
case actionDelete:
stackFileLocation = fmt.Sprintf("%s/%s", SuccessStackFileFolder(stack.FileFolder), stack.FileName)
Expand Down
16 changes: 16 additions & 0 deletions exec/docker_compose_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package exec

import (
"context"
"slices"

"github.com/portainer/agent"
libstack "github.com/portainer/portainer/pkg/libstack"
"github.com/portainer/portainer/pkg/libstack/compose"
"github.com/rs/zerolog/log"
)

// DockerComposeStackService represents a service for managing stacks by using the Docker binary.
Expand All @@ -30,6 +32,20 @@ func NewDockerComposeStackService(binaryPath string) (*DockerComposeStackService

// Deploy executes the docker stack deploy command.
func (service *DockerComposeStackService) Deploy(ctx context.Context, name string, filePaths []string, options agent.DeployOptions) error {

// TODO: this should probably be implemented as an edge job in future.
agentUpgrade := slices.Contains(options.Env, "_agentUpgrade")
if agentUpgrade {
log.Debug().Msgf("Detected portainer agent upgrade")
return service.deployer.Run(ctx, filePaths, "updater", libstack.RunOptions{
Options: libstack.Options{
ProjectName: name,
WorkingDir: options.WorkingDir,
Env: options.Env,
},
})
}

return service.deployer.Deploy(ctx, filePaths, libstack.DeployOptions{
Options: libstack.Options{
ProjectName: name,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/opencontainers/image-spec v1.1.0-rc5
github.com/pkg/errors v0.9.1
github.com/portainer/portainer v0.6.1-0.20240116212059-47f29002f0dc
github.com/portainer/portainer v0.6.1-0.20240117161906-171b42d11821
github.com/rs/zerolog v1.29.0
github.com/wI2L/jsondiff v0.2.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/portainer/portainer v0.6.1-0.20240112073152-f9c0a1c26b72 h1:3grxIEsc2GPBXZga6tA5P0dTjHGFUiE5rKvnV6+kB3I=
github.com/portainer/portainer v0.6.1-0.20240112073152-f9c0a1c26b72/go.mod h1:4sPWxbrwbD8T+W4EEwRWPTq8goN8n3ntlQm6AmZC+XA=
github.com/portainer/portainer v0.6.1-0.20240115043120-17c6eb6d423a h1:AUNvx2+hfvm5TEk1UBiK4zfqM7x5lyRNh1nWKUE8nn4=
github.com/portainer/portainer v0.6.1-0.20240115043120-17c6eb6d423a/go.mod h1:4sPWxbrwbD8T+W4EEwRWPTq8goN8n3ntlQm6AmZC+XA=
github.com/portainer/portainer v0.6.1-0.20240116212059-47f29002f0dc h1:6E+0WPzNvCVLdtvqHvrIQEYI2CwLxhgzusu8TKXji6Q=
github.com/portainer/portainer v0.6.1-0.20240116212059-47f29002f0dc/go.mod h1:4sPWxbrwbD8T+W4EEwRWPTq8goN8n3ntlQm6AmZC+XA=
github.com/portainer/portainer v0.6.1-0.20240117161906-171b42d11821 h1:HfwxvbVbPgeme4CLKNUwqfb6OwZyHC1hWoKCBCILRio=
github.com/portainer/portainer v0.6.1-0.20240117161906-171b42d11821/go.mod h1:4sPWxbrwbD8T+W4EEwRWPTq8goN8n3ntlQm6AmZC+XA=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
Expand Down

0 comments on commit f93c807

Please sign in to comment.