Merge pull request #27 from onesandzeros-nz/main

Dockerized service
This commit is contained in:
Peter Rounce 2023-02-09 08:29:01 +00:00 committed by GitHub
commit ef4c16b14f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 176 additions and 6 deletions

1
.env.example Normal file
View file

@ -0,0 +1 @@
DB_PASSWORD=password

2
Caddyfile_docker Normal file
View file

@ -0,0 +1,2 @@
https://card.yourdomain.com
reverse_proxy boltcard_main:9000

16
Dockerfile Normal file
View file

@ -0,0 +1,16 @@
FROM golang:1.19.0-bullseye
WORKDIR /App
ADD . /App
RUN go build
WORKDIR /App/createboltcard
RUN go get github.com/skip2/go-qrcode
RUN go build
WORKDIR /App/wipeboltcard
RUN go build
WORKDIR /App
ENTRYPOINT ["/App/boltcard"]

View file

@ -17,6 +17,7 @@ The 'bolt card creation' instructions describe how to set up bolt cards for use
| [Specification](docs/SPEC.md) | Bolt card specifications | | [Specification](docs/SPEC.md) | Bolt card specifications |
| [System](docs/SYSTEM.md) | Bolt card system overview | | [System](docs/SYSTEM.md) | Bolt card system overview |
| [Service Install](docs/INSTALL.md) | Bolt card service installation | | [Service Install](docs/INSTALL.md) | Bolt card service installation |
| [Docker Service Install](docs/DOCKER_INSTALL.md) | Bolt card service docker installation |
| [Automatic Card Creation](docs/CARD_ANDROID.md) | Bolt card creation using the Bolt Card app| | [Automatic Card Creation](docs/CARD_ANDROID.md) | Bolt card creation using the Bolt Card app|
| [Manual Card Creation](docs/CARD_MANUAL.md) | Bolt card creation using NXP TagXplorer software| | [Manual Card Creation](docs/CARD_MANUAL.md) | Bolt card creation using NXP TagXplorer software|
| [FAQ](docs/FAQ.md) | Frequently asked questions | | [FAQ](docs/FAQ.md) | Frequently asked questions |

View file

