Support specifying command for services (#50)

This PR is to support overwriting the default `CMD` command of `services` containers.

This is a Gitea specific feature and GitHub Actions doesn't support this syntax.

Reviewed-on: https://gitea.com/gitea/act/pulls/50
Reviewed-by: Jason Song <i@wolfogre.com>
Co-authored-by: Zettat123 <zettat123@gmail.com>
Co-committed-by: Zettat123 <zettat123@gmail.com>
This commit is contained in:
Zettat123 2023-04-23 14:55:17 +08:00 committed by Jason Song
parent 721857e4a0
commit 0c1f2edb99
3 changed files with 11 additions and 0 deletions

View file

@ -168,6 +168,7 @@ type ContainerSpec struct {
Volumes []string `yaml:"volumes,omitempty"` Volumes []string `yaml:"volumes,omitempty"`
Options string `yaml:"options,omitempty"` Options string `yaml:"options,omitempty"`
Credentials map[string]string `yaml:"credentials,omitempty"` Credentials map[string]string `yaml:"credentials,omitempty"`
Cmd []string `yaml:"cmd,omitempty"`
} }
type Strategy struct { type Strategy struct {

View file

@ -522,6 +522,9 @@ type ContainerSpec struct {
Args string Args string
Name string Name string
Reuse bool Reuse bool
// Gitea specific
Cmd []string `yaml:"cmd"`
} }
// Step is the structure of one step in a job // Step is the structure of one step in a job

View file

@ -246,6 +246,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
// add service containers // add service containers
for name, spec := range rc.Run.Job().Services { for name, spec := range rc.Run.Job().Services {
// interpolate env
interpolatedEnvs := make(map[string]string, len(spec.Env)) interpolatedEnvs := make(map[string]string, len(spec.Env))
for k, v := range spec.Env { for k, v := range spec.Env {
interpolatedEnvs[k] = rc.ExprEval.Interpolate(ctx, v) interpolatedEnvs[k] = rc.ExprEval.Interpolate(ctx, v)
@ -254,6 +255,11 @@ func (rc *RunContext) startJobContainer() common.Executor {
for k, v := range interpolatedEnvs { for k, v := range interpolatedEnvs {
envs = append(envs, fmt.Sprintf("%s=%s", k, v)) envs = append(envs, fmt.Sprintf("%s=%s", k, v))
} }
// interpolate cmd
interpolatedCmd := make([]string, 0, len(spec.Cmd))
for _, v := range spec.Cmd {
interpolatedCmd = append(interpolatedCmd, rc.ExprEval.Interpolate(ctx, v))
}
serviceContainerName := createSimpleContainerName(rc.jobContainerName(), name) serviceContainerName := createSimpleContainerName(rc.jobContainerName(), name)
c := container.NewContainer(&container.NewContainerInput{ c := container.NewContainer(&container.NewContainerInput{
Name: serviceContainerName, Name: serviceContainerName,
@ -261,6 +267,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
Image: spec.Image, Image: spec.Image,
Username: username, Username: username,
Password: password, Password: password,
Cmd: interpolatedCmd,
Env: envs, Env: envs,
Mounts: map[string]string{ Mounts: map[string]string{
// TODO merge volumes // TODO merge volumes