Skip to content

Commit

Permalink
fix: don't allow -self-hosted mode as container image (#1783)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ChristopherHX and mergify[bot] committed May 3, 2023
1 parent 568124c commit ca9b783
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions pkg/runner/run_context.go
Expand Up @@ -420,8 +420,9 @@ func (rc *RunContext) startContainer() common.Executor {
}

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

func (rc *RunContext) stopContainer() common.Executor {
Expand Down Expand Up @@ -474,14 +475,20 @@ func (rc *RunContext) Executor() common.Executor {
}
}

func (rc *RunContext) platformImage(ctx context.Context) string {
func (rc *RunContext) containerImage(ctx context.Context) string {
job := rc.Run.Job()

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

return ""
}

func (rc *RunContext) runsOnImage(ctx context.Context) string {
job := rc.Run.Job()

if job.RunsOn() == nil {
common.Logger(ctx).Errorf("'runs-on' key not defined in %s", rc.String())
}
Expand All @@ -497,6 +504,14 @@ func (rc *RunContext) platformImage(ctx context.Context) string {
return ""
}

func (rc *RunContext) platformImage(ctx context.Context) string {
if containerImage := rc.containerImage(ctx); containerImage != "" {
return containerImage
}

return rc.runsOnImage(ctx)
}

func (rc *RunContext) options(ctx context.Context) string {
job := rc.Run.Job()
c := job.Container()
Expand Down

0 comments on commit ca9b783

Please sign in to comment.