Skip to content
Snippets Groups Projects
Commit 3cf798dc authored by Andrea Giannetti's avatar Andrea Giannetti
Browse files

Created convenience script to produce db_credentials.yml; updated README.md

parent f852e434
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,16 @@ A docker-compose script is included in the root folder of this repository ([dock
```bash
docker compose up --build
```
*Before the first run:* Set the following environment variables, as specified in the documentation:
- DB_USER: the database user;
- DB_PASS: the password for the user;
- DB_HOST: the database host, if you are running SAK locally, set it to localhost;
- DB_NAME: the database name;
- DB_PORT: the port to use to connect to the database.
A convenience script is provided to create the credentials file for future connections [create_db_credentials_file.py](etl/create_db_credentials_file.py).
This must be executed before running docker compose, or the credentials file can be compiled by hand.
The following parameters can be set by adding the `command` override in the `etl` section of the docker-compose file:
* --run_id: the run id of the grid to process; if not provided, generates a new run_id;
......
import base64
import os
import argparse
import yaml
parser = argparse.ArgumentParser()
parser.add_argument('--user', default='sak_user')
parser.add_argument('--psw')
parser.add_argument('--host', default='localhost')
parser.add_argument('--db_name', default='sak_database')
parser.add_argument('--port', default=31000)
args = parser.parse_args()
args_dict = vars(args)
key_map = {'user': 'DB_USER',
'psw': 'DB_PASS',
'host': 'DB_HOST',
'db_name': 'DB_NAME',
'port': 'DB_PORT'}
for key in args_dict.keys():
print(os.getenv(key_map[key]))
if os.getenv(key_map[key]) is not None:
args_dict[key] = os.getenv(key_map[key])
assert args.psw is not None
credentials_dict = {}
for key in key_map.keys():
credentials_dict[key_map[key]] = getattr(args, key)
for key in ['DB_USER', 'DB_PASS']:
print(credentials_dict[key])
credentials_dict[key] = base64.b64encode(credentials_dict[key].encode()).decode()
with open(os.path.join('credentials', 'db_credentials.yml'), 'w') as outfile:
yaml.dump(credentials_dict, outfile)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment