diff --git a/.gitignore b/.gitignore index 5fc404e57..1eac33901 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -dist +dist* .tmp .idea /.vscode/ diff --git a/agent.go b/agent.go index 40afe7ef5..8f564bb91 100644 --- a/agent.go +++ b/agent.go @@ -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 { diff --git a/edge/stack/stack.go b/edge/stack/stack.go index a55be13f0..3ecfe11bb 100644 --- a/edge/stack/stack.go +++ b/edge/stack/stack.go @@ -567,6 +567,11 @@ 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{ @@ -574,6 +579,7 @@ func (manager *StackManager) deployStack(ctx context.Context, stack *edgeStack, WorkingDir: stack.FileFolder, Env: envVars, }, + Task: task, }, ) diff --git a/exec/docker_compose_stack.go b/exec/docker_compose_stack.go index deaf33770..899a4a65c 100644 --- a/exec/docker_compose_stack.go +++ b/exec/docker_compose_stack.go @@ -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. @@ -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, diff --git a/go.mod b/go.mod index bcf26989c..a9f16de68 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 63c6fb210..aaa512e64 100644 --- a/go.sum +++ b/go.sum @@ -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=