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>
This commit is contained in:
ChristopherHX 2023-05-03 19:49:17 +02:00 committed by GitHub
parent 568124ca69
commit ca9b783491
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 {
@ -474,7 +475,7 @@ 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()
@ -482,6 +483,12 @@ func (rc *RunContext) platformImage(ctx context.Context) string {
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())
}
@ -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()