add snapshot download, fix binary name, drop chainquery runmode, small refactors

This commit is contained in:
Alex Grintsvayg 2019-11-04 15:16:00 -05:00
parent fced928089
commit cf68868bf8
No known key found for this signature in database
GPG key ID: AEB3F089F86A22B5
4 changed files with 74 additions and 18 deletions

View file

@ -11,7 +11,7 @@ COPY ./stuff/start.sh start
COPY ./stuff/healthcheck.sh healthcheck COPY ./stuff/healthcheck.sh healthcheck
COPY ./stuff/advance_blocks.sh advance COPY ./stuff/advance_blocks.sh advance
COPY ./stuff/fix-permissions.c fix-permissions.c COPY ./stuff/fix-permissions.c fix-permissions.c
RUN curl --progress-bar -L -o ./lbrycrd-linux.zip $(curl -s https://api.github.com/repos/lbryio/lbrycrd/releases | grep -F 'lbrycrd-linux.zip' | grep download | head -n 1 | cut -d'"' -f4) && \ RUN curl --progress-bar -L -o ./lbrycrd-linux.zip $(curl -s https://api.github.com/repos/lbryio/lbrycrd/releases | grep -F 'lbrycrd-linux' | grep download | head -n 1 | cut -d'"' -f4) && \
unzip ./lbrycrd-linux.zip && \ unzip ./lbrycrd-linux.zip && \
gcc fix-permissions.c -o fix-permissions && \ gcc fix-permissions.c -o fix-permissions && \
chmod +x ./lbrycrdd ./lbrycrd-cli ./lbrycrd-tx ./start ./healthcheck ./fix-permissions ./advance chmod +x ./lbrycrdd ./lbrycrd-cli ./lbrycrd-tx ./start ./healthcheck ./fix-permissions ./advance
@ -23,6 +23,7 @@ RUN addgroup --gid 1000 lbrycrd && \
mkdir /etc/lbry && \ mkdir /etc/lbry && \
chown lbrycrd /etc/lbry && \ chown lbrycrd /etc/lbry && \
chmod a+s /usr/bin/fix-permissions chmod a+s /usr/bin/fix-permissions
RUN apt-get update && apt-get -y install wget && apt-get autoclean -y && rm -rf /var/lib/apt/lists/*
VOLUME ["/data"] VOLUME ["/data"]
WORKDIR /data WORKDIR /data
HEALTHCHECK CMD /usr/bin/healthcheck HEALTHCHECK CMD /usr/bin/healthcheck

View file

@ -31,7 +31,7 @@ mounted config file exists, these variables are used to create a fresh config.
Running the default configuration: Running the default configuration:
``` ```
docker run --rm -it -e RUN_MODE=default lbry/lbrycrd:linux-x86_64-production docker run --rm -it -e RUN_MODE=default -e SNAPSHOT_URL="https://lbry.com/snapshot/blockchain" lbry/lbrycrd:linux-x86_64-production
``` ```
Running with RPC password changed: Running with RPC password changed:

31
lbrycrd/deploy.sh Executable file
View file

@ -0,0 +1,31 @@
#!/bin/bash
set -euo pipefail
hash docker 2>/dev/null || { echo >&2 'Make sure Docker is installed'; exit 1; }
set +eo pipefail
docker version | grep -q Server
ret=$?
set -eo pipefail
if [ $ret -ne 0 ]; then
echo "Cannot connect to Docker server. Is it running? Do you have the right user permissions?"
exit 1
fi
echo "This will build the docker image using the latest lbrycrd release and push that image to Docker Hub"
echo ""
echo "What Docker tag should I use? It's the part that goes here: lbry/lbrycrd:TAG"
read -p "Docker tag: " docker_tag
if [ -z "$docker_tag" ]; then
echo "Docker tag cannot be empty"
exit 1
fi
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
docker build -t "lbry/lbrycrd:${docker_tag}" -f Dockerfile-linux-x86_64-production "$DIR"
docker push "lbry/lbrycrd:${docker_tag}"

View file

@ -1,6 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
CONFIG_PATH=/etc/lbry/lbrycrd.conf CONFIG_PATH=/etc/lbry/lbrycrd.conf
function override_config_option() { function override_config_option() {
# Remove existing config line from a config file # Remove existing config line from a config file
# and replace with environment fed value. # and replace with environment fed value.
@ -17,6 +19,7 @@ function override_config_option() {
fi fi
} }
function set_config() { function set_config() {
if [ -d "$CONFIG_PATH" ]; then if [ -d "$CONFIG_PATH" ]; then
echo "$CONFIG_PATH is a directory when it should be a file." echo "$CONFIG_PATH is a directory when it should be a file."
@ -24,7 +27,7 @@ function set_config() {
elif [ -f "$CONFIG_PATH" ]; then elif [ -f "$CONFIG_PATH" ]; then
echo "Merging the mounted config file with environment variables." echo "Merging the mounted config file with environment variables."
local MERGED_CONFIG=/tmp/lbrycrd_merged.conf local MERGED_CONFIG=/tmp/lbrycrd_merged.conf
cat $CONFIG_PATH > $MERGED_CONFIG cp $CONFIG_PATH $MERGED_CONFIG
echo "" >> $MERGED_CONFIG echo "" >> $MERGED_CONFIG
override_config_option PORT port $MERGED_CONFIG override_config_option PORT port $MERGED_CONFIG
override_config_option RPC_USER rpcuser $MERGED_CONFIG override_config_option RPC_USER rpcuser $MERGED_CONFIG
@ -32,31 +35,58 @@ function set_config() {
override_config_option RPC_ALLOW_IP rpcallowip $MERGED_CONFIG override_config_option RPC_ALLOW_IP rpcallowip $MERGED_CONFIG
override_config_option RPC_PORT rpcport $MERGED_CONFIG override_config_option RPC_PORT rpcport $MERGED_CONFIG
override_config_option RPC_BIND rpcbind $MERGED_CONFIG override_config_option RPC_BIND rpcbind $MERGED_CONFIG
override_config_option TX_INDEX txindex $MERGED_CONFIG
override_config_option MAX_TX_FEE maxtxfee $MERGED_CONFIG
override_config_option DUST_RELAY_FEE dustrelayfee $MERGED_CONFIG
# Make the new merged config file the new CONFIG_PATH # Make the new merged config file the new CONFIG_PATH
# This ensures that the original file the user mounted remains unmodified # This ensures that the original file the user mounted remains unmodified
CONFIG_PATH=$MERGED_CONFIG CONFIG_PATH=$MERGED_CONFIG
else else
echo "Creating a fresh config file from environment variables." echo "Creating a fresh config file from environment variables."
## Set config params cat << EOF > $CONFIG_PATH
echo "port=${PORT=9246}" > $CONFIG_PATH server=1
echo "rpcuser=${RPC_USER=lbry}" >> $CONFIG_PATH printtoconsole=1
echo "rpcpassword=${RPC_PASSWORD=lbry}" >> $CONFIG_PATH
echo "rpcallowip=${RPC_ALLOW_IP=127.0.0.1/24}" >> $CONFIG_PATH port=${PORT:-9246}
echo "rpcport=${RPC_PORT=9245}" >> $CONFIG_PATH rpcuser=${RPC_USER:-lbry}
echo "rpcbind=${RPC_BIND=0.0.0.0}" >> $CONFIG_PATH rpcpassword=${RPC_PASSWORD:-lbry}
rpcallowip=${RPC_ALLOW_IP:-127.0.0.1}
rpcport=${RPC_PORT:-9245}
rpcbind=${RPC_BIND:-"0.0.0.0"}
txindex=${TX_INDEX:-"1"}
maxtxfee=${MAX_TX_FEE:-"0.5"}
dustrelayfee=${DUST_RELAY_FEE:-"0.00000001"}
EOF
fi fi
echo "Config: " echo "Config: "
cat $CONFIG_PATH cat $CONFIG_PATH
} }
function download_snapshot() {
local url="${SNAPSHOT_URL:-}" #off by default. latest snapshot at https://lbry.com/snapshot/blockchain
if [[ -n "$url" ]] && [[ ! -d ./.lbrycrd/blocks ]]; then
echo "Downloading blockchain snapshot from $url"
wget -O snapshot.tar.bz2 "$url"
echo "Extracting snapshot..."
mkdir -p ./.lbrycrd
tar xvjf snapshot.tar.bz2 --directory ./.lbrycrd
rm snapshot.tar.bz2
fi
}
## Ensure perms are correct prior to running main binary ## Ensure perms are correct prior to running main binary
/usr/bin/fix-permissions /usr/bin/fix-permissions
## You can optionally specify a run mode if you want to use lbry defined presets for compatibility. ## You can optionally specify a run mode if you want to use lbry defined presets for compatibility.
case $RUN_MODE in case $RUN_MODE in
default ) default )
set_config set_config
exec lbrycrdd -server -conf=$CONFIG_PATH -printtoconsole download_snapshot
exec lbrycrdd -conf=$CONFIG_PATH
;; ;;
## If it's a first run you need to do a full index including all transactions ## If it's a first run you need to do a full index including all transactions
## tx index creates an index of every single transaction in the block history if ## tx index creates an index of every single transaction in the block history if
@ -65,13 +95,7 @@ case $RUN_MODE in
reindex ) reindex )
## Apply this RUN_MODE in the case you need to update a dataset. NOTE: you do not need to use `RUN_MODE reindex` for more than one complete run. ## Apply this RUN_MODE in the case you need to update a dataset. NOTE: you do not need to use `RUN_MODE reindex` for more than one complete run.
set_config set_config
exec lbrycrdd -server -txindex -reindex -conf=$CONFIG_PATH -printtoconsole exec lbrycrdd -conf=$CONFIG_PATH -reindex
;;
chainquery )
## If your only goal is to run Chainquery against this instance of lbrycrd and you're starting a
## fresh local dataset use this run mode.
set_config
exec lbrycrdd -server -txindex -conf=$CONFIG_PATH -printtoconsole
;; ;;
regtest ) regtest )
## Set config params ## Set config params