[lbry] contrib: add linode deployment using docker

This commit is contained in:
Jeffrey Picard 2021-12-10 11:06:55 -05:00 committed by Roy Lee
parent 2df74a828f
commit cb7b2b28bf
4 changed files with 138 additions and 0 deletions

View file

@ -0,0 +1,38 @@
# This Dockerfile builds btcd from source and creates a small (55 MB) docker container based on alpine linux.
#
# Clone this repository and run the following command to build and tag a fresh btcd amd64 container:
#
# docker build . -t yourregistry/btcd
#
# You can use the following command to buid an arm64v8 container:
#
# docker build . -t yourregistry/btcd --build-arg ARCH=arm64v8
#
# For more information how to use this docker image visit:
# https://github.com/lbryio/lbcd/tree/master/docs
#
# 9246 Mainnet Bitcoin peer-to-peer port
# 9245 Mainet RPC port
FROM golang AS build-container
# ENV GO111MODULE=on
ADD . /app
WORKDIR /app
RUN set -ex \
&& if [ "${ARCH}" = "amd64" ]; then export GOARCH=amd64; fi \
&& if [ "${ARCH}" = "arm64v8" ]; then export GOARCH=arm64; fi \
&& echo "Compiling for $GOARCH" \
&& CGO_ENABLED=0 go build .
FROM debian:11-slim
COPY --from=build-container /app/lbcd /
COPY --from=build-container /app/contrib/linode/run.sh /
VOLUME ["/root/.lbcd"]
EXPOSE 9245 9246
ENTRYPOINT ["/run.sh"]

View file

@ -0,0 +1,19 @@
version: "3"
volumes:
lbcd:
external: true
services:
lbcd:
image: lbry/lbcd:linode_deployment
container_name: lbcd
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- lbcd:/root/.lbcd:rw
ports:
- "REPLACE_ME:9245:9245"
- "9246:9246"

View file

@ -0,0 +1,79 @@
#!/bin/bash
# <UDF name="username" Label="Username" example="lbry" />
# <UDF name="password" Label="Password" example="ASDF123!@#" />
# <UDF name="private_ip_prefix" Label="PrivateIPPrefix" example="192" default="192" />
# <UDF name="snapshot_url" Label="SnapshotURL" default="https://snapshots.lbry.com/blockchain/lbcd/data-1052K.zip" />
# <UDF name="AWS_ACCESS_KEY_ID" Label="AccessKey" default="" />
# <UDF name="AWS_SECRET_ACCESS_KEY" Label="SecretKey" default="" />
# <UDF name="endpoint_url" Label="BlockStorageEndpoint" default="" />
# <UDF name="docker_compose_file_url" Label="ConfigURL" default="https://picardtek-linode-storage.us-east-1.linodeobjects.com/config/docker-compose-lbcd.yml" />
source <ssinclude StackScriptID=1>
# For debugging
exec > >(tee -i /var/log/stackscript.log) 2>&1
set -xeo pipefail
function user_add_sudo {
USERNAME="$1"
USERPASS="$2"
if [ ! -n "$USERNAME" ] || [ ! -n "$USERPASS" ]; then
echo "No new username and/or password entered"
return 1;
fi
adduser "$USERNAME" --disabled-password --gecos ""
echo "$USERNAME:$USERPASS" | chpasswd
apt-get install -y sudo
usermod -aG sudo "$USERNAME"
}
function download_snapshot {
if [ -z "${AWS_ACCESS_KEY_ID}" ]; then
wget "${SNAPSHOT_URL}"
else
echo "[default]
access_key = ${AWS_ACCESS_KEY_ID}
secret_key = ${AWS_SECRET_ACCESS_KEY}" > ~/.s3cfg
if [ -z "${ENDPOINT_URL}" ]; then
s4cmd --verbose get "${SNAPSHOT_URL}"
else
s4cmd --verbose get "${SNAPSHOT_URL}" --endpoint-url "${ENDPOINT_URL}"
fi
fi
}
function download_and_start {
download_snapshot
# get the snapshot data into place
SNAPSHOT_FILE_NAME=$(echo "${SNAPSHOT_URL}" | rev | cut -d/ -f1 | rev)
unzip "${SNAPSHOT_FILE_NAME}" -d ~/.lbcd/
mv ~/.lbcd/"${SNAPSHOT_FILE_NAME}" ~/.lbcd/data
rm "${SNAPSHOT_FILE_NAME}"
# get our private ip
PRIVATE_IP=$(ip addr | grep "${PRIVATE_IP_PREFIX}" | cut -d'/' -f1 | rev | cut -d" " -f 1 | rev)
# download the compose-compose and put our private ip in the for RPC endpoint
wget "${DOCKER_COMPOSE_FILE_URL}" -O - | sed 's/REPLACE_ME/'"${PRIVATE_IP}"'/g' > docker-compose.yml
# Create our volume and start lbcd
docker volume create --driver local \
--opt type=none \
--opt device=~/.lbcd\
--opt o=bind lbcd
docker-compose up -d
}
# add a non-root sudo user
user_add_sudo "${USERNAME}" "${PASSWORD}"
# Update and install dependencies
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install -y unzip wget s4cmd
apt install -y apt-transport-https ca-certificates curl software-properties-common && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && \
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" && \
apt install -y docker-ce docker-ce-cli containerd.io && \
systemctl enable docker && sudo systemctl start docker && \
curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && \
chmod +x /usr/local/bin/docker-compose
# make sure we can use docker
usermod -aG docker $USERNAME
export -f download_and_start
export -f download_snapshot
su "${USERNAME}" -c 'bash -c "cd ~ && download_and_start"'

2
contrib/linode/run.sh Executable file
View file

@ -0,0 +1,2 @@
#!/bin/bash
/lbcd --txindex --notls --rpcuser=lbry --rpcpass=lbry --rpclisten=