Skip to content

Commit

Permalink
Add epoch to cache key given caches are immutable
Browse files Browse the repository at this point in the history
and use spaceless string concatenation in yaml
to split long key names into multiple lines.

Given the immutability of caches,
and that cache key matching is prefix based,
{{ epoch }} must be the last part of the cache-save key.

https://discuss.circleci.com/t/add-mechanism-to-update-existing-cache-key/9014/13
https://circleci.com/docs/2.0/caching/#restoring-cache
https://circleci.com/docs/2.0/configuration-reference/#save_cache
https://stackoverflow.com/questions/3790454/how-do-i-break-a-string-over-multiple-lines/21699210#comment65667554_21699210
  • Loading branch information
ruffsl committed Aug 1, 2019
1 parent d4cee9e commit 479aca7
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@ references:
restore_ccache: &restore_ccache
restore_cache:
name: Restore CCache
key: ccache-v1-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_PR_NUMBER }}-{{ checksum "/opt/ros_ws/checksum.txt" }}
key: "ccache-v1\
-{{ arch }}\
-{{ .Branch }}\
-{{ .Environment.CIRCLE_PR_NUMBER }}\
-{{ checksum \"/opt/ros_ws/checksum.txt\" }}"
restore_underlay_cache: &restore_underlay_cache
restore_cache:
name: Restore Underlay Cache
key: underlay-v1-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_PR_NUMBER }}-{{ checksum "/opt/ros_ws/checksum.txt" }}
key: "underlay-v1\
-{{ arch }}\
-{{ .Branch }}\
-{{ .Environment.CIRCLE_PR_NUMBER }}\
-{{ checksum \"/opt/ros_ws/checksum.txt\" }}"
build_underlay: &build_underlay
run:
name: Build Underlay
Expand All @@ -77,7 +85,12 @@ references:
save_underlay_cache: &save_underlay_cache
save_cache:
name: Save Underlay Cache
key: underlay-v1-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_PR_NUMBER }}-{{ checksum "/opt/ros_ws/checksum.txt" }}
key: "underlay-v1\
-{{ arch }}\
-{{ .Branch }}\
-{{ .Environment.CIRCLE_PR_NUMBER }}\
-{{ checksum \"/opt/ros_ws/checksum.txt\" }}\
-{{ epoch }}"
paths:
- /opt/ros_ws
install_overlay_dependencies: &install_overlay_dependencies
Expand All @@ -89,7 +102,7 @@ references:
sort -k 2 | \
cut -d" " -f1 | \
sha256sum | \
awk '{print "source "$1}' >> $NAV2_WS/checksum.txt
awk '{print "overlay source "$1}' >> $NAV2_WS/checksum.txt
apt-get update
dependencies=$(
rosdep install -q -y \
Expand All @@ -103,14 +116,18 @@ references:
tr -d \, | xargs -n1 | sort -u | xargs)
dpkg -s $dependencies | \
sha256sum | \
awk '{print "dependencies "$1}' >> $NAV2_WS/checksum.txt
awk '{print "overlay dependencies "$1}' >> $NAV2_WS/checksum.txt
store_overlay_checksum: &store_overlay_checksum
store_artifacts:
path: checksum.txt
restore_overlay_cache: &restore_overlay_cache
restore_cache:
name: Restore Overlay Cache
key: overlay-v1-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_PR_NUMBER }}-{{ checksum "/opt/nav2_ws/checksum.txt" }}
key: "overlay-v1\
-{{ arch }}\
-{{ .Branch }}\
-{{ .Environment.CIRCLE_PR_NUMBER }}\
-{{ checksum \"/opt/nav2_ws/checksum.txt\" }}"
build_overlay: &build_overlay
run:
name: Build Overlay
Expand All @@ -132,14 +149,24 @@ references:
save_ccache: &save_ccache
save_cache:
name: Save CCache
key: ccache-v1-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_PR_NUMBER }}-{{ checksum "/opt/ros_ws/checksum.txt" }}
key: "ccache-v1\
-{{ arch }}\
-{{ .Branch }}\
-{{ .Environment.CIRCLE_PR_NUMBER }}\
-{{ checksum \"/opt/ros_ws/checksum.txt\" }}\
-{{ epoch }}"
paths:
- /root/.ccache
when: always
save_overlay_cache: &save_overlay_cache
save_cache:
name: Save Overlay Cache
key: overlay-v1-{{ arch }}-{{ .Branch }}-{{ .Environment.CIRCLE_PR_NUMBER }}-{{ checksum "/opt/nav2_ws/checksum.txt" }}
key: "overlay-v1\
-{{ arch }}\
-{{ .Branch }}\
-{{ .Environment.CIRCLE_PR_NUMBER }}\
-{{ checksum \"/opt/nav2_ws/checksum.txt\" }}\
-{{ epoch }}"
paths:
- /opt/nav2_ws
copy_build_logs: &copy_build_logs
Expand Down

0 comments on commit 479aca7

Please sign in to comment.