Skip to content

Commit

Permalink
Add logic to source packages images from beta account (#8628)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhay-krishna committed Aug 19, 2024
1 parent e46233b commit a528959
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 139 deletions.
5 changes: 3 additions & 2 deletions release/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CLI_MAX_VERSION?=$(shell cat triggers/bundle-release/$(RELEASE_ENVIRONMENT)/CLI_
SOURCE_BUCKET?=source-bucket
RELEASE_BUCKET?=release-bucket
SOURCE_CONTAINER_REGISTRY?=$(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
PACKAGES_SOURCE_CONTAINER_REGISTRY?=$(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
RELEASE_CONTAINER_REGISTRY?=$(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
CDN?=https://$(RELEASE_BUCKET)
CLI_REPO_URL?=https://github.com/aws/eks-anywhere.git
Expand Down Expand Up @@ -134,10 +135,10 @@ run: manifests generate fmt vet ## Run a controller from your host.
##@ ReleaseTestGenerateManifestAssets

dev-release: build ## Perform a dev release of EKS-A bundles and CLI manifests
scripts/release.sh $(REPO_ROOT)/release/downloaded-artifacts $(SOURCE_BUCKET) $(RELEASE_BUCKET) $(CDN) $(SOURCE_CONTAINER_REGISTRY) $(RELEASE_CONTAINER_REGISTRY) $(BUILD_REPO_URL) $(CLI_REPO_URL) $(BUILD_REPO_BRANCH_NAME) $(CLI_REPO_BRANCH_NAME) $(DRY_RUN) $(WEEKLY)
scripts/release.sh $(REPO_ROOT)/release/downloaded-artifacts $(SOURCE_BUCKET) $(RELEASE_BUCKET) $(CDN) $(SOURCE_CONTAINER_REGISTRY) $(PACKAGES_SOURCE_CONTAINER_REGISTRY) $(RELEASE_CONTAINER_REGISTRY) $(BUILD_REPO_URL) $(CLI_REPO_URL) $(BUILD_REPO_BRANCH_NAME) $(CLI_REPO_BRANCH_NAME) $(DRY_RUN) $(WEEKLY)

bundle-release: build ## Perform EKS-A versioned bundles release
scripts/bundle-release.sh $(REPO_ROOT)/release/downloaded-artifacts $(SOURCE_BUCKET) $(RELEASE_BUCKET) $(CDN) $(BUNDLE_NUMBER) $(CLI_MIN_VERSION) $(CLI_MAX_VERSION) $(SOURCE_CONTAINER_REGISTRY) $(RELEASE_CONTAINER_REGISTRY) $(RELEASE_ENVIRONMENT) $(BUILD_REPO_BRANCH_NAME) $(CLI_REPO_BRANCH_NAME) $(BUILD_REPO_URL) $(CLI_REPO_URL)
scripts/bundle-release.sh $(REPO_ROOT)/release/downloaded-artifacts $(SOURCE_BUCKET) $(RELEASE_BUCKET) $(CDN) $(BUNDLE_NUMBER) $(CLI_MIN_VERSION) $(CLI_MAX_VERSION) $(SOURCE_CONTAINER_REGISTRY) $(PACKAGES_SOURCE_CONTAINER_REGISTRY) $(RELEASE_CONTAINER_REGISTRY) $(RELEASE_ENVIRONMENT) $(BUILD_REPO_BRANCH_NAME) $(CLI_REPO_BRANCH_NAME) $(BUILD_REPO_URL) $(CLI_REPO_URL)

eks-a-release: build ## Perform EKS-A CLI release
scripts/eks-a-release.sh $(RELEASE_VERSION) $(REPO_ROOT)/release/downloaded-artifacts $(SOURCE_BUCKET) $(RELEASE_BUCKET) $(CDN) $(BUNDLE_NUMBER) $(RELEASE_NUMBER) $(RELEASE_ENVIRONMENT) $(CLI_REPO_BRANCH_NAME) $(BUILD_REPO_URL) $(CLI_REPO_URL)
Expand Down
49 changes: 26 additions & 23 deletions release/cli/cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var releaseCmd = &cobra.Command{
sourceBucket := viper.GetString("source-bucket")
releaseBucket := viper.GetString("release-bucket")
sourceContainerRegistry := viper.GetString("source-container-registry")
packagesSourceContainerRegistry := viper.GetString("packages-source-container-registry")
releaseContainerRegistry := viper.GetString("release-container-registry")
cdn := viper.GetString("cdn")
devRelease := viper.GetBool("dev-release")
Expand All @@ -95,29 +96,30 @@ var releaseCmd = &cobra.Command{
}

releaseConfig := &releasetypes.ReleaseConfig{
CliRepoSource: cliRepoDir,
BuildRepoSource: buildRepoDir,
CliRepoUrl: cliRepoUrl,
BuildRepoUrl: buildRepoUrl,
BuildRepoBranchName: buildRepoBranchName,
CliRepoBranchName: cliRepoBranchName,
ArtifactDir: artifactDir,
SourceBucket: sourceBucket,
ReleaseBucket: releaseBucket,
SourceContainerRegistry: sourceContainerRegistry,
ReleaseContainerRegistry: releaseContainerRegistry,
CDN: cdn,
BundleNumber: bundleNumber,
ReleaseNumber: releaseNumber,
ReleaseVersion: releaseVersion,
ReleaseDate: releaseDate,
ReleaseTime: releaseTime,
DevRelease: devRelease,
DryRun: dryRun,
Weekly: weekly,
ReleaseEnvironment: releaseEnvironment,
AwsSignerProfileArn: awsSignerProfileArn,
MaxReleasesInManifest: -1,
CliRepoSource: cliRepoDir,
BuildRepoSource: buildRepoDir,
CliRepoUrl: cliRepoUrl,
BuildRepoUrl: buildRepoUrl,
BuildRepoBranchName: buildRepoBranchName,
CliRepoBranchName: cliRepoBranchName,
ArtifactDir: artifactDir,
SourceBucket: sourceBucket,
ReleaseBucket: releaseBucket,
SourceContainerRegistry: sourceContainerRegistry,
PackagesSourceContainerRegistry: packagesSourceContainerRegistry,
ReleaseContainerRegistry: releaseContainerRegistry,
CDN: cdn,
BundleNumber: bundleNumber,
ReleaseNumber: releaseNumber,
ReleaseVersion: releaseVersion,
ReleaseDate: releaseDate,
ReleaseTime: releaseTime,
DevRelease: devRelease,
DryRun: dryRun,
Weekly: weekly,
ReleaseEnvironment: releaseEnvironment,
AwsSignerProfileArn: awsSignerProfileArn,
MaxReleasesInManifest: -1,
}

err := operations.SetRepoHeads(releaseConfig)
Expand Down Expand Up @@ -365,6 +367,7 @@ func init() {
releaseCmd.Flags().String("source-bucket", "eks-a-source-bucket", "The bucket name where the built/staging artifacts are located to download")
releaseCmd.Flags().String("release-bucket", "eks-a-release-bucket", "The bucket name where released artifacts live")
releaseCmd.Flags().String("source-container-registry", "", "The container registry to pull images from for a dev release")
releaseCmd.Flags().String("packages-source-container-registry", "", "The container registry to pull packages images from for a dev release")
releaseCmd.Flags().String("release-container-registry", "", "The container registry that images wll be pushed to")
releaseCmd.Flags().Bool("dev-release", true, "Flag to indicate a dev release")
releaseCmd.Flags().Bool("bundle-release", true, "Flag to indicate a bundle release")
Expand Down
1 change: 0 additions & 1 deletion release/cli/pkg/assets/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type ManifestComponent struct {
}

type ImageTagConfiguration struct {
SourceLatestTagFromECR bool
NonProdSourceImageTagFormat string
ProdSourceImageTagFormat string
ReleaseImageTagFormat string
Expand Down
28 changes: 0 additions & 28 deletions release/cli/pkg/aws/ecr/ecr.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,34 +184,6 @@ func getLastestOCIShaTag(details []*ecr.ImageDetail) (string, string, error) {
return *latest.ImageTags[0], *latest.ImageDigest, nil
}

func GetLatestImageSha(ecrClient *ecr.ECR, repoName string) (string, error) {
imageDetails, err := DescribeImagesPaginated(ecrClient, &ecr.DescribeImagesInput{
RepositoryName: aws.String(repoName),
})
if len(imageDetails) == 0 {
return "", fmt.Errorf("no image details obtained: %v", err)
}
if err != nil {
return "", errors.Cause(err)
}

latest := &ecr.ImageDetail{}
latest.ImagePushedAt = &time.Time{}
for _, detail := range imageDetails {
if detail.ImagePushedAt == nil || detail.ImageDigest == nil || detail.ImageTags == nil || len(detail.ImageTags) == 0 || *detail.ImageManifestMediaType != "application/vnd.oci.image.manifest.v1+json" {
continue
}
if detail.ImagePushedAt != nil && latest.ImagePushedAt.Before(*detail.ImagePushedAt) {
latest = detail
}
}
// Check if latest is empty, and return error if that's the case.
if *latest.ImageTags[0] == "" {
return "", fmt.Errorf("error no images found")
}
return *latest.ImageTags[0], nil
}

// removeStringSlice removes a named string from a slice, without knowing it's index or it being ordered.
func removeStringSlice(l []*string, item string) []*string {
for i, other := range l {
Expand Down
10 changes: 5 additions & 5 deletions release/cli/pkg/bundles/package-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func GetPackagesBundle(r *releasetypes.ReleaseConfig, imageDigests releasetypes.
// If we can't find the build starting with our substring, we default to the original dev tag.
// If we do find the Tag in Private ECR, but it doesn't exist in Public ECR Copy the image over so the helm chart will work correctly.
if r.DevRelease && !r.DryRun {
Helmtag, Helmsha, err = ecr.FilterECRRepoByTagPrefix(r.SourceClients.ECR.EcrClient, "eks-anywhere-packages", "0.0.0", true)
Helmtag, Helmsha, err = ecr.FilterECRRepoByTagPrefix(r.SourceClients.Packages.EcrClient, "eks-anywhere-packages", "0.0.0", true)
if err != nil {
fmt.Printf("Error getting dev version helm tag EKS Anywhere package controller, using latest version %v", err)
}
Imagetag, Imagesha, err = ecr.FilterECRRepoByTagPrefix(r.SourceClients.ECR.EcrClient, "eks-anywhere-packages", "v0.0.0", true)
Imagetag, Imagesha, err = ecr.FilterECRRepoByTagPrefix(r.SourceClients.Packages.EcrClient, "eks-anywhere-packages", "v0.0.0", true)
if err != nil {
fmt.Printf("Error getting dev version Image tag EKS Anywhere package controller, using latest version %v", err)
}
Expand All @@ -69,12 +69,12 @@ func GetPackagesBundle(r *releasetypes.ReleaseConfig, imageDigests releasetypes.
}
if !PackageImage {
fmt.Printf("Did not find the required helm image in Public ECR... copying image: %v\n", fmt.Sprintf("%s/%s:%s", r.ReleaseContainerRegistry, "eks-anywhere-packages", Imagetag))
err := images.CopyToDestination(r.SourceClients.ECR.AuthConfig, r.ReleaseClients.ECRPublic.AuthConfig, fmt.Sprintf("%s/%s:%s", r.SourceContainerRegistry, "eks-anywhere-packages", Imagetag), fmt.Sprintf("%s/%s:%s", r.ReleaseContainerRegistry, "eks-anywhere-packages", Imagetag))
err := images.CopyToDestination(r.SourceClients.Packages.AuthConfig, r.ReleaseClients.ECRPublic.AuthConfig, fmt.Sprintf("%s/%s:%s", r.PackagesSourceContainerRegistry, "eks-anywhere-packages", Imagetag), fmt.Sprintf("%s/%s:%s", r.ReleaseContainerRegistry, "eks-anywhere-packages", Imagetag))
if err != nil {
fmt.Printf("Error copying dev EKS Anywhere package controller image, to ECR Public: %v", err)
}
}
Tokentag, TokenSha, err = ecr.FilterECRRepoByTagPrefix(r.SourceClients.ECR.EcrClient, "ecr-token-refresher", "v0.0.0", true)
Tokentag, TokenSha, err = ecr.FilterECRRepoByTagPrefix(r.SourceClients.Packages.EcrClient, "ecr-token-refresher", "v0.0.0", true)
if err != nil {
fmt.Printf("Error getting dev version Image tag EKS Anywhere package token refresher, using latest version %v", err)
}
Expand All @@ -84,7 +84,7 @@ func GetPackagesBundle(r *releasetypes.ReleaseConfig, imageDigests releasetypes.
}
if !TokenImage {
fmt.Printf("Did not find the required helm image in Public ECR... copying image: %v\n", fmt.Sprintf("%s/%s:%s", r.ReleaseContainerRegistry, "ecr-token-refresher", Tokentag))
err := images.CopyToDestination(r.SourceClients.ECR.AuthConfig, r.ReleaseClients.ECRPublic.AuthConfig, fmt.Sprintf("%s/%s:%s", r.SourceContainerRegistry, "ecr-token-refresher", Tokentag), fmt.Sprintf("%s/%s:%s", r.ReleaseContainerRegistry, "ecr-token-refresher", Tokentag))
err := images.CopyToDestination(r.SourceClients.Packages.AuthConfig, r.ReleaseClients.ECRPublic.AuthConfig, fmt.Sprintf("%s/%s:%s", r.PackagesSourceContainerRegistry, "ecr-token-refresher", Tokentag), fmt.Sprintf("%s/%s:%s", r.ReleaseContainerRegistry, "ecr-token-refresher", Tokentag))
if err != nil {
fmt.Printf("Error copying dev EKS Anywhere package token refresher image, to ECR Public: %v", err)
}
Expand Down
49 changes: 47 additions & 2 deletions release/cli/pkg/clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import (
)

type SourceClients struct {
S3 *SourceS3Clients
ECR *SourceECRClient
S3 *SourceS3Clients
ECR *SourceECRClient
Packages *SourceECRClient
}

type ReleaseClients struct {
Expand Down Expand Up @@ -86,6 +87,17 @@ func CreateDevReleaseClients(dryRun bool) (*SourceClients, *ReleaseClients, erro
return nil, nil, errors.Cause(err)
}

// Session for beta-pdx-packages
packagesSession, err := session.NewSessionWithOptions(session.Options{
Config: aws.Config{
Region: aws.String("us-west-2"),
},
Profile: "packages-beta",
})
if err != nil {
return nil, nil, errors.Cause(err)
}

// S3 client and uploader
s3Client := s3.New(pdxSession)
uploader := s3manager.NewUploader(pdxSession)
Expand All @@ -97,6 +109,13 @@ func CreateDevReleaseClients(dryRun bool) (*SourceClients, *ReleaseClients, erro
return nil, nil, errors.Cause(err)
}

// Get packages source ECR auth config
packagesECRClient := ecrsdk.New(packagesSession)
packagesSourceAuthConfig, err := ecr.GetAuthConfig(packagesECRClient)
if err != nil {
return nil, nil, errors.Cause(err)
}

// Get release ECR Public auth config
ecrPublicClient := ecrpublicsdk.New(iadSession)
releaseAuthConfig, err := ecrpublic.GetAuthConfig(ecrPublicClient)
Expand All @@ -113,6 +132,10 @@ func CreateDevReleaseClients(dryRun bool) (*SourceClients, *ReleaseClients, erro
EcrClient: ecrClient,
AuthConfig: sourceAuthConfig,
},
Packages: &SourceECRClient{
EcrClient: packagesECRClient,
AuthConfig: packagesSourceAuthConfig,
},
}

// Constructing release clients
Expand Down Expand Up @@ -146,6 +169,17 @@ func CreateStagingReleaseClients() (*SourceClients, *ReleaseClients, error) {
return nil, nil, errors.Cause(err)
}

// Session for beta-pdx-packages
packagesSession, err := session.NewSessionWithOptions(session.Options{
Config: aws.Config{
Region: aws.String("us-west-2"),
},
Profile: "packages-beta",
})
if err != nil {
return nil, nil, errors.Cause(err)
}

// Session for eks-a-artifact-beta-iad
releaseSession, err := session.NewSessionWithOptions(session.Options{
Config: aws.Config{
Expand All @@ -171,6 +205,13 @@ func CreateStagingReleaseClients() (*SourceClients, *ReleaseClients, error) {
return nil, nil, errors.Cause(err)
}

// Get packages source ECR auth config
packagesECRClient := ecrsdk.New(packagesSession)
packagesSourceAuthConfig, err := ecr.GetAuthConfig(packagesECRClient)
if err != nil {
return nil, nil, errors.Cause(err)
}

// Get release ECR Public auth config
ecrPublicClient := ecrpublicsdk.New(releaseSession)
releaseAuthConfig, err := ecrpublic.GetAuthConfig(ecrPublicClient)
Expand All @@ -187,6 +228,10 @@ func CreateStagingReleaseClients() (*SourceClients, *ReleaseClients, error) {
EcrClient: ecrClient,
AuthConfig: sourceAuthConfig,
},
Packages: &SourceECRClient{
EcrClient: packagesECRClient,
AuthConfig: packagesSourceAuthConfig,
},
}

// Constructing release clients
Expand Down
17 changes: 13 additions & 4 deletions release/cli/pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ func NewHelm() (*helmDriver, error) {
}

func GetHelmDest(d *helmDriver, r *releasetypes.ReleaseConfig, ReleaseImageURI, assetName string) (string, error) {
fmt.Printf("Getting Helm destination folder for %s\n", assetName)
var chartPath string
var err error

err = d.HelmRegistryLogin(r, "source")
sourceRemoteType := "source"
if assetName == "eks-anywhere-packages" || assetName == "ecr-token-refresher" || assetName == "credential-provider-package" {
sourceRemoteType = "packages"
}
err := d.HelmRegistryLogin(r, sourceRemoteType)
if err != nil {
return "", fmt.Errorf("logging into the source registry: %w", err)
}
Expand All @@ -83,9 +87,9 @@ func GetHelmDest(d *helmDriver, r *releasetypes.ReleaseConfig, ReleaseImageURI,
return "", fmt.Errorf("pulling the helm chart: %w", err)
}

err = d.HelmRegistryLogout(r, "source")
err = d.HelmRegistryLogout(r, sourceRemoteType)
if err != nil {
return "", fmt.Errorf("logging out of the source registry: %w", err)
return "", fmt.Errorf("logging out of the %s registry: %w", sourceRemoteType, err)
}

pwd, err := os.Getwd()
Expand Down Expand Up @@ -189,6 +193,9 @@ func (d *helmDriver) HelmRegistryLogin(r *releasetypes.ReleaseConfig, remoteType
if remoteType == "source" {
authConfig = r.SourceClients.ECR.AuthConfig
remote = r.SourceContainerRegistry
} else if remoteType == "packages" {
authConfig = r.SourceClients.Packages.AuthConfig
remote = r.PackagesSourceContainerRegistry
} else if remoteType == "destination" {
authConfig = r.ReleaseClients.ECRPublic.AuthConfig
remote = r.ReleaseContainerRegistry
Expand All @@ -206,6 +213,8 @@ func (d *helmDriver) HelmRegistryLogout(r *releasetypes.ReleaseConfig, remoteTyp
var remote string
if remoteType == "source" {
remote = r.SourceContainerRegistry
} else if remoteType == "packages" {
remote = r.PackagesSourceContainerRegistry
} else if remoteType == "destination" {
remote = r.ReleaseContainerRegistry
}
Expand Down
24 changes: 10 additions & 14 deletions release/cli/pkg/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,31 +127,24 @@ func CopyToDestination(sourceAuthConfig, releaseAuthConfig *docker.AuthConfigura
func GetSourceImageURI(r *releasetypes.ReleaseConfig, name, repoName string, tagOptions map[string]string, imageTagConfiguration assettypes.ImageTagConfiguration, trimVersionSignifier, hasSeparateTagPerReleaseBranch bool) (string, string, error) {
var sourceImageUri string
var latestTag string
var err error
sourcedFromBranch := r.BuildRepoBranchName
sourceContainerRegistry := r.SourceContainerRegistry
if repoName == "eks-anywhere-packages" || repoName == "ecr-token-refresher" || repoName == "credential-provider-package" {
sourceContainerRegistry = r.PackagesSourceContainerRegistry
}
if r.DevRelease || r.ReleaseEnvironment == "development" {
latestTag = artifactutils.GetLatestUploadDestination(r.BuildRepoBranchName)
if imageTagConfiguration.SourceLatestTagFromECR && !r.DryRun {
if (strings.Contains(name, "eks-anywhere-packages") || strings.Contains(name, "ecr-token-refresher")) && r.BuildRepoBranchName != "main" {
latestTag, _, err = ecr.FilterECRRepoByTagPrefix(r.SourceClients.ECR.EcrClient, repoName, "v0.0.0", false)
} else {
latestTag, err = ecr.GetLatestImageSha(r.SourceClients.ECR.EcrClient, repoName)
}
if err != nil {
return "", "", errors.Cause(err)
}
}
if imageTagConfiguration.NonProdSourceImageTagFormat != "" {
sourceImageTagPrefix := generateFormattedTagPrefix(imageTagConfiguration.NonProdSourceImageTagFormat, tagOptions)
sourceImageUri = fmt.Sprintf("%s/%s:%s-%s",
r.SourceContainerRegistry,
sourceContainerRegistry,
repoName,
sourceImageTagPrefix,
latestTag,
)
} else {
sourceImageUri = fmt.Sprintf("%s/%s:%s",
r.SourceContainerRegistry,
sourceContainerRegistry,
repoName,
latestTag,
)
Expand All @@ -164,7 +157,10 @@ func GetSourceImageURI(r *releasetypes.ReleaseConfig, name, repoName string, tag
}
if !r.DryRun {
sourceEcrAuthConfig := r.SourceClients.ECR.AuthConfig
err := PollForExistence(r.DevRelease, sourceEcrAuthConfig, sourceImageUri, r.SourceContainerRegistry, r.ReleaseEnvironment, r.BuildRepoBranchName)
if repoName == "eks-anywhere-packages" || repoName == "ecr-token-refresher" || repoName == "credential-provider-package" {
sourceEcrAuthConfig = r.SourceClients.Packages.AuthConfig
}
err := PollForExistence(r.DevRelease, sourceEcrAuthConfig, sourceImageUri, sourceContainerRegistry, r.ReleaseEnvironment, r.BuildRepoBranchName)
if err != nil {
if r.BuildRepoBranchName != "main" {
fmt.Printf("Tag corresponding to %s branch not found for %s image. Using image artifact from main\n", r.BuildRepoBranchName, repoName)
Expand Down
Loading

0 comments on commit a528959

Please sign in to comment.