Skip to content

Commit

Permalink
fix(multiarch): use correct multiarch manifests for werf-run and werf…
Browse files Browse the repository at this point in the history
…-kube-run commands

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed May 16, 2023
1 parent a9431b7 commit fca96f2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 31 deletions.
15 changes: 2 additions & 13 deletions cmd/werf/kube_run/kube_run.go
Expand Up @@ -417,21 +417,10 @@ func run(ctx context.Context, pod, secret, namespace string, werfConfig *config.
}
}

targetPlatforms, err := c.GetTargetPlatforms()
image, err = c.GetFullImageName(ctx, imageName)
if err != nil {
return fmt.Errorf("invalid target platforms: %w", err)
return fmt.Errorf("unable to get full name for image %q: %w", imageName, err)
}
if len(targetPlatforms) == 0 {
targetPlatforms = []string{containerBackend.GetDefaultPlatform()}
}

// FIXME(multiarch): specify multiarch manifest here
if err := c.FetchLastImageStage(ctx, targetPlatforms[0], imageName); err != nil {
return err
}

// FIXME(multiarch): specify multiarch manifest here
image = c.GetImageNameForLastImageStage(targetPlatforms[0], imageName)
return nil
}); err != nil {
return err
Expand Down
14 changes: 2 additions & 12 deletions cmd/werf/run/run.go
Expand Up @@ -403,20 +403,10 @@ func run(ctx context.Context, containerBackend container_backend.ContainerBacken
}
}

targetPlatforms, err := c.GetTargetPlatforms()
dockerImageName, err = c.GetFullImageName(ctx, imageName)
if err != nil {
return fmt.Errorf("invalid target platforms: %w", err)
return fmt.Errorf("unable to get full name for image %q: %w", imageName, err)
}
if len(targetPlatforms) == 0 {
targetPlatforms = []string{containerBackend.GetDefaultPlatform()}
}

// FIXME(multiarch): specify multiarch manifest here
if err := c.FetchLastImageStage(ctx, targetPlatforms[0], imageName); err != nil {
return err
}

dockerImageName = c.GetImageNameForLastImageStage(targetPlatforms[0], imageName)
return nil
}); err != nil {
return err
Expand Down
13 changes: 13 additions & 0 deletions pkg/build/conveyor.go
Expand Up @@ -403,6 +403,19 @@ func (c *Conveyor) FetchLastImageStage(ctx context.Context, targetPlatform, imag
return c.StorageManager.FetchStage(ctx, c.ContainerBackend, lastImageStage)
}

func (c *Conveyor) GetFullImageName(ctx context.Context, imageName string) (string, error) {
infoGetters, err := c.GetImageInfoGetters(imagePkg.InfoGetterOptions{})
if err != nil {
return "", nil
}
for _, getter := range infoGetters {
if getter.WerfImageName == imageName {
return getter.GetName(), nil
}
}
return "", fmt.Errorf("image not found")
}

func (c *Conveyor) GetImageInfoGetters(opts imagePkg.InfoGetterOptions) ([]*imagePkg.InfoGetter, error) {
var imagesGetters []*imagePkg.InfoGetter
for _, desc := range c.imagesTree.GetImagesByName(true) {
Expand Down
1 change: 0 additions & 1 deletion pkg/container_backend/legacy_stage_image.go
Expand Up @@ -67,7 +67,6 @@ func (i *LegacyStageImage) GetID() string {
}

func (i *LegacyStageImage) Build(ctx context.Context, options BuildOptions) error {
// FIXME(multiarch): docker server default platform should be defined using server-info, not current machine platform
if i.GetTargetPlatform() == i.ContainerBackend.GetDefaultPlatform() && i.ContainerBackend.GetDefaultPlatform() != "linux/amd64" {
logboek.Context(ctx).Error().LogF("Detected your default build platform as %s.\n", i.ContainerBackend.GetDefaultPlatform())
logboek.Context(ctx).Error().LogF("Building of stapel-type images using Docker-Server backend for platforms other than linux/amd64 is not supported.\n")
Expand Down
10 changes: 5 additions & 5 deletions pkg/docker/main.go
Expand Up @@ -23,7 +23,7 @@ import (
var (
liveCliOutputEnabled bool
isDebug bool
defaultCLi command.Cli
defaultCLI command.Cli
defaultPlatform string
runtimePlatform string
useBuildx bool
Expand All @@ -36,7 +36,7 @@ const (
)

func IsEnabled() bool {
return defaultCLi != nil
return defaultCLI != nil
}

type InitOptions struct {
Expand All @@ -63,13 +63,13 @@ func Init(ctx context.Context, opts InitOptions) error {
isDebug = os.Getenv("WERF_DEBUG_DOCKER") == "1"
liveCliOutputEnabled = opts.Verbose || opts.Debug

defaultCLi, err = newDockerCli(defaultCliOptions(ctx))
defaultCLI, err = newDockerCli(defaultCliOptions(ctx))
if err != nil {
return err
}

spec := platforms.DefaultSpec()
spec.OS = defaultCLi.ServerInfo().OSType
spec.OS = defaultCLI.ServerInfo().OSType
runtimePlatform = platforms.Format(spec)
claimPlatforms := opts.ClaimPlatforms

Expand Down Expand Up @@ -169,7 +169,7 @@ func cli(ctx context.Context) command.Cli {
case cliInterf != nil:
return cliInterf.(command.Cli)
case ctx == context.Background():
return defaultCLi
return defaultCLI
default:
panic("context is not bound with docker cli")
}
Expand Down

0 comments on commit fca96f2

Please sign in to comment.