Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Wrede committed Feb 26, 2024
1 parent d5bcfba commit 8907977
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 6 deletions.
15 changes: 15 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,22 @@ services:
- USER=test
- PROJECT=project
- FLASK_DEBUG=1
# Statestore
- STATESTORE_HOST=mongo
- STATESTORE_PORT=6534
- STATESTORE_USER=fedn_admin
- STATESTORE_PASSWORD=password
# will be overriden by env vars above
- STATESTORE_CONFIG=/app/config/settings-reducer.yaml
# Modelstorage
- MODELSTORAGE_HOST=minio
- MODELSTORAGE_PORT=9000
- MODELSTORAGE_ACCESS_KEY=fedn_admin
- MODELSTORAGE_SECRET_KEY=password
- MODELSTORAGE_BUCKET=fedn-models
- MODELSTORAGE_CONTEXT_BUCKET=fedn-context
- MODELSTORAGE_SECURE_MODE=False
# will be overriden by env vars above
- MODELSTORAGE_CONFIG=/app/config/settings-reducer.yaml
build:
context: .
Expand Down
60 changes: 54 additions & 6 deletions fedn/fedn/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
global STATESTORE_CONFIG
global MODELSTORAGE_CONFIG

def get_env(key, default=None):
""" Get environment variable.
:param key: The environment variable key.
:type key: str
:param default: The default value if the environment variable is not set (optional).
:type default: str
:return: The environment variable value.
:rtype: str
"""
return os.environ.get(key, default)

def get_environment_config():
""" Get the configuration from environment variables.
Expand All @@ -27,8 +38,22 @@ def get_statestore_config(file=None):
:rtype: dict
"""
if file is None:
get_environment_config()
file = STATESTORE_CONFIG
# check if environment variables are set
host = get_env("STATESTORE_HOST", "mongo")
if host is not None:
return {
"type": "MongoDB",
"mongo_config": {
"host": host,
"port": int(get_env("STATESTORE_PORT", 6534)),
"username": get_env("STATESTORE_USER", "fedn_admin"),
"password": get_env("STATESTORE_PASSWORD"),
}
}
else:
# else use the default file
get_environment_config()
file = STATESTORE_CONFIG
with open(file, 'r') as config_file:
try:
settings = dict(yaml.safe_load(config_file))
Expand All @@ -46,8 +71,25 @@ def get_modelstorage_config(file=None):
:rtype: dict
"""
if file is None:
get_environment_config()
file = MODELSTORAGE_CONFIG
# check if environment variables are set
host = get_env("MODELSTORAGE_HOST", "minio")
if host is not None:
return {
"storage_type": "S3",
"storage_config": {
"storage_hostname": host,
"storage_port": int(get_env("MODELSTORAGE_PORT", 9000)),
"storage_access_key": get_env("MODELSTORAGE_ACCESS_KEY"),
"storage_secret_key": get_env("MODELSTORAGE_SECRET_KEY"),
"storage_bucket": get_env("MODELSTORAGE_BUCKET", "fedn-models"),
"context_bucket": get_env("MODELSTORAGE_CONTEXT_BUCKET", "fedn-context"),
"storage_secure_mode": bool(get_env("MODELSTORAGE_SECURE_MODE", False)),
}
}
else:
# else use the default file
get_environment_config()
file = MODELSTORAGE_CONFIG
with open(file, 'r') as config_file:
try:
settings = dict(yaml.safe_load(config_file))
Expand All @@ -65,8 +107,14 @@ def get_network_config(file=None):
:rtype: str
"""
if file is None:
get_environment_config()
file = STATESTORE_CONFIG
# check if environment variables are set
network_id = get_env("NETWORK_ID", "fedn-network")
if network_id is not None:
return network_id
else:
# else use the default file
get_environment_config()
file = STATESTORE_CONFIG
with open(file, 'r') as config_file:
try:
settings = dict(yaml.safe_load(config_file))
Expand Down

0 comments on commit 8907977

Please sign in to comment.