1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

fix: support docker create arguments from container.options (#1022) (#1351)

* fix: support docker create arguments from container.options (#1022)

* fix processing of errors, add verbose logging, fix test

* disable linter for code copied from docker/cli

* fix all linter issues

* Add license info

* Add opts_test.go from docker/cli and required testdata

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Alex Savchuk 2022-10-07 01:09:43 +03:00 committed by GitHub
parent f1bc70aee7
commit 658b6fdbf8
15 changed files with 2327 additions and 32 deletions

View file

@ -10,11 +10,9 @@ import (
"runtime"
"strings"
"github.com/kballard/go-shellquote"
"github.com/mitchellh/go-homedir"
"github.com/opencontainers/selinux/go-selinux"
log "github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/nektos/act/pkg/common"
"github.com/nektos/act/pkg/common/git"
@ -123,7 +121,6 @@ func (rc *RunContext) startJobContainer() common.Executor {
return func(ctx context.Context) error {
logger := common.Logger(ctx)
image := rc.platformImage(ctx)
hostname := rc.hostname(ctx)
rawLogger := logger.WithField("raw_output", true)
logWriter := common.NewLineWriter(rc.commandHandler(ctx), func(s string) bool {
if rc.Config.LogOutput {
@ -168,7 +165,7 @@ func (rc *RunContext) startJobContainer() common.Executor {
Privileged: rc.Config.Privileged,
UsernsMode: rc.Config.UsernsMode,
Platform: rc.Config.ContainerArchitecture,
Hostname: hostname,
Options: rc.options(ctx),
})
return common.NewPipelineExecutor(
@ -311,27 +308,14 @@ func (rc *RunContext) platformImage(ctx context.Context) string {
return ""
}
func (rc *RunContext) hostname(ctx context.Context) string {
logger := common.Logger(ctx)
func (rc *RunContext) options(ctx context.Context) string {
job := rc.Run.Job()
c := job.Container()
if c == nil {
return ""
}
optionsFlags := pflag.NewFlagSet("container_options", pflag.ContinueOnError)
hostname := optionsFlags.StringP("hostname", "h", "", "")
optionsArgs, err := shellquote.Split(c.Options)
if err != nil {
logger.Warnf("Cannot parse container options: %s", c.Options)
return ""
}
err = optionsFlags.Parse(optionsArgs)
if err != nil {
logger.Warnf("Cannot parse container options: %s", c.Options)
return ""
}
return *hostname
return c.Options
}
func (rc *RunContext) isEnabled(ctx context.Context) (bool, error) {