From cc7854171493b70f355cf8e3ae0fc2a488966de8 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Wed, 3 Nov 2021 12:04:29 +0100 Subject: [PATCH] Merge pull request #5670 from overleaf/jpa-cdn-pre-compress [web] cdn_upload: compress assets prior to uploading them to GCS GitOrigin-RevId: a9b0970beb124d20bd2ffe21d30a674ffafd6258 --- services/web/bin/cdn_upload | 41 +++++---------------- services/web/bin/cdn_upload_batch | 44 +++++++++++++++++++++++ services/web/bin/compress_assets | 14 ++++++++ services/web/bin/compress_batch_of_assets | 16 +++++++++ 4 files changed, 83 insertions(+), 32 deletions(-) create mode 100755 services/web/bin/cdn_upload_batch create mode 100755 services/web/bin/compress_assets create mode 100755 services/web/bin/compress_batch_of_assets diff --git a/services/web/bin/cdn_upload b/services/web/bin/cdn_upload index cdd3df2f50..00b9eaa48d 100755 --- a/services/web/bin/cdn_upload +++ b/services/web/bin/cdn_upload @@ -1,47 +1,22 @@ #!/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 '.+(? "$file_gzipped" + + before=$(stat -c%s "$file") + after=$(stat -c%s "$file_gzipped") + if [[ "$after" -ge "$before" ]]; then + rm "$file_gzipped" + else + rm "$file" + fi +done