Skip to content

Commit c16efb1

Browse files
committed
Improve database configuration handling
1 parent 55eef00 commit c16efb1

File tree

6 files changed

+17
-10
lines changed

6 files changed

+17
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
test/resources/repositories
22
browser/binaries/
3+
config/
34
database/data/
45
!**/.gitkeep
56
**/node_modules

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ By default, BugHog uses a MongoDB container.
7777
you might want to prefer all data to be stored on your own MongoDB instance.
7878
If you prefer storing data in your own MongoDB instance, follow these steps:
7979
80-
1. Create a `.env` file from `.env.example` in the BugHog root directory and fill in the missing values.
80+
1. Create a `.env` file from `.env.example` (both in the `config` folder) and fill in the missing values.
8181
82-
2. Rebuild BugHog and run it.
82+
2. (Re)start BugHog.
8383
8484
### Stopping
8585
To stop BugHog, run the following command:

bci/configuration.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,17 @@ def initialize_folders():
3636

3737
@staticmethod
3838
def get_database_connection_params() -> DatabaseConnectionParameters:
39-
if 'BCI_MONGO_HOST' not in os.environ or \
40-
'BCI_MONGO_USERNAME' not in os.environ or \
41-
'BCI_MONGO_DATABASE' not in os.environ or \
42-
'BCI_MONGO_PASSWORD' not in os.environ:
43-
logger.info('Could not find database environment variables, using database container...')
39+
required_database_params = [
40+
'BCI_MONGO_HOST',
41+
'BCI_MONGO_USERNAME',
42+
'BCI_MONGO_DATABASE',
43+
'BCI_MONGO_PASSWORD'
44+
]
45+
missing_database_params = [
46+
param for param in required_database_params
47+
if os.getenv(param) in ['', None]]
48+
if missing_database_params:
49+
logger.info(f'Could not find database parameters {missing_database_params}, using database container...')
4450
return container.run()
4551
else:
4652
database_params = DatabaseConnectionParameters(

bci/distribution/worker_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def start_container_thread():
7575
labels=['bh_worker'],
7676
command=command,
7777
volumes=[
78-
os.path.join(os.getenv('host_pwd'), '.env') + ':/app/.env',
78+
os.path.join(os.getenv('host_pwd'), 'config') + ':/app/config',
7979
os.path.join(os.getenv('host_pwd'), 'browser/binaries/chromium/artisanal') + ':/app/browser/binaries/chromium/artisanal',
8080
os.path.join(os.getenv('host_pwd'), 'browser/binaries/firefox/artisanal') + ':/app/browser/binaries/firefox/artisanal',
8181
os.path.join(os.getenv('host_pwd'), 'experiments') + ':/app/experiments',

bci/master.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self):
4141
self.firefox_build = None
4242
self.chromium_build = None
4343

44-
load_dotenv()
44+
load_dotenv('/app/config/.env')
4545

4646
Global.initialize_folders()
4747
self.db_connection_params = Global.get_database_connection_params()

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ services:
2222
ports:
2323
- "5000:5000"
2424
volumes:
25-
- .env:/app/.env:ro
25+
- ./config:/app/config:ro
2626
- ./browser/binaries/chromium/artisanal:/app/browser/binaries/chromium/artisanal:rw
2727
- ./browser/binaries/firefox/artisanal:/app/browser/binaries/firefox/artisanal:rw
2828
- ./experiments:/app/experiments:ro

0 commit comments

Comments
 (0)