mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #3235 from overleaf/jpa-cdn-upload-set-charset
[bin/cdn_upload] set the charset for stylesheets and javascript files GitOrigin-RevId: f93565ef9475595de64611e04e3f4eca118f5218
This commit is contained in:
parent
12b407c18b
commit
473ff70e99
1 changed files with 45 additions and 2 deletions
|
@ -1,6 +1,49 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
function upload_with_content_type() {
|
||||
content_type=$1
|
||||
bucket=$2
|
||||
shift 2
|
||||
content_type_options=""
|
||||
if [[ "$content_type" != "-" ]]; then
|
||||
content_type_options="-h Content-Type:${content_type};charset=utf-8"
|
||||
fi
|
||||
|
||||
# DOCS for gsutil -- it does not have long command line flags!
|
||||
## global flags
|
||||
# -h NAME:VALUE add header, can occur multiples times
|
||||
# -m upload with multiple threads
|
||||
## rsync flags
|
||||
# -r traverse into directories recursively
|
||||
# -x Python regex for excluding files from the sync
|
||||
gsutil \
|
||||
-h "Cache-Control:public, max-age=31536000" \
|
||||
${content_type_options} \
|
||||
-m \
|
||||
rsync \
|
||||
-r \
|
||||
"$@" \
|
||||
"/tmp/public/" \
|
||||
"${bucket}/public/"
|
||||
}
|
||||
function upload_into_bucket() {
|
||||
bucket=$1
|
||||
|
||||
# stylesheets
|
||||
upload_with_content_type 'text/css' "$bucket" \
|
||||
-x '.+(?<!\.css)$'
|
||||
|
||||
# javascript files
|
||||
upload_with_content_type 'application/javascript' "$bucket" \
|
||||
-x '.+(?<!\.js)$'
|
||||
|
||||
# the rest
|
||||
upload_with_content_type '-' "$bucket" \
|
||||
-x '.+\.(css|js)$'
|
||||
|
||||
}
|
||||
|
||||
# Upload to staging CDN if branch is either 'master' or 'staging-master'
|
||||
if [[ "$BRANCH_NAME" == "master" || "$BRANCH_NAME" == "staging-master" ]]; then
|
||||
tar --directory=/tmp/ -xf build.tar
|
||||
|
@ -8,10 +51,10 @@ if [[ "$BRANCH_NAME" == "master" || "$BRANCH_NAME" == "staging-master" ]]; then
|
|||
# delete source maps
|
||||
find /tmp/public -name '*.js.map' -delete
|
||||
|
||||
gsutil -h "Cache-Control:public, max-age=31536000" -m cp -r /tmp/public $CDN_STAG
|
||||
upload_into_bucket $CDN_STAG
|
||||
# Only upload to production CDN if branch is
|
||||
if [[ "$BRANCH_NAME" == "master" ]]; then
|
||||
gsutil -h "Cache-Control:public, max-age=31536000" -m cp -r /tmp/public $CDN_PROD
|
||||
upload_into_bucket $CDN_PROD
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in a new issue