Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: integration tests should not fail (#5669)
* fix: integration tests should not fail

- RepoDigest is always `repo@sha256:digest`
- Use GetDigest() when `sha256:digest` is needed.
- Fix DeleteImage method for default implementation, Selectel, AWS, and Gitlab.

Signed-off-by: Ivan Mikheykin <ivan.mikheykin@flant.com>
  • Loading branch information
diafour committed Jun 1, 2023
1 parent fb707aa commit c4e411a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pkg/docker_registry/aws_ecr.go
Expand Up @@ -44,13 +44,14 @@ func (r *awsEcr) DeleteRepoImage(_ context.Context, repoImage *image.Info) error
if err != nil {
return err
}
digest := repoImage.GetDigest()

mySession := session.Must(session.NewSession())
service := ecr.New(mySession, aws.NewConfig().WithRegion(region))
_, err = service.BatchDeleteImage(&ecr.BatchDeleteImageInput{
ImageIds: []*ecr.ImageIdentifier{
{
ImageDigest: &repoImage.RepoDigest,
ImageDigest: &digest,
},
},
RepositoryName: &repository,
Expand Down
2 changes: 1 addition & 1 deletion pkg/docker_registry/default.go
Expand Up @@ -67,7 +67,7 @@ func (r *defaultImplementation) TagRepoImage(ctx context.Context, repoImage *ima
}

func (r *defaultImplementation) DeleteRepoImage(ctx context.Context, repoImage *image.Info) error {
return r.api.deleteImageByReference(ctx, strings.Join([]string{repoImage.Repository, repoImage.RepoDigest}, "@"))
return r.api.deleteImageByReference(ctx, repoImage.RepoDigest)
}

func (r *defaultImplementation) String() string {
Expand Down
3 changes: 1 addition & 2 deletions pkg/docker_registry/gitlab_registry.go
Expand Up @@ -128,8 +128,7 @@ func (r *gitLabRegistry) deleteRepoImageTagWithCustomScope(repoImage *image.Info
}

func (r *gitLabRegistry) deleteRepoImageWithCustomScope(repoImage *image.Info, scopeFunc func(ref name.Reference) []string) error {
reference := strings.Join([]string{repoImage.Repository, repoImage.RepoDigest}, "@")
return r.customDeleteRepoImage("/v2/%s/manifests/%s", reference, scopeFunc)
return r.customDeleteRepoImage("/v2/%s/manifests/%s", repoImage.RepoDigest, scopeFunc)
}

func (r *gitLabRegistry) customDeleteRepoImage(endpointFormat, reference string, scopeFunc func(ref name.Reference) []string) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/docker_registry/selectel.go
Expand Up @@ -112,7 +112,7 @@ func (r *selectel) deleteRepoImage(ctx context.Context, repoImage *image.Info) e

//nolint:bodyclose
// TODO: close response body
resp, err := r.selectelApi.deleteReference(ctx, hostname, registryID, repository, repoImage.RepoDigest, token)
resp, err := r.selectelApi.deleteReference(ctx, hostname, registryID, repository, repoImage.GetDigest(), token)
if err != nil {
return r.handleFailedApiResponse(resp, err)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/image/info.go
Expand Up @@ -17,6 +17,7 @@ type Info struct {
Name string `json:"name"`
Repository string `json:"repository"`
Tag string `json:"tag"`
// repo@sha256:digest
RepoDigest string `json:"repoDigest"`

OnBuild []string `json:"onBuild"`
Expand Down Expand Up @@ -104,6 +105,7 @@ func NormalizeRepository(repository string) (res string) {
return
}

// ExtractRepoDigest return repo@digest from the list.
func ExtractRepoDigest(inspectRepoDigests []string, repository string) string {
for _, inspectRepoDigest := range inspectRepoDigests {
repoAndDigest := strings.SplitN(inspectRepoDigest, "@sha256:", 2)
Expand Down

0 comments on commit c4e411a

Please sign in to comment.