Skip to content

Commit

Permalink
Merge pull request coreos#1038 from jlebon/pr/releases-max-age
Browse files Browse the repository at this point in the history
plume: upload release index with max-age=300
  • Loading branch information
jlebon authored Aug 2, 2019
2 parents 40cf53d + 150a742 commit 7ebd0ca
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/ore/aws/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func runUpload(cmd *cobra.Command, args []string) error {
}
defer f.Close()

err = API.UploadObject(f, s3BucketName, s3ObjectPath, uploadForce, "", "")
err = API.UploadObject(f, s3BucketName, s3ObjectPath, uploadForce)
if err != nil {
fmt.Fprintf(os.Stderr, "Error uploading: %v\n", err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/plume/prerelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func awsUploadToPartition(spec *channelSpec, part *awsPartitionSpec, imageName,

if snapshot == nil {
plog.Printf("Creating S3 object %v...", s3ObjectURL)
err = api.UploadObject(f, part.Bucket, s3ObjectPath, false, "", "")
err = api.UploadObject(f, part.Bucket, s3ObjectPath, false)
if err != nil {
return nil, nil, fmt.Errorf("Error uploading: %v", err)
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/plume/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func modifyReleaseMetadataIndex(spec *fcosChannelSpec, commitId string) {

releaseFile, err := api.DownloadFile(spec.Bucket, releasePath)
if err != nil {
plog.Fatalf("downloading release metadata: %v", err)
plog.Fatalf("downloading release metadata at %s: %v", releasePath, err)
}
defer releaseFile.Close()

Expand Down Expand Up @@ -612,7 +612,9 @@ func modifyReleaseMetadataIndex(spec *fcosChannelSpec, commitId string) {
plog.Fatalf("marshalling release metadata json: %v", err)
}

err = api.UploadObject(bytes.NewReader(out), spec.Bucket, path, true, specPolicy, aws.ContentTypeJSON)
// we don't want this to be cached for very long so that e.g. Cincinnati picks it up quickly
var releases_max_age = 60 * 5
err = api.UploadObjectExt(bytes.NewReader(out), spec.Bucket, path, true, specPolicy, aws.ContentTypeJSON, releases_max_age)
if err != nil {
plog.Fatalf("uploading release metadata json: %v", err)
}
Expand Down
10 changes: 9 additions & 1 deletion platform/api/aws/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ func s3IsNotFound(err error) bool {
}

// UploadObject uploads an object to S3
func (a *API) UploadObject(r io.Reader, bucket, path string, force bool, policy string, contentType string) error {
func (a *API) UploadObject(r io.Reader, bucket, path string, force bool) error {
return a.UploadObjectExt(r, bucket, path, force, "", "", -1)
}

// UploadObjectExt uploads an object to S3 with more control over options.
func (a *API) UploadObjectExt(r io.Reader, bucket, path string, force bool, policy string, contentType string, max_age int) error {
s3uploader := s3manager.NewUploaderWithClient(a.s3)

if !force {
Expand All @@ -73,6 +78,9 @@ func (a *API) UploadObject(r io.Reader, bucket, path string, force bool, policy
Key: aws.String(path),
ACL: aws.String(policy),
}
if max_age >= 0 {
input.CacheControl = aws.String(fmt.Sprintf("max-age=%d", max_age))
}
if contentType != "" {
input.ContentType = aws.String(contentType)
}
Expand Down

0 comments on commit 7ebd0ca

Please sign in to comment.