feat: support more options of containers

This commit is contained in:
Jason Song 2022-11-18 16:09:51 +08:00 committed by Jason Song
parent 97629ae8af
commit b9c20dcaa4
No known key found for this signature in database
GPG key ID: 8402EEEE4511A8B5
5 changed files with 11 additions and 2 deletions

View file

@ -57,6 +57,8 @@ type NewContainerInput struct {
UsernsMode string UsernsMode string
Platform string Platform string
Options string Options string
AutoRemove bool
} }
// FileEntry is a file to copy to a container // 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), NetworkMode: container.NetworkMode(input.NetworkMode),
Privileged: input.Privileged, Privileged: input.Privileged,
UsernsMode: container.UsernsMode(input.UsernsMode), UsernsMode: container.UsernsMode(input.UsernsMode),
AutoRemove: input.AutoRemove,
} }
logger.Debugf("Common container.HostConfig ==> %+v", hostConfig) logger.Debugf("Common container.HostConfig ==> %+v", hostConfig)

View file

@ -366,6 +366,7 @@ func newStepContainer(ctx context.Context, step step, image string, cmd []string
Privileged: rc.Config.Privileged, Privileged: rc.Config.Privileged,
UsernsMode: rc.Config.UsernsMode, UsernsMode: rc.Config.UsernsMode,
Platform: rc.Config.ContainerArchitecture, Platform: rc.Config.ContainerArchitecture,
AutoRemove: rc.Config.AutoRemove,
}) })
return stepContainer return stepContainer
} }

View file

@ -9,6 +9,7 @@ import (
"regexp" "regexp"
"runtime" "runtime"
"strings" "strings"
"time"
"github.com/mitchellh/go-homedir" "github.com/mitchellh/go-homedir"
"github.com/opencontainers/selinux/go-selinux" "github.com/opencontainers/selinux/go-selinux"
@ -150,7 +151,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
rc.JobContainer = container.NewContainer(&container.NewContainerInput{ rc.JobContainer = container.NewContainer(&container.NewContainerInput{
Cmd: nil, 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(), WorkingDir: rc.Config.ContainerWorkdir(),
Image: image, Image: image,
Username: username, Username: username,
@ -158,7 +159,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
Name: name, Name: name,
Env: envList, Env: envList,
Mounts: mounts, Mounts: mounts,
NetworkMode: "host", NetworkMode: rc.Config.ContainerNetworkMode,
Binds: binds, Binds: binds,
Stdout: logWriter, Stdout: logWriter,
Stderr: logWriter, Stderr: logWriter,
@ -166,6 +167,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
UsernsMode: rc.Config.UsernsMode, UsernsMode: rc.Config.UsernsMode,
Platform: rc.Config.ContainerArchitecture, Platform: rc.Config.ContainerArchitecture,
Options: rc.options(ctx), Options: rc.options(ctx),
AutoRemove: rc.Config.AutoRemove,
}) })
return common.NewPipelineExecutor( return common.NewPipelineExecutor(

View file

@ -59,6 +59,8 @@ type Config struct {
PresetGitHubContext *model.GithubContext // the preset github context, overrides some fields like DefaultBranch, Env, Secrets etc. 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 EventJSON string // the content of JSON file to use for event.json in containers, overrides EventPath
ContainerNamePrefix string // the prefix of container name 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 DefaultActionInstance string // the default actions web site
} }

View file

@ -130,6 +130,7 @@ func (sd *stepDocker) newStepContainer(ctx context.Context, image string, cmd []
Privileged: rc.Config.Privileged, Privileged: rc.Config.Privileged,
UsernsMode: rc.Config.UsernsMode, UsernsMode: rc.Config.UsernsMode,
Platform: rc.Config.ContainerArchitecture, Platform: rc.Config.ContainerArchitecture,
AutoRemove: rc.Config.AutoRemove,
}) })
return stepContainer return stepContainer
} }