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 committed Jan 11, 2024
1 parent 222d923 commit a0af919
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 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
4 changes: 2 additions & 2 deletions 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.20231227185441-27e997fe0d1e
github.com/portainer/portainer v0.6.1-0.20240109020621-68dddbabbfaa
github.com/rs/zerolog v1.29.0
github.com/wI2L/jsondiff v0.2.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
Expand Down Expand Up @@ -116,7 +116,7 @@ require (
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.16.1 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.32.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +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.20231227185441-27e997fe0d1e h1:XWtJUsjPDJ8F2SsYBrPT+M9bleZG3wZx652jzCEB+zo=
github.com/portainer/portainer v0.6.1-0.20231227185441-27e997fe0d1e/go.mod h1:73Zf/oSGvxq8/u0AdmXGWwyiUytLz3LbUygJF3KjgmM=
github.com/portainer/portainer v0.6.1-0.20240109020621-68dddbabbfaa h1:1Khny+FwWWEkY8DYDBeHDCrRuoWlMMxtoQIZ52R22xM=
github.com/portainer/portainer v0.6.1-0.20240109020621-68dddbabbfaa/go.mod h1:L+FcDxUE5tztHmIZd8rCeuPwI15IOPgj7RXRSXTDiks=
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 Expand Up @@ -419,8 +419,8 @@ golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.1.0 h1:xYY+Bajn2a7VBmTM5GikTmnK8ZuX8YgnQCqZpbBNtmA=
golang.org/x/time v0.1.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
Expand Down

0 comments on commit a0af919

Please sign in to comment.