Skip to content
Open
Show file tree
Hide file tree
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
340 changes: 213 additions & 127 deletions src/cmd/create.go

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/cmd/enter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"os"

"github.com/containers/toolbox/pkg/architecture"
"github.com/containers/toolbox/pkg/utils"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -108,7 +109,8 @@ func enter(cmd *cobra.Command, args []string) error {
containerArg,
enterFlags.distro,
"",
enterFlags.release)
enterFlags.release,
architecture.HostArchID)

if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/rootMigrationPath.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"strings"

"github.com/containers/toolbox/pkg/architecture"
"github.com/containers/toolbox/pkg/utils"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -56,7 +57,7 @@ func rootRunImpl(cmd *cobra.Command, args []string) error {
return &exitError{exitCode, err}
}

container, image, release, err := resolveContainerAndImageNames("", "", "", "", "")
container, image, release, err := resolveContainerAndImageNames("", "", "", "", "", architecture.HostArchID)
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"syscall"
"time"

"github.com/containers/toolbox/pkg/architecture"
"github.com/containers/toolbox/pkg/nvidia"
"github.com/containers/toolbox/pkg/podman"
"github.com/containers/toolbox/pkg/shell"
Expand Down Expand Up @@ -145,7 +146,8 @@ func run(cmd *cobra.Command, args []string) error {
"--container",
runFlags.distro,
"",
runFlags.release)
runFlags.release,
architecture.HostArchID)

if err != nil {
return err
Expand Down Expand Up @@ -225,7 +227,7 @@ func runCommand(container string,
return nil
}

if err := createContainer(container, image, release, "", false); err != nil {
if err := createContainer(container, image, release, "", architecture.GetArchConfigDefault(), false); err != nil {
return err
}
} else if containersCount == 1 && defaultContainer {
Expand Down
89 changes: 88 additions & 1 deletion src/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"strings"
"syscall"

"github.com/containers/toolbox/pkg/architecture"
"github.com/containers/toolbox/pkg/shell"
"github.com/containers/toolbox/pkg/utils"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -261,6 +262,18 @@ func discardInputAsync(ctx context.Context) (<-chan int, <-chan error) {
return retValCh, errCh
}

func createErrorConflictingArchSpecs(archCLI, archTag int) error {
var builder strings.Builder
fmt.Fprintf(&builder, "conflicting architecture specifications\n")
fmt.Fprintf(&builder, "--arch=%s but image tag specifies %s\n",
architecture.GetArchNameOCI(archCLI),
architecture.GetArchNameOCI(archTag))
fmt.Fprintf(&builder, "Run '%s --help' for usage.", executableBase)

errMsg := builder.String()
return errors.New(errMsg)
}

func createErrorContainerNotFound(container string) error {
var builder strings.Builder
fmt.Fprintf(&builder, "container %s not found\n", container)
Expand All @@ -281,6 +294,15 @@ func createErrorDistroWithoutRelease(distro string) error {
return errors.New(errMsg)
}

func createErrorImagePull(image, domain string) error {
var builder strings.Builder
fmt.Fprintf(&builder, "failed to pull image %s\n", image)
fmt.Fprintf(&builder, "If it was a private image, log in with: podman login %s\n", domain)
fmt.Fprintf(&builder, "Use '%s --verbose ...' for further details.", executableBase)

return errors.New(builder.String())
}

func createErrorInvalidContainer(containerArg string) error {
var builder strings.Builder
fmt.Fprintf(&builder, "invalid argument for '%s'\n", containerArg)
Expand Down Expand Up @@ -345,6 +367,14 @@ func createErrorProfileDNotFound() error {
return errors.New(errMsg)
}

func createErrorSkopeoNotFound(imageFull string, archID int) error {
archName := architecture.GetArchNameOCI(archID)
return fmt.Errorf(
"Cannot inspect image %s for architecture %s: skopeo is not installed.\n"+
"Skopeo is required for creating non-native architecture containers.",
imageFull, archName)
}

func createErrorSudoersDNotFound() error {
const sudoersD = "/etc/sudoers.d"

Expand Down Expand Up @@ -483,9 +513,40 @@ func poll(pollFn pollFunc, eventFD int32, fds ...int32) error {
}
}

func resolveContainerAndImageNames(container, containerArg, distroCLI, imageCLI, releaseCLI string) (
func resolveArchitectureID(arch string, image string) (int, error) {
archID := architecture.NotSpecified
if arch != "" {
archIDParsed, err := architecture.ParseArgArchValue(arch)
if err != nil {
return architecture.NotSpecified, err
}
archID = archIDParsed
}

if image != "" && utils.IsSupportedDistroImage(image) {
archIDFromTag := architecture.ImageReferenceGetArchFromTag(image)

if archID == architecture.NotSpecified && archIDFromTag != architecture.NotSpecified {
logrus.Debug("non-native architecture was detected in the image tag -> cross-architecture approach is going to be used")

archID = archIDFromTag
} else if archID != archIDFromTag && archIDFromTag != architecture.NotSpecified {
return architecture.NotSpecified, createErrorConflictingArchSpecs(archID, archIDFromTag)
}
}

if archID == architecture.NotSpecified {
archID = architecture.HostArchID
}

return archID, nil
}

func resolveContainerAndImageNames(container, containerArg, distroCLI, imageCLI, releaseCLI string, archID int) (
string, string, string, error,
) {
containerWasEmpty := container == ""

container, image, release, err := utils.ResolveContainerAndImageNames(container,
distroCLI,
imageCLI,
Expand Down Expand Up @@ -540,9 +601,35 @@ func resolveContainerAndImageNames(container, containerArg, distroCLI, imageCLI,
}
}

if containerWasEmpty && !architecture.HasContainerNativeArch(archID) {
archIDFromTag := architecture.ImageReferenceGetArchFromTag(image)

if archIDFromTag == architecture.NotSpecified {
archName := architecture.GetArchNameOCI(archID)
if archName != "" {
container = container + "-" + archName
}
}
}

return container, image, release, nil
}

func resolveImageNameWithArchitectureSuffix(image string, archID int) string {
if architecture.HasContainerNativeArch(archID) {
return image
}

archIDFromTag := architecture.ImageReferenceGetArchFromTag(image)
isSupportedDistroImage := utils.IsSupportedDistroImage(image)

if isSupportedDistroImage && archIDFromTag == architecture.NotSpecified {
return image + "-" + architecture.GetArchNameOCI(archID)
}

return image
}

// showManual tries to open the specified manual page using man on stdout
func showManual(manual string) error {
manBinary, err := exec.LookPath("man")
Expand Down
Loading
Loading