mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-06-22 01:34:25 +02:00
fix: Interpolate job container.volume (#1036)
Interpolate job container.volumes in GetBindsAndMounts(), matching service container volumes and other container fields (image, options).
Fixes expressions like ${{ secrets.MAME }}:/path:ro being passed literally and rejected as invalid bind mounts
Reviewed-on: https://gitea.com/gitea/runner/pulls/1036
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
@@ -189,6 +189,9 @@ func (rc *RunContext) GetBindsAndMounts() ([]string, map[string]string) {
|
|||||||
if job := rc.Run.Job(); job != nil {
|
if job := rc.Run.Job(); job != nil {
|
||||||
if container := job.Container(); container != nil {
|
if container := job.Container(); container != nil {
|
||||||
for _, v := range container.Volumes {
|
for _, v := range container.Volumes {
|
||||||
|
if rc.ExprEval != nil {
|
||||||
|
v = rc.ExprEval.Interpolate(context.Background(), v)
|
||||||
|
}
|
||||||
if !strings.Contains(v, ":") || filepath.IsAbs(v) {
|
if !strings.Contains(v, ":") || filepath.IsAbs(v) {
|
||||||
// Bind anonymous volume or host file.
|
// Bind anonymous volume or host file.
|
||||||
binds = append(binds, v)
|
binds = append(binds, v)
|
||||||
|
|||||||
@@ -276,6 +276,37 @@ func TestRunContext_GetBindsAndMounts(t *testing.T) {
|
|||||||
{"MountExistingVolume", []string{"volume-id:/volume"}, "", map[string]string{"volume-id": "/volume"}},
|
{"MountExistingVolume", []string{"volume-id:/volume"}, "", map[string]string{"volume-id": "/volume"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Run("InterpolatedContainerVolumes", func(t *testing.T) {
|
||||||
|
job := &model.Job{}
|
||||||
|
err := job.RawContainer.Encode(map[string][]string{
|
||||||
|
"volumes": {"${{ secrets.MAME }}:/root/.mame/roms:ro"},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
rc := &RunContext{
|
||||||
|
Name: "TestRCName",
|
||||||
|
Run: &model.Run{
|
||||||
|
Workflow: &model.Workflow{
|
||||||
|
Name: "TestWorkflowName",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Config: &Config{
|
||||||
|
BindWorkdir: false,
|
||||||
|
Secrets: map[string]string{
|
||||||
|
"MAME": "/host/mame/roms",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
rc.Run.JobID = "job1"
|
||||||
|
rc.Run.Workflow.Jobs = map[string]*model.Job{"job1": job}
|
||||||
|
rc.ExprEval = rc.NewExpressionEvaluator(context.Background())
|
||||||
|
|
||||||
|
gotbind, gotmount := rc.GetBindsAndMounts()
|
||||||
|
assert.Contains(t, gotbind, "/host/mame/roms:/root/.mame/roms:ro")
|
||||||
|
assert.NotContains(t, gotbind, "${{ secrets.MAME }}")
|
||||||
|
assert.NotContains(t, gotmount, "${{ secrets.MAME }}")
|
||||||
|
})
|
||||||
|
|
||||||
for _, testcase := range tests {
|
for _, testcase := range tests {
|
||||||
t.Run(testcase.name, func(t *testing.T) {
|
t.Run(testcase.name, func(t *testing.T) {
|
||||||
job := &model.Job{}
|
job := &model.Job{}
|
||||||
|
|||||||
Reference in New Issue
Block a user