@ -1,9 +1,3 @@
DROP DATABASE IF EXISTS card_db;
CREATE DATABASE card_db;
DROP USER IF EXISTS cardapp;
CREATE USER cardapp WITH PASSWORD 'database_password';
\c card_db; \c card_db;
CREATE TABLE settings ( CREATE TABLE settings (

2
create_db_init.sql Normal file
View file

@ -0,0 +1,2 @@
DROP DATABASE IF EXISTS card_db;
CREATE DATABASE card_db;

2
create_db_user.sql Normal file
View file

@ -0,0 +1,2 @@
DROP USER cardapp;
CREATE USER cardapp WITH PASSWORD 'database_password';

62
docker-compose.yml Normal file
View file

@ -0,0 +1,62 @@
version: '3'
services:
boltcard:
build:
context: ./
dockerfile: Dockerfile
container_name: boltcard_main
depends_on:
- db
restart: unless-stopped
environment:
- LOG_LEVEL=DEBUG
- DB_HOST=db
- DB_USER=cardapp
- DB_PASSWORD=${DB_PASSWORD}
- DB_PORT=5432
- DB_NAME=card_db
expose:
- "9000"
volumes:
- ${PWD}/tls.cert:/boltcard/tls.cert
- ${PWD}/admin.macaroon:/boltcard/admin.macaroon
networks:
- boltnet
db:
image: postgres
container_name: boltcard_db
restart: unless-stopped
environment:
- POSTGRES_USER=cardapp
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=card_db
- PGDATA=/var/lib/postgresql/data/pgdata
volumes:
- db-data:/var/lib/postgresql/data
- ./select_db.sql:/docker-entrypoint-initdb.d/select_db.sql
- ./create_db.sql:/docker-entrypoint-initdb.d/create_db.sql
- ./settings.sql:/docker-entrypoint-initdb.d/settings.sql
expose:
- "5432"
networks:
- boltnet
webserver:
image: caddy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
- "443:443/udp"
volumes:
- ${PWD}/Caddyfile_docker:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config
networks:
- boltnet
networks:
boltnet:
volumes:
db-data:
caddy_data:
external: true
caddy_config:

34
docker_init.sh Executable file
View file

@ -0,0 +1,34 @@
#!/bin/bash
echo Enter the domain name excluding the protocol
read domainname
echo Enter your LND node gRPC domain
read lnd_host
echo LND node gRPC port
read lnd_port
sed -i "1s/.*/https:\/\/$domainname/" Caddyfile_docker
sed -i "s/[(]'HOST_DOMAIN'[^)]*[)]/(\'HOST_DOMAIN\', \'$domainname\')/" settings.sql
echo writing the domain name to $domainname ...
PASSWORD=$(date +%s|sha256sum|base64|head -c 32)
if [[ ! -e .env ]]; then
cp .env.example .env
fi
sed -i "s/^DB_PASSWORD=.*$/DB_PASSWORD=$PASSWORD/g" .env
decrypt_key=$(hexdump -vn16 -e'4/4 "%08x" 1 "\n"' /dev/random)
echo $decrypt_key
sed -i "s/[(]'LOG_LEVEL'[^)]*[)]/(\'LOG_LEVEL\', \'DEBUG\')/" settings.sql
sed -i "s/[(]'AES_DECRYPT_KEY'[^)]*[)]/(\'AES_DECRYPT_KEY\', \'$decrypt_key\')/" settings.sql
sed -i "s/[(]'MIN_WITHDRAW_SATS'[^)]*[)]/(\'MIN_WITHDRAW_SATS\', \'1\')/" settings.sql
sed -i "s/[(]'MAX_WITHDRAW_SATS'[^)]*[)]/(\'MAX_WITHDRAW_SATS\', \'1000000\')/" settings.sql
sed -i "s/[(]'LN_HOST'[^)]*[)]/(\'LN_HOST\', \'$lnd_host\')/" settings.sql
sed -i "s/[(]'LN_PORT'[^)]*[)]/(\'LN_PORT\', \'$lnd_port\')/" settings.sql
sed -i "s/[(]'LN_TLS_FILE'[^)]*[)]/(\'LN_TLS_FILE\', \'\/boltcard\/tls.cert\')/" settings.sql
sed -i "s/[(]'LN_MACAROON_FILE'[^)]*[)]/(\'LN_MACAROON_FILE\', \'\/boltcard\/admin.macaroon\')/" settings.sql
sed -i "s/[(]'FEE_LIMIT_SAT'[^)]*[)]/(\'FEE_LIMIT_SAT\', \'10\')/" settings.sql
sed -i "s/[(]'FEE_LIMIT_PERCENT'[^)]*[)]/(\'FEE_LIMIT_PERCENT\', \'0.5\')/" settings.sql
sed -i "s/[(]'FUNCTION_LNURLW'[^)]*[)]/(\'FUNCTION_LNURLW\', \'ENABLE\')/" settings.sql
sed -i "s/[(]'FUNCTION_LNURLP'[^)]*[)]/(\'FUNCTION_LNURLP\', \'DISABLE\')/" settings.sql
sed -i "s/[(]'FUNCTION_EMAIL'[^)]*[)]/(\'FUNCTION_EMAIL\', \'DISABLE\')/" settings.sql

53
docs/DOCKER_INSTALL.md Normal file
View file

@ -0,0 +1,53 @@
# Bolt card service installation using Docker
### install Docker engine and Docker compose
- [Docker engine download &
install](https://docs.docker.com/engine/install/)
### Set up the boltcard server
- Run `./docker_init.sh` to set up the initial data
- Put the `tls.cert` file and `admin.macaroon` files in the project root directory
### https setup
set up the domain A record to point to the server
set up the server hosting firewall to allow open access to https (port 443) only
### database setup
copy the `.env.example` file to `.env` and change the database password
### service bring-up and running
```
$ sudo groupadd docker
$ sudo usermod -aG docker ${USER}
(log out & in again)
$ docker volume create caddy_data
// add -d option for detached mode
$ docker compose up
```
### stop docker
```
$ docker compose down
```
To delete the database and reset the docker volume, run `docker compose down --volumes`
*NOTE: caddy_data volume won't be removed even if you run `docker compose down --volumes` because it's an external volume. **Make sure to wipe your programmed cards before wiping the database***
### check container logs
- [Docker Logs](https://docs.docker.com/engine/reference/commandline/logs/)
```
$ docker logs [OPTIONS] CONTAINER
```
Run `$ docker ps` to list containers and get container names/ids
#### running create bolt card command
- `docker exec boltcard_main createboltcard/createboltcard` to see options
- `docker exec boltcard_main createboltcard/createboltcard -enable -allow_neg_bal -tx_max=1000 -day_max=10000 -name=card_1` for example
- this will give you a one-time link in text and QR code form

View file

@ -12,7 +12,9 @@ echo Continue? "(y or n)"
read x read x
if [ "$x" = "y" ]; then if [ "$x" = "y" ]; then
psql postgres -f create_db_init.sql
psql postgres -f create_db.sql psql postgres -f create_db.sql
psql postgres -f create_db_user.sql
psql postgres -f settings.sql psql postgres -f settings.sql
echo Database created echo Database created
else else

1
select_db.sql Normal file
View file

@ -0,0 +1 @@
SELECT 'CREATE DATABASE card_db' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'card_db');