Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fix(multiarch): publish git metadata for multiplatform mode images
Introduced MultiplatformImage descriptor to manage multiplatform images and maintain list of multiplatform images in the ImagesTree primitive. Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
- Loading branch information
1 parent
e685e5e
commit 1913c95
Showing
3 changed files
with
131 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package image | ||
|
||
import ( | ||
common_image "github.com/werf/werf/pkg/image" | ||
"github.com/werf/werf/pkg/storage/manager" | ||
"github.com/werf/werf/pkg/util" | ||
) | ||
|
||
type MultiplatformImage struct { | ||
Name string | ||
Images []*Image | ||
|
||
MultiplatformImageOptions | ||
|
||
calculatedDigest string | ||
stageID common_image.StageID | ||
} | ||
|
||
type MultiplatformImageOptions struct { | ||
IsArtifact, IsDockerfileImage, IsDockerfileTargetStage bool | ||
} | ||
|
||
func NewMultiplatformImage(name string, images []*Image, storageManager manager.StorageManagerInterface, opts MultiplatformImageOptions) *MultiplatformImage { | ||
img := &MultiplatformImage{ | ||
Name: name, | ||
Images: images, | ||
MultiplatformImageOptions: opts, | ||
} | ||
|
||
metaStageDeps := util.MapFuncToSlice(images, func(img *Image) string { | ||
stageDesc := img.GetLastNonEmptyStage().GetStageImage().Image.GetStageDescription() | ||
return stageDesc.StageID.String() | ||
}) | ||
img.calculatedDigest = util.Sha3_224Hash(metaStageDeps...) | ||
|
||
_, uniqueID := storageManager.GenerateStageUniqueID(img.GetDigest(), nil) | ||
img.stageID = common_image.StageID{Digest: img.GetDigest(), UniqueID: uniqueID} | ||
|
||
return img | ||
} | ||
|
||
func (img *MultiplatformImage) GetPlatforms() []string { | ||
return util.MapFuncToSlice(img.Images, func(img *Image) string { return img.TargetPlatform }) | ||
} | ||
|
||
func (img *MultiplatformImage) GetDigest() string { | ||
return img.calculatedDigest | ||
} | ||
|
||
func (img *MultiplatformImage) GetStageID() common_image.StageID { | ||
return img.stageID | ||
} | ||
|
||
func (img *MultiplatformImage) GetImagesInfoList() []*common_image.Info { | ||
return util.MapFuncToSlice(img.Images, func(img *Image) *common_image.Info { | ||
stageDesc := img.GetLastNonEmptyStage().GetStageImage().Image.GetStageDescription() | ||
return stageDesc.Info | ||
}) | ||
} |