Skip to content

Commit

Permalink
add smart rollup snapshot download logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasochem committed Mar 15, 2024
1 parent 0c4b252 commit f4ffa9c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
22 changes: 22 additions & 0 deletions charts/tezos/scripts/smart-rollup-snapshot-downloader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

set -e

data_dir="/var/tezos"
rollup_dir="$data_dir/rollup"
snapshot_file=$rollup_dir/rollup.snapshot

if [ ! -d "$data_dir" ]; then
echo "ERROR: /var/tezos doesn't exist. There should be a volume mounted."
exit 1
fi

if [ -e "$rollup_dir/context/store.dict" ]; then
echo "Smart rollup snapshot has already been imported. Exiting."
exit 0
fi

echo "Did not find a pre-existing smart rollup snapshot."

mkdir -p "$rollup_dir"
curl -LfsS ${SNAPSHOT_URL} | tee >(sha256sum > ${snapshot_file}.sha256sum) > "$snapshot_file"
17 changes: 17 additions & 0 deletions charts/tezos/scripts/smart-rollup-snapshot-importer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set -e

bin_dir="/usr/local/bin"
data_dir="/var/tezos"
smart_rollup_node_dir="$data_dir/rollup"
smart_rollup_node="$bin_dir/octez-smart-rollup-node"
snapshot_file=${rollup_dir}/rollup.snapshot

if [ ! -f ${snapshot_file} ]; then
echo "No snapshot to import."
exit 0
fi

${smart_rollup_node} snapshot import ${snapshot_file} --data-dir ${rollup_data_dir} --no-check
find ${node_dir}

rm -rvf ${snapshot_file}
27 changes: 27 additions & 0 deletions charts/tezos/templates/octez-rollup-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,33 @@ spec:
- name: MY_POD_NAME
value: {{ $k }}
initContainers:
- name: snapshot-downloader
image: "{{ $.Values.tezos_k8s_images.utils }}"
imagePullPolicy: {{ $.Values.tezos_k8s_images_pull_policy }}
command:
- /bin/sh
volumeMounts:
- mountPath: /var/tezos
name: var-volume
args:
- "-c"
- |
{{ tpl ($.Files.Get "scripts/smart-rollup-snapshot-downloader.sh") $ | indent 12 }}
env:
- name: SNAPSHOT_URL
value: {{ $v.snapshot_url }}
- name: snapshot-importer
image: "{{ $.Values.images.octez }}"
imagePullPolicy: {{ $.Values.images_pull_policy }}
command:
- /bin/sh
volumeMounts:
- mountPath: /var/tezos
name: var-volume
args:
- "-c"
- |
{{ tpl ($.Files.Get "scripts/smart-rollup-snapshot-importer.sh") $ | indent 12 }}
- image: {{ $.Values.tezos_k8s_images.utils }}
imagePullPolicy: {{ $.Values.tezos_k8s_images_pull_policy }}
name: config-generator
Expand Down

0 comments on commit f4ffa9c

Please sign in to comment.