diff --git a/pkg/container/docker_run.go b/pkg/container/docker_run.go index 896a269..add0e2e 100644 --- a/pkg/container/docker_run.go +++ b/pkg/container/docker_run.go @@ -57,6 +57,8 @@ type NewContainerInput struct { UsernsMode string Platform string Options string + + AutoRemove bool } // FileEntry is a file to copy to a container @@ -475,6 +477,7 @@ func (cr *containerReference) create(capAdd []string, capDrop []string) common.E NetworkMode: container.NetworkMode(input.NetworkMode), Privileged: input.Privileged, UsernsMode: container.UsernsMode(input.UsernsMode), + AutoRemove: input.AutoRemove, } logger.Debugf("Common container.HostConfig ==> %+v", hostConfig) diff --git a/pkg/runner/action.go b/pkg/runner/action.go index 2dee988..275de09 100644 --- a/pkg/runner/action.go +++ b/pkg/runner/action.go @@ -366,6 +366,7 @@ func newStepContainer(ctx context.Context, step step, image string, cmd []string Privileged: rc.Config.Privileged, UsernsMode: rc.Config.UsernsMode, Platform: rc.Config.ContainerArchitecture, + AutoRemove: rc.Config.AutoRemove, }) return stepContainer } diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 74469bb..86e59a4 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -9,6 +9,7 @@ import ( "regexp" "runtime" "strings" + "time" "github.com/mitchellh/go-homedir" "github.com/opencontainers/selinux/go-selinux" @@ -150,7 +151,7 @@ func (rc *RunContext) startJobContainer() common.Executor { rc.JobContainer = container.NewContainer(&container.NewContainerInput{ Cmd: nil, - Entrypoint: []string{"/usr/bin/tail", "-f", "/dev/null"}, + Entrypoint: []string{"/bin/sleep", fmt.Sprint(rc.Config.ContainerMaxLifetime.Round(time.Second).Seconds())}, WorkingDir: rc.Config.ContainerWorkdir(), Image: image, Username: username, @@ -158,7 +159,7 @@ func (rc *RunContext) startJobContainer() common.Executor { Name: name, Env: envList, Mounts: mounts, - NetworkMode: "host", + NetworkMode: rc.Config.ContainerNetworkMode, Binds: binds, Stdout: logWriter, Stderr: logWriter, @@ -166,6 +167,7 @@ func (rc *RunContext) startJobContainer() common.Executor { UsernsMode: rc.Config.UsernsMode, Platform: rc.Config.ContainerArchitecture, Options: rc.options(ctx), + AutoRemove: rc.Config.AutoRemove, }) return common.NewPipelineExecutor( diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index b0b74ad..c36fec4 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -59,6 +59,8 @@ type Config struct { PresetGitHubContext *model.GithubContext // the preset github context, overrides some fields like DefaultBranch, Env, Secrets etc. EventJSON string // the content of JSON file to use for event.json in containers, overrides EventPath ContainerNamePrefix string // the prefix of container name + ContainerMaxLifetime time.Duration // the max lifetime of job containers + ContainerNetworkMode string // the network mode of job containers DefaultActionInstance string // the default actions web site } diff --git a/pkg/runner/step_docker.go b/pkg/runner/step_docker.go index 4ac3b27..b51da53 100644 --- a/pkg/runner/step_docker.go +++ b/pkg/runner/step_docker.go @@ -130,6 +130,7 @@ func (sd *stepDocker) newStepContainer(ctx context.Context, image string, cmd [] Privileged: rc.Config.Privileged, UsernsMode: rc.Config.UsernsMode, Platform: rc.Config.ContainerArchitecture, + AutoRemove: rc.Config.AutoRemove, }) return stepContainer }