Skip to content

Commit f93c807

Browse files
hookenzChaim Lev-Ari
authored andcommitted
use docker run to deploy stack for agent upgrade
1 parent 304c4e0 commit f93c807

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

edge/stack/stack.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,14 @@ func (manager *StackManager) performActionOnStack(queueSleepInterval time.Durati
358358
}
359359
}
360360

361+
agentUpgrade := stack.EdgeUpdateID != 0
362+
if agentUpgrade {
363+
stack.EnvVars = append(stack.EnvVars, portainer.Pair{
364+
Name: "_agentUpgrade",
365+
Value: "true",
366+
})
367+
}
368+
361369
manager.deployStack(ctx, stack, stackName, stackFileLocation)
362370
case actionDelete:
363371
stackFileLocation = fmt.Sprintf("%s/%s", SuccessStackFileFolder(stack.FileFolder), stack.FileName)

exec/docker_compose_stack.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package exec
22

33
import (
44
"context"
5+
"slices"
56

67
"github.com/portainer/agent"
78
libstack "github.com/portainer/portainer/pkg/libstack"
89
"github.com/portainer/portainer/pkg/libstack/compose"
10+
"github.com/rs/zerolog/log"
911
)
1012

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

3133
// Deploy executes the docker stack deploy command.
3234
func (service *DockerComposeStackService) Deploy(ctx context.Context, name string, filePaths []string, options agent.DeployOptions) error {
35+
36+
// TODO: this should probably be implemented as an edge job in future.
37+
agentUpgrade := slices.Contains(options.Env, "_agentUpgrade")
38+
if agentUpgrade {
39+
log.Debug().Msgf("Detected portainer agent upgrade")
40+
return service.deployer.Run(ctx, filePaths, "updater", libstack.RunOptions{
41+
Options: libstack.Options{
42+
ProjectName: name,
43+
WorkingDir: options.WorkingDir,
44+
Env: options.Env,
45+
},
46+
})
47+
}
48+
3349
return service.deployer.Deploy(ctx, filePaths, libstack.DeployOptions{
3450
Options: libstack.Options{
3551
ProjectName: name,

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/mitchellh/mapstructure v1.5.0
2525
github.com/opencontainers/image-spec v1.1.0-rc5
2626
github.com/pkg/errors v0.9.1
27-
github.com/portainer/portainer v0.6.1-0.20240116212059-47f29002f0dc
27+
github.com/portainer/portainer v0.6.1-0.20240117161906-171b42d11821
2828
github.com/rs/zerolog v1.29.0
2929
github.com/wI2L/jsondiff v0.2.0
3030
gopkg.in/alecthomas/kingpin.v2 v2.2.6

go.sum

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
277277
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
278278
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
279279
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
280-
github.com/portainer/portainer v0.6.1-0.20240112073152-f9c0a1c26b72 h1:3grxIEsc2GPBXZga6tA5P0dTjHGFUiE5rKvnV6+kB3I=
281-
github.com/portainer/portainer v0.6.1-0.20240112073152-f9c0a1c26b72/go.mod h1:4sPWxbrwbD8T+W4EEwRWPTq8goN8n3ntlQm6AmZC+XA=
282-
github.com/portainer/portainer v0.6.1-0.20240115043120-17c6eb6d423a h1:AUNvx2+hfvm5TEk1UBiK4zfqM7x5lyRNh1nWKUE8nn4=
283-
github.com/portainer/portainer v0.6.1-0.20240115043120-17c6eb6d423a/go.mod h1:4sPWxbrwbD8T+W4EEwRWPTq8goN8n3ntlQm6AmZC+XA=
284-
github.com/portainer/portainer v0.6.1-0.20240116212059-47f29002f0dc h1:6E+0WPzNvCVLdtvqHvrIQEYI2CwLxhgzusu8TKXji6Q=
285-
github.com/portainer/portainer v0.6.1-0.20240116212059-47f29002f0dc/go.mod h1:4sPWxbrwbD8T+W4EEwRWPTq8goN8n3ntlQm6AmZC+XA=
280+
github.com/portainer/portainer v0.6.1-0.20240117161906-171b42d11821 h1:HfwxvbVbPgeme4CLKNUwqfb6OwZyHC1hWoKCBCILRio=
281+
github.com/portainer/portainer v0.6.1-0.20240117161906-171b42d11821/go.mod h1:4sPWxbrwbD8T+W4EEwRWPTq8goN8n3ntlQm6AmZC+XA=
286282
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
287283
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
288284
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=

0 commit comments

Comments
 (0)