From 0d26c80f6fd08bc87ee6e2de1786fbc2d68a1448 Mon Sep 17 00:00:00 2001 From: Alexey Igrychev Date: Wed, 11 May 2022 14:22:35 +0100 Subject: [PATCH] fix(publish): override images when related stages are lost Signed-off-by: Alexey Igrychev --- go.mod | 1 + go.sum | 2 ++ pkg/build/publish_images_phase.go | 11 ++++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 76f1e6bf7f..c7e3a1e329 100644 --- a/go.mod +++ b/go.mod @@ -69,6 +69,7 @@ require ( github.com/xeipuuv/gojsonschema v1.2.0 // indirect golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 golang.org/x/net v0.0.0-20200707034311-ab3426394381 + golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect google.golang.org/grpc v1.29.1 gopkg.in/dancannon/gorethink.v3 v3.0.5 // indirect gopkg.in/fatih/pool.v2 v2.0.0 // indirect diff --git a/go.sum b/go.sum index 8a45e5d5a8..57c93a3db8 100644 --- a/go.sum +++ b/go.sum @@ -1824,6 +1824,8 @@ golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200523222454-059865788121 h1:rITEj+UZHYC927n8GT97eC3zrpzXdb/voyeOuVKS46o= golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 h1:nonptSpoQ4vQjyraW20DXPAglgQfVnM9ZC6MmNLMR60= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915090833-1cbadb444a80/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/pkg/build/publish_images_phase.go b/pkg/build/publish_images_phase.go index 143ef8c9f7..d623144ff7 100644 --- a/pkg/build/publish_images_phase.go +++ b/pkg/build/publish_images_phase.go @@ -240,8 +240,9 @@ func (phase *PublishImagesPhase) publishImageByTag(ctx context.Context, img *Ima imageRepository := phase.ImagesRepo.ImageRepositoryName(img.GetName()) imageName := phase.ImagesRepo.ImageRepositoryNameWithTag(img.GetName(), imageMetaTag) imageActualTag := phase.ImagesRepo.ImageRepositoryTag(img.GetName(), imageMetaTag) + imageStageID := img.GetLastNonEmptyStage().GetImage().GetStageDescription().Info.ID - alreadyExists, alreadyExistingRepoImageInfo, err := phase.checkImageAlreadyExists(ctx, opts.ExistingTagsList, img.GetName(), imageMetaTag, img.GetContentSignature()) + alreadyExists, alreadyExistingRepoImageInfo, err := phase.checkImageAlreadyExists(ctx, opts.ExistingTagsList, img.GetName(), imageMetaTag, img.GetContentSignature(), imageStageID) if err != nil { return fmt.Errorf("error checking image %s already exists in the images repo: %s", img.LogName(), err) } @@ -311,7 +312,7 @@ func (phase *PublishImagesPhase) publishImageByTag(ctx context.Context, img *Ima return err } - alreadyExists, alreadyExistingRepoImageInfo, err := phase.checkImageAlreadyExists(ctx, existingTags, img.GetName(), imageMetaTag, img.GetContentSignature()) + alreadyExists, alreadyExistingRepoImageInfo, err := phase.checkImageAlreadyExists(ctx, existingTags, img.GetName(), imageMetaTag, img.GetContentSignature(), imageStageID) if err != nil { return fmt.Errorf("error checking image %s already exists in the images repo: %s", img.LogName(), err) } @@ -365,7 +366,7 @@ func (phase *PublishImagesPhase) publishImageByTag(ctx context.Context, img *Ima DoError(publishingFunc) } -func (phase *PublishImagesPhase) checkImageAlreadyExists(ctx context.Context, existingTags []string, werfImageName, imageMetaTag, imageContentSignature string) (bool, *image.Info, error) { +func (phase *PublishImagesPhase) checkImageAlreadyExists(ctx context.Context, existingTags []string, werfImageName, imageMetaTag, imageContentSignature, imageStageID string) (bool, *image.Info, error) { imageActualTag := phase.ImagesRepo.ImageRepositoryTag(werfImageName, imageMetaTag) if !util.IsStringsContainValue(existingTags, imageActualTag) { @@ -381,6 +382,10 @@ func (phase *PublishImagesPhase) checkImageAlreadyExists(ctx context.Context, ex return false, nil, fmt.Errorf("error getting repo image %q manifest: %s", phase.ImagesRepo.ImageRepositoryNameWithTag(werfImageName, imageMetaTag), err) } + if repoImage.ParentID != imageStageID { + return false, nil, nil + } + repoImageContentSignature := repoImage.Labels[image.WerfContentSignatureLabel] logboek.Context(ctx).Info().LogBlock("Existing tag %q manifest", imageActualTag).Do(func() { logboek.Context(ctx).Debug().LogF("Content signature: %s\n", imageContentSignature)