From 3740589850303f67cf4fd17b65c4e39a7c1f9391 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Tue, 12 Jan 2021 10:08:59 -0800 Subject: [PATCH 1/5] Cache rust artifacts only when cargo files are detected This way we don't turn the `target` directory into a reserved directory if people are not using rust. --- run-build-functions.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/run-build-functions.sh b/run-build-functions.sh index 6d17bacb..1f3efa79 100755 --- a/run-build-functions.sh +++ b/run-build-functions.sh @@ -685,9 +685,13 @@ cache_artifacts() { cache_home_directory ".boot" "boot dependencies" cache_home_directory ".composer" "composer dependencies" cache_home_directory ".homebrew-cache", "homebrew cache" - cache_home_directory ".rustup" "rust rustup cache" - cache_home_directory ".cargo/registry" "rust cargo registry cache" - cache_home_directory ".cargo/bin" "rust cargo bin cache" + + if if [ -f Cargo.toml ] || [ -f Cargo.lock ] + then + cache_home_directory ".rustup" "rust rustup cache" + cache_home_directory ".cargo/registry" "rust cargo registry cache" + cache_home_directory ".cargo/bin" "rust cargo bin cache" + fi # Don't follow the Go import path or we'll store # the origin repo twice. From f009c3b090cf61c8cfb76dc6826f1d5729f39731 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Tue, 12 Jan 2021 10:27:49 -0800 Subject: [PATCH 2/5] Update run-build-functions.sh Co-authored-by: Vivian Brown --- run-build-functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-build-functions.sh b/run-build-functions.sh index 1f3efa79..1f0eaf8d 100755 --- a/run-build-functions.sh +++ b/run-build-functions.sh @@ -686,7 +686,7 @@ cache_artifacts() { cache_home_directory ".composer" "composer dependencies" cache_home_directory ".homebrew-cache", "homebrew cache" - if if [ -f Cargo.toml ] || [ -f Cargo.lock ] + if [ -f Cargo.toml ] || [ -f Cargo.lock ] then cache_home_directory ".rustup" "rust rustup cache" cache_home_directory ".cargo/registry" "rust cargo registry cache" From 4dbcb17453c3531da43fdd5814c3a717feffafeb Mon Sep 17 00:00:00 2001 From: David Calavera Date: Tue, 12 Jan 2021 10:29:46 -0800 Subject: [PATCH 3/5] Cache the target directory only when a cargo file exists. Signed-off-by: David Calavera --- run-build-functions.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/run-build-functions.sh b/run-build-functions.sh index 1f0eaf8d..0faaaab1 100755 --- a/run-build-functions.sh +++ b/run-build-functions.sh @@ -675,7 +675,11 @@ cache_artifacts() { cache_cwd_directory ".venv" "python virtualenv" cache_cwd_directory ".build" "swift build" cache_cwd_directory ".netlify/plugins" "build plugins" - cache_cwd_directory "target" "rust compile output" + + if [ -f Cargo.toml ] || [ -f Cargo.lock ] + then + cache_cwd_directory "target" "rust compile output" + fi cache_home_directory ".yarn_cache" "yarn cache" cache_home_directory ".cache/pip" "pip cache" From ebc2ba70c2b710bf047bee80ee0b49068a25c9ee Mon Sep 17 00:00:00 2001 From: David Calavera Date: Tue, 12 Jan 2021 10:31:57 -0800 Subject: [PATCH 4/5] Copy target directory using reflinks. This allows keeping both directories until the deploy is completed, while keeping the fast nature of moving things around. Signed-off-by: David Calavera --- run-build-functions.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/run-build-functions.sh b/run-build-functions.sh index 0faaaab1..748dc5de 100755 --- a/run-build-functions.sh +++ b/run-build-functions.sh @@ -678,7 +678,7 @@ cache_artifacts() { if [ -f Cargo.toml ] || [ -f Cargo.lock ] then - cache_cwd_directory "target" "rust compile output" + cache_cwd_directory_fast_copy "target" "rust compile output" fi cache_home_directory ".yarn_cache" "yarn cache" @@ -756,6 +756,17 @@ move_cache() { fi } +fast_copy_cache() { + local src=$1 + local dst=$2 + if [ -d $src ] + then + echo "Started $3" + cp --reflink=always $src $dst + echo "Finished $3" + fi +} + restore_home_cache() { move_cache "$NETLIFY_CACHE_DIR/$1" "$HOME/$1" "restoring cached $2" } @@ -772,6 +783,10 @@ cache_cwd_directory() { move_cache "$PWD/$1" "$NETLIFY_CACHE_DIR/$1" "saving $2" } +cache_cwd_directory_fast_copy() { + fast_copy_cache "$PWD/$1" "$NETLIFY_CACHE_DIR/$1" "saving $2" +} + install_missing_commands() { if [[ $BUILD_COMMAND_PARSER == *"grunt"* ]] then From 4d33fddd39a1c53a380ca346427ef57987172b9a Mon Sep 17 00:00:00 2001 From: David Calavera Date: Wed, 13 Jan 2021 11:08:46 -0800 Subject: [PATCH 5/5] Cache .rustup regardless of whether there are cargo files or not. Signed-off-by: David Calavera --- run-build-functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-build-functions.sh b/run-build-functions.sh index 748dc5de..2a04e62e 100755 --- a/run-build-functions.sh +++ b/run-build-functions.sh @@ -689,10 +689,10 @@ cache_artifacts() { cache_home_directory ".boot" "boot dependencies" cache_home_directory ".composer" "composer dependencies" cache_home_directory ".homebrew-cache", "homebrew cache" + cache_home_directory ".rustup" "rust rustup cache" if [ -f Cargo.toml ] || [ -f Cargo.lock ] then - cache_home_directory ".rustup" "rust rustup cache" cache_home_directory ".cargo/registry" "rust cargo registry cache" cache_home_directory ".cargo/bin" "rust cargo bin cache" fi