Skip to content

Commit

Permalink
fix processing of errors, add verbose logging, fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-savchuk committed Sep 16, 2022
1 parent 8964c67 commit 1d0c067
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 21 additions & 9 deletions pkg/container/docker_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,20 +389,17 @@ func (cr *containerReference) create(capAdd []string, capDrop []string) common.E

optionsArgs, err := shellquote.Split(input.Options)
if err != nil {
logger.Warnf("Cannot split container options: %s", input.Options)
return nil
return fmt.Errorf("Cannot split container options: '%s': '%w'", input.Options, err)
}

err = flags.Parse(optionsArgs)
if err != nil {
logger.Warnf("Cannot parse container options: %s", input.Options)
return nil
return fmt.Errorf("Cannot parse container options: '%s': '%w'", input.Options, err)
}

containerConfig, err := parse(flags, copts, "")
if err != nil {
logger.Warnf("Cannot parse container options: %s", input.Options)
return nil
return fmt.Errorf("Cannot process container options: '%s': '%w'", input.Options, err)
}

config := &container.Config{
Expand All @@ -411,7 +408,14 @@ func (cr *containerReference) create(capAdd []string, capDrop []string) common.E
Env: input.Env,
Tty: isTerminal,
}
mergo.Merge(config, containerConfig.Config, mergo.WithOverride)
logger.Debugf("Common container.Config ==> %+v", config)
logger.Debugf("Custom container.Config from options ==> %+v", containerConfig.Config)

err = mergo.Merge(config, containerConfig.Config, mergo.WithOverride)
if err != nil {
return fmt.Errorf("Cannot merge container.Config options: '%s': '%w'", input.Options, err)
}
logger.Debugf("Merged container.Config ==> %+v", config)

if len(input.Cmd) != 0 {
config.Cmd = input.Cmd
Expand Down Expand Up @@ -453,12 +457,20 @@ func (cr *containerReference) create(capAdd []string, capDrop []string) common.E
Privileged: input.Privileged,
UsernsMode: container.UsernsMode(input.UsernsMode),
}
mergo.Merge(hostConfig, containerConfig.HostConfig, mergo.WithOverride)
logger.Debugf("Common container.HostConfig ==> %+v", hostConfig)
logger.Debugf("Custom container.HostConfig from options ==> %+v", containerConfig.HostConfig)

err = mergo.Merge(hostConfig, containerConfig.HostConfig, mergo.WithOverride)
if err != nil {
return fmt.Errorf("Cannot merge container.HostConfig options: '%s': '%w'", input.Options, err)
}
logger.Debugf("Merged container.HostConfig ==> %+v", hostConfig)

resp, err := cr.cli.ContainerCreate(ctx, config, hostConfig, nil, platSpecs, input.Name)
if err != nil {
return fmt.Errorf("failed to create container: %w", err)
return fmt.Errorf("failed to create container: '%w'", err)
}

logger.Debugf("Created container name=%s id=%v from image %v (platform: %s)", input.Name, resp.ID, input.Image, input.Platform)
logger.Debugf("ENV ==> %v", input.Env)

Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/testdata/container-hostname/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
echo "UID: $(id -u)"
echo "GID: $(id -g)"
echo "HOST: $(uname -n)"
[[ $(id -u) == "100" ]] && [[ $(id -g) == "101" ]] && [[ $(uname -n) == "my.host.local" ]]
[[ "$(id -u)" == "100" ]] && [[ "$(id -g)" == "101" ]] && [[ "$(uname -n)" == "my.host.local" ]]
default-hostname:
runs-on: ubuntu-latest
Expand Down

0 comments on commit 1d0c067

Please sign in to comment.