overleaf/services/web/bin/cdn_upload
Jakob Ackermann cc78541714 Merge pull request #5670 from overleaf/jpa-cdn-pre-compress
[web] cdn_upload: compress assets prior to uploading them to GCS

GitOrigin-RevId: a9b0970beb124d20bd2ffe21d30a674ffafd6258
2021-11-04 09:03:32 +00:00

38 lines
921 B
Bash
Executable file

#!/bin/bash
set -e
function upload_into_bucket() {
bucket=$1
# stylesheets
bin/cdn_upload_batch 'text/css' "$bucket" '.css' \
-x '.+(?<!\.css)$' &
# javascript files
bin/cdn_upload_batch 'application/javascript' "$bucket" '.js' \
-x '.+(?<!\.js)$' &
# the rest
bin/cdn_upload_batch '-' "$bucket" '-' \
-x '.+\.(css|js)$' &
wait
}
# Upload to staging CDN if branch is either 'master' or 'staging-master' or main variants
if [[ "$BRANCH_NAME" == "master" || "$BRANCH_NAME" == "staging-master" || "$BRANCH_NAME" == "main" || "$BRANCH_NAME" == "staging-main" ]]; then
tar --directory=/tmp/ -xf build.tar
# delete source maps
find /tmp/public -name '*.js.map' -delete
bin/compress_assets
upload_into_bucket $CDN_STAG
# Only upload to production CDN if branch is
if [[ "$BRANCH_NAME" == "master" || "$BRANCH_NAME" == "main" ]]; then
upload_into_bucket $CDN_PROD
fi
fi