From 904b38820aee23d90ce04426ebd84b0eaf4c983a Mon Sep 17 00:00:00 2001 From: Heinrich Lee Yu Date: Thu, 6 Jun 2019 15:53:21 +0800 Subject: Tar assets-compile-cache cache files Speeds up zipping and uploading of cache --- .gitlab/ci/frontend.gitlab-ci.yml | 19 +++++++++++++------ scripts/assets-compile-cache/archive | 10 ++++++++++ scripts/assets-compile-cache/clean-old-assets | 6 ++++++ scripts/assets-compile-cache/extract | 9 +++++++++ scripts/clean-old-cached-assets | 6 ------ 5 files changed, 38 insertions(+), 12 deletions(-) create mode 100755 scripts/assets-compile-cache/archive create mode 100755 scripts/assets-compile-cache/clean-old-assets create mode 100755 scripts/assets-compile-cache/extract delete mode 100755 scripts/clean-old-cached-assets diff --git a/.gitlab/ci/frontend.gitlab-ci.yml b/.gitlab/ci/frontend.gitlab-ci.yml index fd5733593ef..cc7e20ba9bc 100644 --- a/.gitlab/ci/frontend.gitlab-ci.yml +++ b/.gitlab/ci/frontend.gitlab-ci.yml @@ -1,11 +1,18 @@ .assets-compile-cache: &assets-compile-cache cache: - key: "assets-compile:vendor_ruby:.yarn-cache:tmp_cache_assets_sprockets:v5" + key: "assets-compile-compressed:vendor_ruby:.yarn-cache:tmp_cache_assets_sprockets:v1" paths: - - vendor/ruby/ - - .yarn-cache/ - - tmp/cache/assets/sprockets + - cache_archives policy: pull-push + before_script: + - scripts/assets-compile-cache/extract + - date + - source scripts/utils.sh + - source scripts/prepare_build.sh + - date + after_script: + - scripts/assets-compile-cache/archive + - date .use-pg: &use-pg services: @@ -37,7 +44,7 @@ gitlab:assets:compile: - free -m - retry bundle exec rake gitlab:assets:compile - time scripts/build_assets_image - - scripts/clean-old-cached-assets + - scripts/assets-compile-cache/clean-old-assets - rm -f /etc/apt/sources.list.d/google*.list # We don't need to update Chrome here # Play dependent manual jobs - install_api_client_dependencies_with_apt @@ -68,7 +75,7 @@ compile-assets: - retry yarn install --frozen-lockfile --cache-folder .yarn-cache - free -m - retry bundle exec rake gitlab:assets:compile - - scripts/clean-old-cached-assets + - scripts/assets-compile-cache/clean-old-assets variables: # we override the max_old_space_size to prevent OOM errors NODE_OPTIONS: --max_old_space_size=3584 diff --git a/scripts/assets-compile-cache/archive b/scripts/assets-compile-cache/archive new file mode 100755 index 00000000000..85b145ec3b4 --- /dev/null +++ b/scripts/assets-compile-cache/archive @@ -0,0 +1,10 @@ +#!/bin/bash + +echo "Archiving cache files..." + +mkdir -p cache_archives +[ -d vendor/ruby ] && tar -czf cache_archives/vendor-ruby.tar.gz vendor/ruby +[ -d .yarn-cache ] && tar -czf cache_archives/yarn-cache.tar.gz .yarn-cache +[ -d tmp/cache/assets/sprockets ] && tar -czf cache_archives/tmp-cache-assets-sprockets.tar.gz tmp/cache/assets/sprockets + +echo "Done!" diff --git a/scripts/assets-compile-cache/clean-old-assets b/scripts/assets-compile-cache/clean-old-assets new file mode 100755 index 00000000000..8bdd3a9cdb6 --- /dev/null +++ b/scripts/assets-compile-cache/clean-old-assets @@ -0,0 +1,6 @@ +#!/bin/bash + +# Clean up cached files that are older than 4 days +find tmp/cache/assets/sprockets/ -type f -mtime +4 -execdir rm -- "{}" \; + +du -d 0 -h tmp/cache/assets/sprockets | cut -f1 | xargs -I % echo "tmp/cache/assets/sprockets/ is currently %" diff --git a/scripts/assets-compile-cache/extract b/scripts/assets-compile-cache/extract new file mode 100755 index 00000000000..aebf92a9347 --- /dev/null +++ b/scripts/assets-compile-cache/extract @@ -0,0 +1,9 @@ +#!/bin/bash + +echo "Extracting cache files..." + +[ -f cache_archives/vendor-ruby.tar.gz ] && tar -xzf cache_archives/vendor-ruby.tar.gz +[ -f cache_archives/yarn-cache.tar.gz ] && tar -xzf cache_archives/yarn-cache.tar.gz +[ -f cache_archives/tmp-cache-assets-sprockets.tar.gz ] && tar -xzf cache_archives/tmp-cache-assets-sprockets.tar.gz + +echo "Done!" diff --git a/scripts/clean-old-cached-assets b/scripts/clean-old-cached-assets deleted file mode 100755 index 8bdd3a9cdb6..00000000000 --- a/scripts/clean-old-cached-assets +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -# Clean up cached files that are older than 4 days -find tmp/cache/assets/sprockets/ -type f -mtime +4 -execdir rm -- "{}" \; - -du -d 0 -h tmp/cache/assets/sprockets | cut -f1 | xargs -I % echo "tmp/cache/assets/sprockets/ is currently %" -- cgit v1.2.1