Skip to content

Commit

Permalink
fix(export, multiplatform): fix no child with platform linux/amd64 in…
Browse files Browse the repository at this point in the history
… index

Signed-off-by: Aleksei Igrychev <aleksei.igrychev@palark.com>
  • Loading branch information
alexey-igrychev committed Oct 25, 2024
1 parent 0dc6012 commit 49a1540
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pkg/build/build_phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (phase *BuildPhase) publishMultiplatformImageMetadata(ctx context.Context,
container_backend.LogImageName(ctx, fullImageName)
container_backend.LogMultiplatformImageInfo(ctx, platforms)

if err := primaryStagesStorage.PostMultiplatformImage(ctx, phase.Conveyor.ProjectName(), img.GetStageID().String(), img.GetImagesInfoList()); err != nil {
if err := primaryStagesStorage.PostMultiplatformImage(ctx, phase.Conveyor.ProjectName(), img.GetStageID().String(), img.GetImagesInfoList(), platforms); err != nil {
return fmt.Errorf("unable to post multiplatform image %s %s: %w", name, img.GetStageID(), err)
}

Expand Down
26 changes: 22 additions & 4 deletions pkg/docker_registry/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,15 +688,33 @@ func (api *api) PushManifestList(ctx context.Context, reference string, opts Man
if err != nil {
return fmt.Errorf("unable to parse reference %q: %w", info.Name, err)
}

// FIXME(multiarch): Optimize: do not get manifest, save v1.Image into the image.Info (optional)
desc, err := remote.Get(ref, api.defaultRemoteOptions(ctx)...)
if err != nil {
return fmt.Errorf("unable to get manifest of %q: %w", info.Name, err)
// FIXME(multiarch): add platform to image.Info.
var pl *v1.Platform
var desc *remote.Descriptor
var img v1.Image
for _, p := range opts.Platforms {
pl, err = v1.ParsePlatform(p)
if err != nil {
return fmt.Errorf("unable to parse platform %q: %w", p, err)
}

options := append(api.defaultRemoteOptions(ctx), remote.WithPlatform(*pl))
desc, err = remote.Get(ref, options...)
if err != nil {
return fmt.Errorf("unable to get manifest of %q: %w", info.Name, err)
}

img, err = desc.Image()
if err == nil {
break
}
}
img, err := desc.Image()
if err != nil {
return fmt.Errorf("unable to get image descriptor of %q: %w", info.Name, err)
}

cf, err := img.ConfigFile()
if err != nil {
return fmt.Errorf("unable to get config file of %q: %w", info.Name, err)
Expand Down
1 change: 1 addition & 0 deletions pkg/docker_registry/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type ArchiveOpener interface {

type ManifestListOptions struct {
Manifests []*image.Info
Platforms []string
}

type GetRepoImageOptions struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/local_stages_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (storage *LocalStagesStorage) PostClientIDRecord(_ context.Context, _ strin
panic("not implemented")
}

func (storage *LocalStagesStorage) PostMultiplatformImage(ctx context.Context, projectName, tag string, allPlatformsImages []*image.Info) error {
func (storage *LocalStagesStorage) PostMultiplatformImage(_ context.Context, _, _ string, _ []*image.Info, _ []string) error {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/repo_stages_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,14 +880,14 @@ func (storage *RepoStagesStorage) PostClientIDRecord(ctx context.Context, projec
return nil
}

func (storage *RepoStagesStorage) PostMultiplatformImage(ctx context.Context, projectName, tag string, allPlatformsImages []*image.Info) error {
func (storage *RepoStagesStorage) PostMultiplatformImage(ctx context.Context, projectName, tag string, allPlatformsImages []*image.Info, platforms []string) error {
logboek.Context(ctx).Debug().LogF("-- RepoStagesStorage.PostMultiplatformImage by tag %s for project %s\n", tag, projectName)

fullImageName := fmt.Sprintf("%s:%s", storage.RepoAddress, tag)

logboek.Context(ctx).Debug().LogF("-- RepoStagesStorage.PostMultiplatformImage full image name: %s\n", fullImageName)

opts := docker_registry.ManifestListOptions{Manifests: allPlatformsImages}
opts := docker_registry.ManifestListOptions{Manifests: allPlatformsImages, Platforms: platforms}
if err := storage.DockerRegistry.PushManifestList(ctx, fullImageName, opts); err != nil {
return fmt.Errorf("unable to push image %s: %w", fullImageName, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/stages_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type StagesStorage interface {

GetClientIDRecords(ctx context.Context, projectName string, opts ...Option) ([]*ClientIDRecord, error)
PostClientIDRecord(ctx context.Context, projectName string, rec *ClientIDRecord) error
PostMultiplatformImage(ctx context.Context, projectName, tag string, allPlatformsImages []*image.Info) error
PostMultiplatformImage(ctx context.Context, projectName, tag string, allPlatformsImages []*image.Info, platforms []string) error
FilterStagesAndProcessRelatedData(ctx context.Context, stageDescriptions []*image.StageDescription, options FilterStagesAndProcessRelatedDataOptions) ([]*image.StageDescription, error)

String() string
Expand Down

0 comments on commit 49a1540

Please sign in to comment.