diff --git a/charts/tezos/scripts/smart-rollup-snapshot-downloader.sh b/charts/tezos/scripts/smart-rollup-snapshot-downloader.sh new file mode 100755 index 0000000..c2ce7bc --- /dev/null +++ b/charts/tezos/scripts/smart-rollup-snapshot-downloader.sh @@ -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" diff --git a/charts/tezos/scripts/smart-rollup-snapshot-importer.sh b/charts/tezos/scripts/smart-rollup-snapshot-importer.sh new file mode 100644 index 0000000..3a0dd52 --- /dev/null +++ b/charts/tezos/scripts/smart-rollup-snapshot-importer.sh @@ -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} diff --git a/charts/tezos/templates/octez-rollup-node.yaml b/charts/tezos/templates/octez-rollup-node.yaml index 02ccd0d..72f704c 100644 --- a/charts/tezos/templates/octez-rollup-node.yaml +++ b/charts/tezos/templates/octez-rollup-node.yaml @@ -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