Skip to content

Commit

Permalink
fix(publish): override images when related stages are lost
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Igrychev <alexey.igrychev@flant.com>
  • Loading branch information
alexey-igrychev committed May 11, 2022
1 parent e03bb7f commit 0d26c80
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -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=
Expand Down
11 changes: 8 additions & 3 deletions pkg/build/publish_images_phase.go
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down

0 comments on commit 0d26c80

Please sign in to comment.