Skip to content

Commit

Permalink
Improve database configuration handling
Browse files Browse the repository at this point in the history
  • Loading branch information
GJFR committed Feb 17, 2024
1 parent 55eef00 commit 3a87e8b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
test/resources/repositories
browser/binaries/
config/
database/data/
!**/.gitkeep
**/node_modules
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ By default, BugHog uses a MongoDB container.
you might want to prefer all data to be stored on your own MongoDB instance.
If you prefer storing data in your own MongoDB instance, follow these steps:
1. Create a `.env` file from `.env.example` in the BugHog root directory and fill in the missing values.
1. Create a `.env` file from `.env.example` (both in the `config` folder) and fill in the missing values.
2. Rebuild BugHog and run it.
2. (Re)start BugHog.
### Stopping
To stop BugHog, run the following command:
Expand Down
16 changes: 11 additions & 5 deletions bci/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ def initialize_folders():

@staticmethod
def get_database_connection_params() -> DatabaseConnectionParameters:
if 'BCI_MONGO_HOST' not in os.environ or \
'BCI_MONGO_USERNAME' not in os.environ or \
'BCI_MONGO_DATABASE' not in os.environ or \
'BCI_MONGO_PASSWORD' not in os.environ:
logger.info('Could not find database environment variables, using database container...')
required_database_params = [
'BCI_MONGO_HOST',
'BCI_MONGO_USERNAME',
'BCI_MONGO_DATABASE',
'BCI_MONGO_PASSWORD'
]
missing_database_params = [
param for param in required_database_params
if os.getenv(param) in ['', None]]
if missing_database_params:
logger.info(f'Could not find database parameters {missing_database_params}, using database container...')
return container.run()
else:
database_params = DatabaseConnectionParameters(
Expand Down
2 changes: 1 addition & 1 deletion bci/distribution/worker_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def start_container_thread():
labels=['bh_worker'],
command=command,
volumes=[
os.path.join(os.getenv('host_pwd'), '.env') + ':/app/.env',
os.path.join(os.getenv('host_pwd'), 'config') + ':/app/config',
os.path.join(os.getenv('host_pwd'), 'browser/binaries/chromium/artisanal') + ':/app/browser/binaries/chromium/artisanal',
os.path.join(os.getenv('host_pwd'), 'browser/binaries/firefox/artisanal') + ':/app/browser/binaries/firefox/artisanal',
os.path.join(os.getenv('host_pwd'), 'experiments') + ':/app/experiments',
Expand Down
2 changes: 1 addition & 1 deletion bci/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self):
self.firefox_build = None
self.chromium_build = None

load_dotenv()
load_dotenv('/app/config/.env')

Global.initialize_folders()
self.db_connection_params = Global.get_database_connection_params()
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
ports:
- "5000:5000"
volumes:
- .env:/app/.env:ro
- ./config:/app/config:ro
- ./browser/binaries/chromium/artisanal:/app/browser/binaries/chromium/artisanal:rw
- ./browser/binaries/firefox/artisanal:/app/browser/binaries/firefox/artisanal:rw
- ./experiments:/app/experiments:ro
Expand Down

0 comments on commit 3a87e8b

Please sign in to comment.