Skip to content

Commit

Permalink
Use ECR Public source client for image checks in prod bundle release (#…
Browse files Browse the repository at this point in the history
…9016)

Co-authored-by: Abhay Krishna Arunachalam <[email protected]>
  • Loading branch information
eks-distro-pr-bot and abhay-krishna authored Nov 18, 2024
1 parent e4334bc commit 8da1f91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
18 changes: 14 additions & 4 deletions release/cli/pkg/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,24 @@ func ComputeImageDigestFromManifest(ecrPublicClient *ecrpublicsdk.ECRPublic, reg
return fmt.Sprintf("%x", digest), nil
}

func CheckRepositoryImagesAndTagsCountLimit(sourceImageUri, releaseImageUri, sourceContainerRegistry, releaseContainerRegistry string, ecrClient *ecrsdk.ECR, ecrPublicClient *ecrpublicsdk.ECRPublic) error {
func CheckRepositoryImagesAndTagsCountLimit(sourceImageUri, releaseImageUri, sourceContainerRegistry, releaseContainerRegistry string, ecrClient interface{}, ecrPublicClient *ecrpublicsdk.ECRPublic) error {
repository, _ := artifactutils.SplitImageUri(releaseImageUri, releaseContainerRegistry)

fmt.Printf("Checking if image %s can be pushed to repository %s\n", releaseImageUri, repository)

sourceImageDigest, err := ecr.GetImageDigest(sourceImageUri, sourceContainerRegistry, ecrClient)
if err != nil {
return errors.Cause(err)
var sourceImageDigest string
var err error
switch ecrClient.(type) {
case *ecrsdk.ECR:
sourceImageDigest, err = ecr.GetImageDigest(sourceImageUri, sourceContainerRegistry, ecrClient.(*ecrsdk.ECR))
if err != nil {
return errors.Cause(err)
}
case *ecrpublicsdk.ECRPublic:
sourceImageDigest, err = ecrpublic.GetImageDigest(sourceImageUri, sourceContainerRegistry, ecrClient.(*ecrpublicsdk.ECRPublic))
if err != nil {
return errors.Cause(err)
}
}

allImagesCount, err := ecrpublic.GetAllImagesCount(repository, ecrPublicClient)
Expand Down
7 changes: 6 additions & 1 deletion release/cli/pkg/operations/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ func handleImageUpload(_ context.Context, r *releasetypes.ReleaseConfig, package
releaseImageUri := artifact.Image.ReleaseImageURI
sourceEcrAuthConfig := defaultSourceEcrAuthConfig
sourceContainerRegistry := r.SourceContainerRegistry
sourceEcrClient := r.SourceClients.ECR.EcrClient
var sourceEcrClient interface{}
if r.ReleaseEnvironment == "production" && r.BundleRelease {
sourceEcrClient = r.SourceClients.ECR.EcrPublicClient
} else {
sourceEcrClient = r.SourceClients.ECR.EcrClient
}
if packagesutils.NeedsPackagesAccountArtifacts(r) && (strings.Contains(sourceImageUri, "eks-anywhere-packages") || strings.Contains(sourceImageUri, "ecr-token-refresher") || strings.Contains(sourceImageUri, "credential-provider-package")) {
sourceEcrAuthConfig = packagesSourceEcrAuthConfig
sourceContainerRegistry = r.PackagesSourceContainerRegistry
Expand Down

0 comments on commit 8da1f91

Please sign in to comment.