Skip to content

Commit

Permalink
[ADP-3368] Add admin.yml pipeline with a step to update a preprod sna…
Browse files Browse the repository at this point in the history
…pshot (#4643)

This PR is feeding a new pipeline with 1 command. The new pipeline is
active at
https://buildkite.com/cardano-foundation/cardano-wallet-buildkite-admin

- [x] Add a new pipeline to manage/control buildkite agent state
- [x] Add a blocked command that refresh the common preprod node state
via `csnapshot` service
  • Loading branch information
paolino authored Jun 26, 2024
2 parents fae66a5 + 2be8f1e commit 6063d18
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .buildkite/admin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
agents:
queue: "cardano-wallet"

env:
LC_ALL: "C.UTF-8"
NIX_PATH: "channel:nixos-21.11"
STATE_DIR: "/var/lib/buildkite-agent/cache"



steps:
- block: "Refresh preprod node state"
key: refresh-preprod-node-state-block
- label: 'Refresh preprod node state'
depends_on: refresh-preprod-node-state-block
command:
- ./scripts/buildkite/release/fetch-preprod-snapshot.sh
env:
NODE_STATE_DIR: "${STATE_DIR?}/node/preprod"
agents:
system: x86_64-linux
43 changes: 43 additions & 0 deletions scripts/buildkite/release/fetch-preprod-snapshot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#! /usr/bin/env -S nix shell 'nixpkgs#curl' 'nixpkgs#lz4' --command bash
# shellcheck shell=bash

set -euox pipefail

mkdir -p "$NODE_STATE_DIR"

cd "$NODE_STATE_DIR"

curl -s https://downloads.csnapshots.io/testnet/testnet-db-snapshot.json \
| jq -r .[].file_name > filename_new


if [ -f filename ]; then
if [ "$(cat filename)" == "$(cat filename_new)" ]; then
echo "Preprod snapshot is up to date with the latest snapshot available."
exit 0
fi
fi

dir_new="$(sed -e 's/\.tar\.lz4//' filename_new)"

rm -rf "$dir_new" && mkdir -p "$dir_new"

cd "$dir_new"

curl -o snapshot.tar.lz4 \
"https://downloads.csnapshots.io/testnet/$(cat ../filename_new)"
lz4 -c -d snapshot.tar.lz4 > snapshot.tar
tar -x -f snapshot.tar

cd ..

if [ -f filename ]; then
dir_old="$(sed -e 's/\.tar\.lz4//' filename)"
rm -rf "$dir_old"
fi

# Set the `db` directory to a symlink in a way that is supposed to be atomic.
# See also: https://unix.stackexchange.com/a/6786
ln -s "$dir_new"/db db-new && mv -T db-new db

mv filename_new filename

0 comments on commit 6063d18

Please sign in to comment.