Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add containerd's normalized architectures to archMapper #2168

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/container/docker_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

func (cr *containerReference) Create(capAdd []string, capDrop []string) common.Executor {
return common.
NewInfoExecutor("%sdocker create image=%s platform=%s entrypoint=%+q cmd=%+q network=%+q", logPrefix, cr.input.Image, cr.input.Platform, cr.input.Entrypoint, cr.input.Cmd, cr.input.NetworkMode).

Check warning on line 67 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L67

Added line #L67 was not covered by tests
Then(
common.NewPipelineExecutor(
cr.connect(),
Expand All @@ -76,7 +76,7 @@

func (cr *containerReference) Start(attach bool) common.Executor {
return common.
NewInfoExecutor("%sdocker run image=%s platform=%s entrypoint=%+q cmd=%+q network=%+q", logPrefix, cr.input.Image, cr.input.Platform, cr.input.Entrypoint, cr.input.Cmd, cr.input.NetworkMode).

Check warning on line 79 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L79

Added line #L79 was not covered by tests
Then(
common.NewPipelineExecutor(
cr.connect(),
Expand Down Expand Up @@ -238,8 +238,10 @@

archMapper := map[string]string{
"x86_64": "X64",
"amd64": "X64",
"386": "X86",
"aarch64": "ARM64",
"arm64": "ARM64",

Check warning on line 244 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L241-L244

Added lines #L241 - L244 were not covered by tests
}
if arch, ok := archMapper[info.Architecture]; ok {
return arch
Expand Down Expand Up @@ -343,13 +345,13 @@
return nil, nil, fmt.Errorf("Cannot parse container options: '%s': '%w'", input.Options, err)
}

if len(copts.netMode.Value()) == 0 {
if err = copts.netMode.Set(cr.input.NetworkMode); err != nil {
return nil, nil, fmt.Errorf("Cannot parse networkmode=%s. This is an internal error and should not happen: '%w'", cr.input.NetworkMode, err)
}

Check warning on line 351 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L348-L351

Added lines #L348 - L351 were not covered by tests
}

containerConfig, err := parse(flags, copts, runtime.GOOS)

Check warning on line 354 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L354

Added line #L354 was not covered by tests
if err != nil {
return nil, nil, fmt.Errorf("Cannot process container options: '%s': '%w'", input.Options, err)
}
Expand Down Expand Up @@ -389,11 +391,11 @@
input := cr.input

config := &container.Config{
Image: input.Image,
WorkingDir: input.WorkingDir,
Env: input.Env,
ExposedPorts: input.ExposedPorts,
Tty: isTerminal,

Check warning on line 398 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L394-L398

Added lines #L394 - L398 were not covered by tests
}
logger.Debugf("Common container.Config ==> %+v", config)

Expand Down Expand Up @@ -429,14 +431,14 @@
}

hostConfig := &container.HostConfig{
CapAdd: capAdd,
CapDrop: capDrop,
Binds: input.Binds,
Mounts: mounts,
NetworkMode: container.NetworkMode(input.NetworkMode),
Privileged: input.Privileged,
UsernsMode: container.UsernsMode(input.UsernsMode),
PortBindings: input.PortBindings,

Check warning on line 441 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L434-L441

Added lines #L434 - L441 were not covered by tests
}
logger.Debugf("Common container.HostConfig ==> %+v", hostConfig)

Expand All @@ -445,22 +447,22 @@
return err
}

var networkingConfig *network.NetworkingConfig
logger.Debugf("input.NetworkAliases ==> %v", input.NetworkAliases)
n := hostConfig.NetworkMode
// IsUserDefined and IsHost are broken on windows
if n.IsUserDefined() && n != "host" && len(input.NetworkAliases) > 0 {
endpointConfig := &network.EndpointSettings{
Aliases: input.NetworkAliases,
}
networkingConfig = &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
input.NetworkMode: endpointConfig,
},
}
}

Check warning on line 463 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L450-L463

Added lines #L450 - L463 were not covered by tests

resp, err := cr.cli.ContainerCreate(ctx, config, hostConfig, networkingConfig, platSpecs, input.Name)

Check warning on line 465 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L465

Added line #L465 was not covered by tests
if err != nil {
return fmt.Errorf("failed to create container: '%w'", err)
}
Expand All @@ -481,17 +483,17 @@
inspect, _, err := cr.cli.ImageInspectWithRaw(ctx, cr.input.Image)
if err != nil {
logger.Error(err)
return fmt.Errorf("inspect image: %w", err)
}

Check warning on line 487 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L486-L487

Added lines #L486 - L487 were not covered by tests

if inspect.Config == nil {
return nil

Check warning on line 490 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L490

Added line #L490 was not covered by tests
}

imageEnv, err := godotenv.Unmarshal(strings.Join(inspect.Config.Env, "\n"))
if err != nil {
logger.Error(err)
return fmt.Errorf("unmarshal image env: %w", err)

Check warning on line 496 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L496

Added line #L496 was not covered by tests
}

for k, v := range imageEnv {
Expand Down Expand Up @@ -607,7 +609,7 @@
}
exp := regexp.MustCompile(`\d+\n`)
found := exp.FindString(sid)
id, err := strconv.ParseInt(strings.TrimSpace(found), 10, 32)

Check warning on line 612 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L612

Added line #L612 was not covered by tests
if err != nil {
return nil
}
Expand Down Expand Up @@ -670,30 +672,30 @@
}
}

func (cr *containerReference) CopyTarStream(ctx context.Context, destPath string, tarStream io.Reader) error {
// Mkdir
buf := &bytes.Buffer{}
tw := tar.NewWriter(buf)
_ = tw.WriteHeader(&tar.Header{
Name: destPath,
Mode: 777,
Typeflag: tar.TypeDir,
})
tw.Close()
err := cr.cli.CopyToContainer(ctx, cr.id, "/", buf, types.CopyToContainerOptions{})
if err != nil {
return fmt.Errorf("failed to mkdir to copy content to container: %w", err)
}

Check warning on line 688 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L675-L688

Added lines #L675 - L688 were not covered by tests
// Copy Content
err = cr.cli.CopyToContainer(ctx, cr.id, destPath, tarStream, types.CopyToContainerOptions{})
if err != nil {
return fmt.Errorf("failed to copy content to container: %w", err)
}

Check warning on line 693 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L690-L693

Added lines #L690 - L693 were not covered by tests
// If this fails, then folders have wrong permissions on non root container
if cr.UID != 0 || cr.GID != 0 {
_ = cr.Exec([]string{"chown", "-R", fmt.Sprintf("%d:%d", cr.UID, cr.GID), destPath}, nil, "0", "")(ctx)
}
return nil

Check warning on line 698 in pkg/container/docker_run.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/docker_run.go#L695-L698

Added lines #L695 - L698 were not covered by tests
}

func (cr *containerReference) copyDir(dstPath string, srcPath string, useGitIgnore bool) common.Executor {
Expand Down
Loading