in release/cli/pkg/operations/download.go [87:189]
func handleArchiveDownload(_ context.Context, r *releasetypes.ReleaseConfig, artifact releasetypes.Artifact, s3Retrier *retrier.Retrier, s3Client *s3sdk.S3, s3Downloader *s3manager.Downloader) error {
sourceS3Prefix := artifact.Archive.SourceS3Prefix
sourceS3Key := artifact.Archive.SourceS3Key
artifactPath := artifact.Archive.ArtifactPath
objectKey := filepath.Join(sourceS3Prefix, sourceS3Key)
objectLocalFilePath := filepath.Join(artifactPath, sourceS3Key)
fmt.Printf("Archive - %s\n", objectKey)
if r.DryRun && artifact.Archive.ImageFormat != "tarball" {
fmt.Println("Skipping OS image downloads in dry-run mode")
} else {
err := s3Retrier.Retry(func() error {
keyExists, err := s3.KeyExists(s3Client, r.SourceBucket, objectKey, artifact.Archive.Private)
if err != nil {
return fmt.Errorf("checking if object [%s] is present in S3 bucket: %v", objectKey, err)
}
if !keyExists {
return fmt.Errorf("requested object not found: %v", objectKey)
}
return nil
})
if err != nil {
if r.BuildRepoBranchName != "main" {
var latestSourceS3PrefixFromMain string
fmt.Printf("Artifact corresponding to %s branch not found for %s archive. Using artifact from main\n", r.BuildRepoBranchName, sourceS3Key)
if strings.Contains(sourceS3Key, "eksctl-anywhere") {
latestSourceS3PrefixFromMain = strings.NewReplacer(r.CliRepoBranchName, "latest").Replace(sourceS3Prefix)
} else {
gitTagFromMain, err := filereader.ReadGitTag(artifact.Archive.ProjectPath, r.BuildRepoSource, "main")
if err != nil {
return errors.Cause(err)
}
latestSourceS3PrefixFromMain = strings.NewReplacer(r.BuildRepoBranchName, "latest", artifact.Archive.GitTag, gitTagFromMain).Replace(sourceS3Prefix)
}
objectKey = filepath.Join(latestSourceS3PrefixFromMain, sourceS3Key)
} else {
return fmt.Errorf("retries exhausted waiting for source archive [%s] to be available for download: %v", objectKey, err)
}
}
err = s3.DownloadFile(objectLocalFilePath, r.SourceBucket, objectKey, s3Downloader, artifact.Archive.Private)
if err != nil {
return fmt.Errorf("downloading archive file [%s] from S3: %v", objectKey, err)
}
// Download checksum files for the archive
checksumExtensions := []string{
".sha256",
".sha512",
}
// Adding a special case for tinkerbell/hook project.
// The project builds linux kernel files that are not stored as tarballs and currently do not have SHA checksums.
// TODO(pokearu): Add logic to generate SHA for hook project
if artifact.Archive.ProjectPath == constants.HookProjectPath {
checksumExtensions = []string{}
}
for _, extension := range checksumExtensions {
objectShasumFileName := fmt.Sprintf("%s%s", sourceS3Key, extension)
objectShasumFileKey := filepath.Join(sourceS3Prefix, objectShasumFileName)
objectShasumFileLocalFilePath := filepath.Join(artifactPath, objectShasumFileName)
fmt.Printf("Checksum file - %s\n", objectShasumFileKey)
err := s3Retrier.Retry(func() error {
keyExists, err := s3.KeyExists(s3Client, r.SourceBucket, objectShasumFileKey, artifact.Archive.Private)
if err != nil {
return fmt.Errorf("checking if object [%s] is present in S3 bucket: %v", objectShasumFileKey, err)
}
if !keyExists {
return fmt.Errorf("requested object not found: %v", objectShasumFileKey)
}
return nil
})
if err != nil {
if r.BuildRepoBranchName != "main" {
var latestSourceS3PrefixFromMain string
fmt.Printf("Artifact corresponding to %s branch not found for %s archive. Using artifact from main\n", r.BuildRepoBranchName, sourceS3Key)
if strings.Contains(sourceS3Key, "eksctl-anywhere") {
latestSourceS3PrefixFromMain = strings.NewReplacer(r.CliRepoBranchName, "latest").Replace(sourceS3Prefix)
} else {
gitTagFromMain, err := filereader.ReadGitTag(artifact.Archive.ProjectPath, r.BuildRepoSource, "main")
if err != nil {
return errors.Cause(err)
}
latestSourceS3PrefixFromMain = strings.NewReplacer(r.BuildRepoBranchName, "latest", artifact.Archive.GitTag, gitTagFromMain).Replace(sourceS3Prefix)
}
objectShasumFileKey = filepath.Join(latestSourceS3PrefixFromMain, objectShasumFileName)
} else {
return fmt.Errorf("retries exhausted waiting for source checksum file [%s] to be available for download: %v", objectShasumFileKey, err)
}
}
err = s3.DownloadFile(objectShasumFileLocalFilePath, r.SourceBucket, objectShasumFileKey, s3Downloader, artifact.Archive.Private)
if err != nil {
return fmt.Errorf("downloading checksum file [%s] from S3: %v", objectShasumFileKey, err)
}
}
}
return nil
}