Skip to content

Commit

Permalink
Copy latest MSI package file instead of using redirects... again
Browse files Browse the repository at this point in the history
S3 redirects don't work with awscli either, it's a CloudFront caching
issue. :(
  • Loading branch information
Ivan Mirić committed Apr 8, 2021
1 parent b81ec2c commit bc39f28
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packaging/bin/create-msi-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ sync_to_s3() ***REMOVED***
log "Syncing to S3 ..."
aws s3 sync --no-progress --delete "$***REMOVED***REPODIR***REMOVED***/" "s3://$***REMOVED***S3PATH***REMOVED***/"

# Update redirect to the latest package.
latest="$(find "$REPODIR" -name '*.msi' -printf '%P\n' | sort | tail -1)"
aws s3 cp --no-progress --website-redirect="/msi/$***REMOVED***latest***REMOVED***" \
--content-type='application/x-msi' --cache-control='max-age=60,must-revalidate' \
"$REPODIR/k6-latest-amd64.msi" "s3://$***REMOVED***S3PATH***REMOVED***/k6-latest-amd64.msi"

# Set a short cache expiration for index files.
aws s3 cp --no-progress --recursive --exclude='*' --include='*.html' \
# Set a short cache expiration for index files and the latest MSI package.
aws s3 cp --no-progress --recursive --exclude='*' \
--include='*.html' \
--cache-control='max-age=60,must-revalidate' \
--content-type='text/html' \
--metadata-directive=REPLACE \
"s3://$***REMOVED***S3PATH***REMOVED***" "s3://$***REMOVED***S3PATH***REMOVED***"
aws s3 cp --no-progress \
--cache-control='max-age=60,must-revalidate' \
--content-type='application/x-msi' \
--metadata-directive=REPLACE \
"s3://$***REMOVED***S3PATH***REMOVED***/k6-latest-amd64.msi" "s3://$***REMOVED***S3PATH***REMOVED***/k6-latest-amd64.msi"
***REMOVED***

mkdir -p "$REPODIR"
Expand All @@ -52,11 +52,14 @@ aws s3 sync --no-progress --exclude='*' --include='*.msi' "s3://$***REMOVED***S3

# Copy the new packages in
find "$PKGDIR" -name "*.msi" -type f -print0 | xargs -r0 cp -t "$REPODIR"
# Add placeholder for latest package redirect
touch "$REPODIR/k6-latest-amd64.msi"

delete_old_pkgs "$REPODIR"

# Update the latest package. This could be done with S3 redirects, but
# CloudFront caches redirects aggressively and I wasn't able to invalidate it.
latest="$(find "$REPODIR" -name '*.msi' -printf '%P\n' | sort | tail -1)"
cp -p "$***REMOVED***REPODIR***REMOVED***/$***REMOVED***latest***REMOVED***" "$***REMOVED***REPODIR***REMOVED***/k6-latest-amd64.msi"

log "Generating index.html ..."
(cd "$REPODIR" && generate_index.py -r)

Expand Down

0 comments on commit bc39f28

Please sign in to comment.