Skip to content

Commit 240b826

Browse files
author
Chaim Lev-Ari
committed
refactor(stack): deploy tasks
1 parent f93c807 commit 240b826

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
dist
1+
dist*
22
.tmp
33
.idea
44
/.vscode/

agent.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ type (
211211
DeployOptions struct {
212212
DeployerBaseOptions
213213
Prune bool
214+
// Task is the name of the short lived task to deploy, if non empty will run the service as a task
215+
// (docker compose will be run with `run --rm` instead of `up`)
216+
Task string
214217
}
215218

216219
RemoveOptions struct {

edge/stack/stack.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,6 @@ 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-
369361
manager.deployStack(ctx, stack, stackName, stackFileLocation)
370362
case actionDelete:
371363
stackFileLocation = fmt.Sprintf("%s/%s", SuccessStackFileFolder(stack.FileFolder), stack.FileName)
@@ -575,13 +567,19 @@ func (manager *StackManager) deployStack(ctx context.Context, stack *edgeStack,
575567

576568
envVars := buildEnvVarsForDeployer(stack.EnvVars)
577569

570+
task := ""
571+
if stack.EdgeUpdateID != 0 {
572+
task = "updater"
573+
}
574+
578575
err = manager.deployer.Deploy(ctx, stackName, []string{stackFileLocation},
579576
agent.DeployOptions{
580577
DeployerBaseOptions: agent.DeployerBaseOptions{
581578
Namespace: stack.Namespace,
582579
WorkingDir: stack.FileFolder,
583580
Env: envVars,
584581
},
582+
Task: task,
585583
},
586584
)
587585

exec/docker_compose_stack.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package exec
22

33
import (
44
"context"
5-
"slices"
65

76
"github.com/portainer/agent"
87
libstack "github.com/portainer/portainer/pkg/libstack"
@@ -33,16 +32,18 @@ func NewDockerComposeStackService(binaryPath string) (*DockerComposeStackService
3332
// Deploy executes the docker stack deploy command.
3433
func (service *DockerComposeStackService) Deploy(ctx context.Context, name string, filePaths []string, options agent.DeployOptions) error {
3534

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{
35+
if options.Task != "" {
36+
log.Debug().
37+
Str("task name", options.Task).
38+
Msg("Detected short lived task run")
39+
40+
return service.deployer.Run(ctx, filePaths, options.Task, libstack.RunOptions{
4141
Options: libstack.Options{
4242
ProjectName: name,
4343
WorkingDir: options.WorkingDir,
4444
Env: options.Env,
4545
},
46+
Remove: true,
4647
})
4748
}
4849

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,5 @@ require (
133133
)
134134

135135
replace github.com/jaguilar/vt100 => github.com/tonistiigi/vt100 v0.0.0-20190402012908-ad4c4a574305
136+
137+
replace github.com/portainer/portainer => ../portainer

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,6 @@ 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.20240117161906-171b42d11821 h1:HfwxvbVbPgeme4CLKNUwqfb6OwZyHC1hWoKCBCILRio=
281-
github.com/portainer/portainer v0.6.1-0.20240117161906-171b42d11821/go.mod h1:4sPWxbrwbD8T+W4EEwRWPTq8goN8n3ntlQm6AmZC+XA=
282280
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
283281
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
284282
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=

0 commit comments

Comments
 (0)