Skip to content

Commit ca9b783

Browse files
fix: don't allow -self-hosted mode as container image (#1783)
* fix: don't allow `-self-hosted` mode as container image * fix: jobcontainer in hostmode platform * Update run_context.go --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 568124c commit ca9b783

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

pkg/runner/run_context.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,9 @@ func (rc *RunContext) startContainer() common.Executor {
420420
}
421421

422422
func (rc *RunContext) IsHostEnv(ctx context.Context) bool {
423-
image := rc.platformImage(ctx)
424-
return strings.EqualFold(image, "-self-hosted")
423+
platform := rc.runsOnImage(ctx)
424+
image := rc.containerImage(ctx)
425+
return image == "" && strings.EqualFold(platform, "-self-hosted")
425426
}
426427

427428
func (rc *RunContext) stopContainer() common.Executor {
@@ -474,14 +475,20 @@ func (rc *RunContext) Executor() common.Executor {
474475
}
475476
}
476477

477-
func (rc *RunContext) platformImage(ctx context.Context) string {
478+
func (rc *RunContext) containerImage(ctx context.Context) string {
478479
job := rc.Run.Job()
479480

480481
c := job.Container()
481482
if c != nil {
482483
return rc.ExprEval.Interpolate(ctx, c.Image)
483484
}
484485

486+
return ""
487+
}
488+
489+
func (rc *RunContext) runsOnImage(ctx context.Context) string {
490+
job := rc.Run.Job()
491+
485492
if job.RunsOn() == nil {
486493
common.Logger(ctx).Errorf("'runs-on' key not defined in %s", rc.String())
487494
}
@@ -497,6 +504,14 @@ func (rc *RunContext) platformImage(ctx context.Context) string {
497504
return ""
498505
}
499506

507+
func (rc *RunContext) platformImage(ctx context.Context) string {
508+
if containerImage := rc.containerImage(ctx); containerImage != "" {
509+
return containerImage
510+
}
511+
512+
return rc.runsOnImage(ctx)
513+
}
514+
500515
func (rc *RunContext) options(ctx context.Context) string {
501516
job := rc.Run.Job()
502517
c := job.Container()

0 commit comments

Comments
 (0)