Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(edge-stacks): run updater as a short lived task [EE-6454] #564

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dist
dist*
.tmp
.idea
/.vscode/
Expand Down
3 changes: 3 additions & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ type (
DeployOptions struct {
DeployerBaseOptions
Prune bool
// Task is the name of the short lived task to deploy, if non empty will run the service as a task
// (docker compose will be run with `run --rm` instead of `up`)
Task string
}

RemoveOptions struct {
Expand Down
6 changes: 6 additions & 0 deletions edge/stack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,13 +567,19 @@ func (manager *StackManager) deployStack(ctx context.Context, stack *edgeStack,

envVars := buildEnvVarsForDeployer(stack.EnvVars)

task := ""
if stack.EdgeUpdateID != 0 {
task = "updater"
}

err = manager.deployer.Deploy(ctx, stackName, []string{stackFileLocation},
agent.DeployOptions{
DeployerBaseOptions: agent.DeployerBaseOptions{
Namespace: stack.Namespace,
WorkingDir: stack.FileFolder,
Env: envVars,
},
Task: task,
},
)

Expand Down
17 changes: 17 additions & 0 deletions exec/docker_compose_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"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 +31,22 @@ 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 {

if options.Task != "" {
log.Debug().
Str("task name", options.Task).
Msg("Detected short lived task run")

return service.deployer.Run(ctx, filePaths, options.Task, libstack.RunOptions{
Options: libstack.Options{
ProjectName: name,
WorkingDir: options.WorkingDir,
Env: options.Env,
},
Remove: true,
})
}

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.20240123081012-ff330ccf4005
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.20240123081012-ff330ccf4005 h1:PyeHnran8CY88LRCpOpNP/GZWJzTOu7brz7Cf3pblOo=
github.com/portainer/portainer v0.6.1-0.20240123081012-ff330ccf4005/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