Skip to content

Commit

Permalink
Improve installation instructions
Browse files Browse the repository at this point in the history
Signed-off-by: alfred richardsn <rchrdsn@protonmail.ch>
  • Loading branch information
r4rdsn committed Nov 19, 2020
1 parent 123306f commit 1856402
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ cp .env.example .env
8. Install [Docker Compose](https://docs.docker.com/compose/install/).
9. Start container:
```bash
docker-compose up
docker-compose up --build
```

For subsequent launches starting container is enough.

### Manual
1. Clone the repository:
```bash
Expand All @@ -72,17 +74,23 @@ cp .env.example .env
8. Create a file containing Telegram bot's API token with filename specified in ```TOKEN_FILENAME``` from ```.env``` (example in [secrets/tbtoken](secrets/tbtoken)).
9. *(Optional)* If you're going to support escrow, create a file containing JSON mapping blockchain names to bot's WIF and API nodes with filename specified in ```ESCROW_FILENAME``` from ```.env``` (example in [secrets/escrow.json](secrets/escrow.json)).
10. Create a file containing database password with filename specified in ```DATABASE_PASSWORD_FILENAME``` from ```.env``` (example in [secrets/dbpassword](secrets/dbpassword)).
11. Install [MongoDB server](https://docs.mongodb.com/manual/installation/).
12. Start MongoDB server and [enable authentification](https://docs.mongodb.com/manual/tutorial/enable-authentication/) of user specified in ```DATABASE_USERNAME``` with password in file specified in ```DATABASE_PASSWORD_FILENAME``` for database specified in ```DATABASE_NAME``` from ```.env```.
13. Set environment variables:
11. Install and start [MongoDB server](https://docs.mongodb.com/manual/installation/).
12. Set environment variables:
```bash
export $(grep -v '^#' .env | xargs)
```
14. Launch TellerBot:
13. Create database user:
```bash
./mongo-init.sh
```
14. Restart MongoDB server with [access control enabled](https://docs.mongodb.com/manual/tutorial/enable-authentication/#re-start-the-mongodb-instance-with-access-control).
15. Launch TellerBot:
```bash
python .
```

For subsequent launches setting enviroment variables and launching TellerBot is enough.

## Contributing
You can help by working on [opened issues](https://github.com/fincubator/tellerbot/issues), fixing bugs, creating new features, improving documentation or [translating bot messages to your language](https://hosted.weblate.org/engage/tellerbot/).

Expand Down
7 changes: 4 additions & 3 deletions mongo-init.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
mongo -- "${MONGO_INITDB_DATABASE}" <<EOF
#!/bin/sh
mongo -- "${MONGO_INITDB_DATABASE-$DATABASE_NAME}" <<EOF
db.createUser(
{
user: "${MONGO_INITDB_ROOT_USERNAME}",
pwd: "${MONGO_INITDB_ROOT_PASSWORD}",
user: "${MONGO_INITDB_ROOT_USERNAME:-$DATABASE_USERNAME}",
pwd: "${MONGO_INITDB_ROOT_PASSWORD:-$(cat "${DATABASE_PASSWORD_FILENAME}")}",
roles: ["readWrite"]
}
);
Expand Down
11 changes: 7 additions & 4 deletions src/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
try:
with open(config.DATABASE_PASSWORD_FILENAME, "r") as password_file:
client = AsyncIOMotorClient(
config.DATABASE_HOST,
config.DATABASE_PORT,
username=config.DATABASE_USERNAME,
password=password_file.read(),
"mongodb://{username}:{password}@{host}:{port}/{name}".format(
host=config.DATABASE_HOST,
port=config.DATABASE_PORT,
username=config.DATABASE_USERNAME,
password=password_file.read().strip(),
name=config.DATABASE_NAME,
)
)
except (AttributeError, FileNotFoundError):
client = AsyncIOMotorClient(config.DATABASE_HOST)
Expand Down

0 comments on commit 1856402

Please sign in to comment.