Skip to content

Commit 09c7ecd

Browse files
committed
Cirrus: Groom rust cache before updating
Port of containers/netavark#553 Signed-off-by: Chris Evich <[email protected]>
1 parent d628692 commit 09c7ecd

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

.cirrus.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ build_task:
3737
image_name: "${FEDORA_NETAVARK_IMAGE}"
3838
cargo_cache: &cargo_cache
3939
folder: "$CARGO_HOME"
40-
fingerprint_key: "cargo_v1_${DEST_BRANCH}" # Cache for branch + PRs
40+
fingerprint_script: echo -e "cargo_v3_${DEST_BRANCH}_amd64\n---\n$(<Cargo.lock)\n---\n$(<Cargo.toml)"
4141
reupload_on_changes: true
4242
targets_cache: &targets_cache
4343
folder: "$CARGO_TARGET_DIR"
44-
fingerprint_key: "targets_v1_${CIRRUS_BUILD_ID}" # Cache only within same build
44+
fingerprint_script: echo -e "targets_v3_${CIRRUS_TAG}${DEST_BRANCH}${CIRRUS_PR}_amd64\n---\n$(<Cargo.lock)\n---\n$(<Cargo.toml)"
4545
reupload_on_changes: true
4646
bin_cache: &bin_cache
4747
# This simply prevents rebuilding bin/aardvark-dns* or every subsequent task.
@@ -50,6 +50,8 @@ build_task:
5050
reupload_on_changes: true
5151
setup_script: &setup "$SCRIPT_BASE/setup.sh $CIRRUS_TASK_NAME"
5252
main_script: &main "$SCRIPT_BASE/runner.sh $CIRRUS_TASK_NAME"
53+
# N/B: This script comes from `main` on the netavark repo
54+
cache_grooming_script: &groom bash "$SCRIPT_BASE/netavark_cache_groom.sh"
5355
upload_caches: [ "cargo", "targets", "bin" ]
5456

5557

@@ -63,15 +65,16 @@ build_task:
6365
# architecture: arm64 # CAUTION: This has to be "arm64", not aarch64.
6466
# cargo_cache: &cargo_cache_aarch64
6567
# <<: *cargo_cache
66-
# fingerprint_key: "cargo_v1_${DEST_BRANCH}_aarch64"
68+
# fingerprint_script: echo -e "cargo_v3_${DEST_BRANCH}_aarch64\n---\n$(<Cargo.lock)\n---\n$(<Cargo.toml)"
6769
# targets_cache: &targets_cache_aarch64
6870
# <<: *targets_cache
69-
# fingerprint_key: "cargo_v1_${DEST_BRANCH}_aarch64"
71+
# fingerprint_script: echo -e "targets_v3_${CIRRUS_TAG}${DEST_BRANCH}${CIRRUS_PR}_aarch64\n---\n$(<Cargo.lock)\n---\n$(<Cargo.toml)"
7072
# bin_cache: &bin_cache_aarch64
7173
# <<: *bin_cache
7274
# fingerprint_key: "cargo_v1_${DEST_BRANCH}_aarch64"
7375
# setup_script: *setup
7476
# main_script: *main
77+
# cache_grooming_script: *groom
7578
# upload_caches: [ "cargo", "targets", "bin" ]
7679

7780

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
#
3+
# This script is intended to be run from Cirrus-CI to prepare the
4+
# rust targets cache for re-use during subsequent runs. This mainly
5+
# involves removing files and directories which change frequently
6+
# but are cheap/quick to regenerate - i.e. prevent "cache-flapping".
7+
# Any other use of this script is not supported and may cause harm.
8+
9+
set -eo pipefail
10+
11+
SCRIPT_DIRPATH=$(dirname ${BASH_SOURCE[0]})
12+
source $SCRIPT_DIRPATH/lib.sh
13+
14+
if [[ "$CIRRUS_CI" != true ]] || [[ -z "$DEST_BRANCH" ]]; then
15+
die "Script is not intended for use outside of Cirrus-CI"
16+
fi
17+
18+
SCRIPT_DEST=$SCRIPT_DIRPATH/cache_groom.sh
19+
showrun curl --location --silent --show-error -o $SCRIPT_DEST \
20+
https://raw.githubusercontent.com/containers/netavark/$DEST_BRANCH/contrib/cirrus/cache_groom.sh
21+
22+
# Certain common automation library calls assume execution from this file
23+
exec bash $SCRIPT_DEST

0 commit comments

Comments
 (0)