Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Update docker-compose with nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
nolim1t committed Mar 3, 2020
1 parent 1be9fb3 commit 9dc02b5
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 8 deletions.
1 change: 1 addition & 0 deletions stage2/04-docker-compose/01-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ chmod 755 files/compose-service
cp files/docker-compose.yml ${ROOTFS_DIR}/home/${FIRST_USER_NAME}/docker-compose.yml
cp files/umbrel-createwallet.py ${ROOTFS_DIR}/home/${FIRST_USER_NAME}/umbrel-createwallet.py
cp files/umbrel-unlock.py ${ROOTFS_DIR}/home/${FIRST_USER_NAME}/umbrel-unlock.py
cp -fr files/build ${ROOTFS_DIR}/home/${FIRST_USER_NAME}

# Docker compose service
on_chroot << EOF
Expand Down
11 changes: 11 additions & 0 deletions stage2/04-docker-compose/files/build/lnd-unlock/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM alpine:3.10

RUN apk add --no-cache curl jq

RUN mkdir /lnd/

COPY unlock.sh /bin/unlock

RUN chmod +x /bin/unlock

ENTRYPOINT ["unlock"]
46 changes: 46 additions & 0 deletions stage2/04-docker-compose/files/build/lnd-unlock/unlock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

HOST=localhost:8080
TLS_CERT=/lnd/tls.cert
MACAROON="$(xxd -p /run/secrets/lnd-admin | tr -d '\n')"
PASS="$(cat /run/secrets/lnd-password | tr -d '\n' | base64 | tr -d '\n')"
UNLOCK_PAYLOAD="$(jq -nc --arg wallet_password ${PASS} '{$wallet_password}')"

lncurl() {
url_path=$1
data=$2

curl --fail --silent --show-error \
--cacert "${TLS_CERT}" \
--header "Grpc-Metadata-macaroon: ${MACAROON}" \
--data "${data}" \
"https://${HOST}/v1/${url_path}"
}

while true; do
# First make sure that port is open
while ! nc -z localhost 8080; do
>&2 echo "Waiting for ${HOST} port to open…"
sleep 3
done
>&2 echo "Port ${HOST} is open"

# Wait a bit more in case the port was just opened
sleep 1

>&2 echo "Trying ${HOST}/getinfo…"
INFO=$(lncurl getinfo)
if [ "$?" = "0" ]; then
>&2 echo "Response: ${INFO}"
alias="$(echo "${INFO}" | jq '.alias')"
>&2 echo "Wallet for ${alias} unlocked!"
exit 0
fi
>&2 echo "${HOST}/getinfo FAILED, out=${INFO}"

>&2 echo "Trying ${HOST}/unlockwallet…"
RESULT=$(lncurl unlockwallet "${UNLOCK_PAYLOAD}")
>&2 echo "${HOST}/unlockwallet completed with: exit-code=$?, out=${RESULT}"

sleep 16
done
43 changes: 42 additions & 1 deletion stage2/04-docker-compose/files/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
version: '3.7'
x-logging: &default-logging
driver: journald
options:
tag: "{{.Name}}"

x-utility: &default-utility
image: "alpine:3.11"
logging: *default-logging
network_mode: host

services:
web:
image: nginx:1.17.8
logging: *default-logging
volumes:
- ${HOME}/nginx:/etc/nginx
restart: on-failure
network_mode: host
bitcoin:
image: lncm/bitcoind:v0.19.0.1
logging: *default-logging
volumes:
- ${HOME}/bitcoin:/root/.bitcoin
restart: on-failure
network_mode: host
lnd:
image: lncm/lnd:v0.8.0-experimental
logging: *default-logging
volumes:
- /home/umbrel/lnd:/root/.lnd
- ${HOME}/lnd:/root/.lnd
- /var/lib/tor:/var/lib/tor
- /run/tor:/run/tor
restart: on-failure
depends_on: [ bitcoin, web ]
network_mode: host
lnd-unlock:
build: ${HOME}/build/lnd-unlock/
depends_on: [ lnd ]
logging: *default-logging
secrets:
- lnd-password
- lnd-admin
volumes:
- "${HOME}/lnd/tls.cert:/lnd/tls.cert:ro"
network_mode: host
secrets:
lnd-password:
file: ${HOME}/secrets/lnd-password.txt
lnd-admin:
file: ${HOME}/lnd/data/chain/bitcoin/mainnet/admin.macaroon
11 changes: 5 additions & 6 deletions stage2/04-docker-compose/files/umbrel-createwallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def main():
password_str=randompass(stringLength=15)
temp_password_file = open(temp_password_file_path, "w")
# Check if there is an existing file, if not generate a random password
if not os.path.exists("/home/umbrel/lnd/sesame.txt"):
if not os.path.exists("/home/umbrel/secrets/lnd-password.txt"):
# sesame file doesnt exist
password_str=randompass(stringLength=15)
if not os.path.exists(save_password_control_file):
Expand All @@ -63,18 +63,17 @@ def main():
temp_password_file.close()
else:
# Use sesame.txt if password_control_file exists
password_file = open("/home/umbrel/lnd/sesame.txt","w")
password_file = open("/home/umbrel/lnd/secrets/lnd-password.txt","w")
password_file.write(password_str)
password_file.close()
else:
# Get password from file if sesame file already exists
password_str = open('/home/umbrel/lnd/sesame.txt', 'r').read().rstrip()
password_str = open('/home/umbrel/secrets/lnd-password.txt', 'r').read().rstrip()

# Convert password to byte encoded
password_bytes = str(password_str).encode('utf-8')

# Step 1 get seed from web or file

# Send request to generate seed if seed file doesnt exist
if not os.path.exists(seed_filename):
r = requests.get(url, verify=cert_path)
Expand Down
2 changes: 1 addition & 1 deletion stage2/04-docker-compose/files/umbrel-unlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import base64, codecs, json, requests
url = 'https://localhost:8080/v1/unlockwallet'
cert_path = '/home/umbrel/lnd/tls.cert'
password_str = open('/home/umbrel/lnd/sesame.txt', 'r').read().rstrip()
password_str = open('/home/umbrel/secrets/lnd-password.txt', 'r').read().rstrip()
password_bytes = str(password_str).encode('utf-8')
data = {
'wallet_password': base64.b64encode(password_bytes).decode(),
Expand Down

0 comments on commit 9dc02b5

Please sign in to comment.