Skip to content

Commit 7fceb5a

Browse files
Jeffrey Picardroylee17
authored andcommitted
[lbry] contrib: add linode deployment using docker
1 parent fc9bac6 commit 7fceb5a

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed

contrib/linode/Dockerfile.deploy

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This Dockerfile builds btcd from source and creates a small (55 MB) docker container based on alpine linux.
2+
#
3+
# Clone this repository and run the following command to build and tag a fresh btcd amd64 container:
4+
#
5+
# docker build . -t yourregistry/btcd
6+
#
7+
# You can use the following command to buid an arm64v8 container:
8+
#
9+
# docker build . -t yourregistry/btcd --build-arg ARCH=arm64v8
10+
#
11+
# For more information how to use this docker image visit:
12+
# https://github.com/lbryio/lbcd/tree/master/docs
13+
#
14+
# 9246 Mainnet Bitcoin peer-to-peer port
15+
# 9245 Mainet RPC port
16+
17+
FROM golang AS build-container
18+
19+
# ENV GO111MODULE=on
20+
21+
ADD . /app
22+
WORKDIR /app
23+
RUN set -ex \
24+
&& if [ "${ARCH}" = "amd64" ]; then export GOARCH=amd64; fi \
25+
&& if [ "${ARCH}" = "arm64v8" ]; then export GOARCH=arm64; fi \
26+
&& echo "Compiling for $GOARCH" \
27+
&& CGO_ENABLED=0 go build .
28+
29+
FROM debian:11-slim
30+
31+
COPY --from=build-container /app/lbcd /
32+
COPY --from=build-container /app/contrib/linode/run.sh /
33+
34+
VOLUME ["/root/.lbcd"]
35+
36+
EXPOSE 9245 9246
37+
38+
ENTRYPOINT ["/run.sh"]

contrib/linode/docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: "3"
2+
3+
volumes:
4+
lbcd:
5+
external: true
6+
7+
services:
8+
lbcd:
9+
image: lbry/lbcd:linode_deployment
10+
container_name: lbcd
11+
ulimits:
12+
memlock:
13+
soft: -1
14+
hard: -1
15+
volumes:
16+
- lbcd:/root/.lbcd:rw
17+
ports:
18+
- "REPLACE_ME:9245:9245"
19+
- "9246:9246"
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
# <UDF name="username" Label="Username" example="lbry" />
3+
# <UDF name="password" Label="Password" example="ASDF123!@#" />
4+
# <UDF name="private_ip_prefix" Label="PrivateIPPrefix" example="192" default="192" />
5+
# <UDF name="snapshot_url" Label="SnapshotURL" default="https://snapshots.lbry.com/blockchain/lbcd/data-1052K.zip" />
6+
# <UDF name="AWS_ACCESS_KEY_ID" Label="AccessKey" default="" />
7+
# <UDF name="AWS_SECRET_ACCESS_KEY" Label="SecretKey" default="" />
8+
# <UDF name="endpoint_url" Label="BlockStorageEndpoint" default="" />
9+
# <UDF name="docker_compose_file_url" Label="ConfigURL" default="https://picardtek-linode-storage.us-east-1.linodeobjects.com/config/docker-compose-lbcd.yml" />
10+
11+
source <ssinclude StackScriptID=1>
12+
13+
# For debugging
14+
exec > >(tee -i /var/log/stackscript.log) 2>&1
15+
set -xeo pipefail
16+
17+
function user_add_sudo {
18+
USERNAME="$1"
19+
USERPASS="$2"
20+
if [ ! -n "$USERNAME" ] || [ ! -n "$USERPASS" ]; then
21+
echo "No new username and/or password entered"
22+
return 1;
23+
fi
24+
adduser "$USERNAME" --disabled-password --gecos ""
25+
echo "$USERNAME:$USERPASS" | chpasswd
26+
apt-get install -y sudo
27+
usermod -aG sudo "$USERNAME"
28+
}
29+
30+
function download_snapshot {
31+
if [ -z "${AWS_ACCESS_KEY_ID}" ]; then
32+
wget "${SNAPSHOT_URL}"
33+
else
34+
echo "[default]
35+
access_key = ${AWS_ACCESS_KEY_ID}
36+
secret_key = ${AWS_SECRET_ACCESS_KEY}" > ~/.s3cfg
37+
if [ -z "${ENDPOINT_URL}" ]; then
38+
s4cmd --verbose get "${SNAPSHOT_URL}"
39+
else
40+
s4cmd --verbose get "${SNAPSHOT_URL}" --endpoint-url "${ENDPOINT_URL}"
41+
fi
42+
fi
43+
}
44+
45+
function download_and_start {
46+
download_snapshot
47+
# get the snapshot data into place
48+
SNAPSHOT_FILE_NAME=$(echo "${SNAPSHOT_URL}" | rev | cut -d/ -f1 | rev)
49+
unzip "${SNAPSHOT_FILE_NAME}" -d ~/.lbcd/
50+
mv ~/.lbcd/"${SNAPSHOT_FILE_NAME}" ~/.lbcd/data
51+
rm "${SNAPSHOT_FILE_NAME}"
52+
# get our private ip
53+
PRIVATE_IP=$(ip addr | grep "${PRIVATE_IP_PREFIX}" | cut -d'/' -f1 | rev | cut -d" " -f 1 | rev)
54+
# download the compose-compose and put our private ip in the for RPC endpoint
55+
wget "${DOCKER_COMPOSE_FILE_URL}" -O - | sed 's/REPLACE_ME/'"${PRIVATE_IP}"'/g' > docker-compose.yml
56+
# Create our volume and start lbcd
57+
docker volume create --driver local \
58+
--opt type=none \
59+
--opt device=~/.lbcd\
60+
--opt o=bind lbcd
61+
docker-compose up -d
62+
}
63+
# add a non-root sudo user
64+
user_add_sudo "${USERNAME}" "${PASSWORD}"
65+
# Update and install dependencies
66+
sudo apt-get update && sudo apt-get upgrade -y
67+
sudo apt-get install -y unzip wget s4cmd
68+
apt install -y apt-transport-https ca-certificates curl software-properties-common && \
69+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && \
70+
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" && \
71+
apt install -y docker-ce docker-ce-cli containerd.io && \
72+
systemctl enable docker && sudo systemctl start docker && \
73+
curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && \
74+
chmod +x /usr/local/bin/docker-compose
75+
# make sure we can use docker
76+
usermod -aG docker $USERNAME
77+
export -f download_and_start
78+
export -f download_snapshot
79+
su "${USERNAME}" -c 'bash -c "cd ~ && download_and_start"'

contrib/linode/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
/lbcd --txindex --notls --rpcuser=lbry --rpcpass=lbry --rpclisten=

0 commit comments

Comments
 (0)