* 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:
@@ -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) {
|
||||
|
12
pkg/runner/testdata/container-hostname/push.yml
vendored
12
pkg/runner/testdata/container-hostname/push.yml
vendored
@@ -10,10 +10,13 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: node:16-buster-slim
|
||||
options: "--hostname my.host.local"
|
||||
options: "--hostname my.host.local --user 100:101"
|
||||
steps:
|
||||
- run: |
|
||||
[[ $(uname -n) == "my.host.local" ]]
|
||||
echo "UID: $(id -u)"
|
||||
echo "GID: $(id -g)"
|
||||
echo "HOST: $(uname -n)"
|
||||
[[ "$(id -u)" == "100" ]] && [[ "$(id -g)" == "101" ]] && [[ "$(uname -n)" == "my.host.local" ]]
|
||||
|
||||
default-hostname:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -21,4 +24,7 @@ jobs:
|
||||
image: node:16-buster-slim
|
||||
steps:
|
||||
- run: |
|
||||
[[ $(uname -n) ]] && [[ $(uname -n) != "my.host.local" ]]
|
||||
echo "UID: $(id -u)"
|
||||
echo "GID: $(id -g)"
|
||||
echo "HOST: $(uname -n)"
|
||||
[[ "$(id -u)" == "0" ]] && [[ "$(id -g)" == "0" ]] && [[ $(uname -n) ]] && [[ "$(uname -n)" != "my.host.local" ]]
|
||||
|
Reference in New Issue
Block a user