Support intepolation for env of services (#47)

Reviewed-on: https://gitea.com/gitea/act/pulls/47
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Zettat123 <zettat123@gmail.com>
Co-committed-by: Zettat123 <zettat123@gmail.com>
This commit is contained in:
Zettat123 2023-04-20 16:24:31 +08:00 committed by Lunny Xiao
parent 8609522aa4
commit e12252a43a

View file

@ -246,9 +246,13 @@ func (rc *RunContext) startJobContainer() common.Executor {
// add service containers
for name, spec := range rc.Run.Job().Services {
mergedEnv := envList
interpolatedEnvs := make(map[string]string, len(spec.Env))
for k, v := range spec.Env {
mergedEnv = append(mergedEnv, fmt.Sprintf("%s=%s", k, v))
interpolatedEnvs[k] = rc.ExprEval.Interpolate(ctx, v)
}
envs := make([]string, 0, len(interpolatedEnvs))
for k, v := range interpolatedEnvs {
envs = append(envs, fmt.Sprintf("%s=%s", k, v))
}
serviceContainerName := createSimpleContainerName(rc.jobContainerName(), name)
c := container.NewContainer(&container.NewContainerInput{
@ -257,7 +261,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
Image: spec.Image,
Username: username,
Password: password,
Env: mergedEnv,
Env: envs,
Mounts: map[string]string{
// TODO merge volumes
name: ext.ToContainerPath(rc.Config.Workdir),