Files
stacks-puppet-node/api/ops

98 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
set -e
# must be run from the api/ directory
exit_error() {
echo "$1" >&2
exit 1
}
test -d "deployment" || exit_error "Must be run from the api/ directory"
docker ps -a >/dev/null 2>&1 || exit_error "Could not connect to docker (is it running, and do you have permission?)"
init_indexer () {
# set up search indexer
# $1: the directory into which to store the search data (default: data/)
datadir="$1"
if [[ -z "$datadir" ]]; then
datadir="$(pwd)/data"
fi
local idxData="$datadir/search-api"
echo "Initializing Blockstack Indexer with dummy data..."
mkdir -p "$idxData"
cp search/fixtures/blockchain_data.json "$idxData/blockchain_data.json"
cp search/fixtures/profile_data.slice.json "$idxData/profile_data.json"
mkdir -p "$datadir/mongodb"
}
function init_core () {
# set up core node
# $1: the directory into which to store the Blockstack Core data (default: data/)
# $2: the tag of the Blockstack Core docker image to pull (default: master)
datadir="$1"
tag="$2"
image=quay.io/blockstack/blockstack-core
if [[ -z "$datadir" ]]; then
datadir="$(pwd)/data"
fi
if [[ -z "$tag" ]]; then
tag=master
else
# need to remove '/'
tag="$(echo "$tag" | sed -r 's@/@_@g')"
fi
local coreData="$datadir/blockstack-core"
echo "Initializing Blockstack Core node (tag=$tag) into $coreData. This task runs in the background and may take up to 20 minutes..."
mkdir -p "$coreData/server/"
cp "deployment/blockstack-server.ini" "$coreData/server/blockstack-server.ini"
docker run -d --rm \
-v "$coreData/server/:/root/.blockstack-server/" \
--name blockstack-core-init \
"$image:$tag" \
blockstack-core --debug fast_sync > /dev/null
docker logs -f blockstack-core-init
}
function commands() {
# usage
cat <<-EOF
ops commands:
init-indexer [data_dir] -> Set up the bootstrapping data for the indexer
init-core [data_dir [tag] -> Set up blockstack-core instance for this API
EOF
}
function init_all() {
# $1: data directory
# $2: blockstack-core tag
init_indexer "$1"
init_core "$1" "$2"
}
# entry point
case "$1" in
init-indexer)
init_indexer "$2"
;;
init-core)
init_core "$2" "$3"
;;
init)
init_all "$2" "$3"
;;
*)
commands
;;
esac