Skip to content

Commit

Permalink
fix and add more config envs
Browse files Browse the repository at this point in the history
  • Loading branch information
Wrede committed Feb 27, 2024
1 parent a6597ab commit 3baafbb
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 59 deletions.
2 changes: 1 addition & 1 deletion config/reducer-settings.override.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ services:
reducer:
volumes:
- ${HOST_REPO_DIR:-.}/fedn:/app/fedn
- ${HOST_REPO_DIR:-.}/config/settings-reducer.yaml:/app/config/settings-reducer.yaml
- ${HOST_REPO_DIR:-.}/config/settings-controller.yaml:/app/config/settings-controller.yaml
File renamed without changes.
37 changes: 22 additions & 15 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,28 @@ services:
- USER=test
- PROJECT=project
- FLASK_DEBUG=1
# Controller
- FEDN_CONTROLLER_HOST=api-server
- FEDN_CONTROLLER_PORT=8092
- FEDN_CONTROLLER_DEBUG=True
- FEDN_CONTROLLER_CONFIG=/app/config/settings-controller.yaml
# Statestore
- STATESTORE_HOST=mongo
- STATESTORE_PORT=6534
- STATESTORE_USER=fedn_admin
- STATESTORE_PASSWORD=password
- FEDN_STATESTORE_HOST=mongo
- FEDN_STATESTORE_PORT=6534
- FEDN_STATESTORE_USER=fedn_admin
- FEDN_STATESTORE_PASSWORD=password
# will be overriden by env vars above
- STATESTORE_CONFIG=/app/config/settings-reducer.yaml
- FEDN_STATESTORE_CONFIG=/app/config/settings-controller.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
- FEDN_MODELSTORAGE_HOST=minio
- FEDN_MODELSTORAGE_PORT=9000
- FEDN_MODELSTORAGE_ACCESS_KEY=fedn_admin
- FEDN_MODELSTORAGE_SECRET_KEY=password
- FEDN_MODELSTORAGE_BUCKET=fedn-models
- FEDN_MODELSTORAGE_CONTEXT_BUCKET=fedn-context
- FEDN_MODELSTORAGE_SECURE_MODE=False
# will be overriden by env vars above
- MODELSTORAGE_CONFIG=/app/config/settings-reducer.yaml
- FEDN_MODELSTORAGE_CONFIG=/app/config/settings-controller.yaml
build:
context: .
args:
Expand Down Expand Up @@ -110,9 +115,10 @@ services:
working_dir: /app
volumes:
- ${HOST_REPO_DIR:-.}/fedn:/app/fedn
- ${HOST_REPO_DIR:-.}/config:/app/config
entrypoint: [ "sh", "-c" ]
command:
- "/venv/bin/pip install --no-cache-dir -e /app/fedn && /venv/bin/fedn run combiner --init config/settings-combiner.yaml"
- "/venv/bin/pip install --no-cache-dir -e /app/fedn && /venv/bin/fedn run combiner --init config/settings-combiner.yaml.template"
ports:
- 12080:12080
healthcheck:
Expand All @@ -139,9 +145,10 @@ services:
working_dir: /app
volumes:
- ${HOST_REPO_DIR:-.}/fedn:/app/fedn
- ${HOST_REPO_DIR:-.}/config:/app/config
entrypoint: [ "sh", "-c" ]
command:
- "/venv/bin/pip install --no-cache-dir -e /app/fedn && /venv/bin/fedn run client --init config/settings-client.yaml"
- "/venv/bin/pip install --no-cache-dir -e /app/fedn && /venv/bin/fedn run client --init config/settings-client.yaml.template"
deploy:
replicas: 0
depends_on:
Expand Down
1 change: 1 addition & 0 deletions fedn/cli/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def combiner_cmd(ctx, discoverhost, discoverport, token, name, host, port, fqdn,
:param max_clients:
:param init:
"""
# TODO: Should use fedn.common.config.get_combiner_config() instead of this
config = {'discover_host': discoverhost, 'discover_port': discoverport, 'token': token, 'host': host,
'port': port, 'fqdn': fqdn, 'name': name, 'secure': secure, 'verify': verify, 'max_clients': max_clients,
'init': init}
Expand Down
132 changes: 89 additions & 43 deletions fedn/fedn/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,35 @@ def get_environment_config():
"""
global STATESTORE_CONFIG
global MODELSTORAGE_CONFIG

STATESTORE_CONFIG = os.environ.get('STATESTORE_CONFIG',
'/workspaces/fedn/config/settings-reducer.yaml.template')
MODELSTORAGE_CONFIG = os.environ.get('MODELSTORAGE_CONFIG',
'/workspaces/fedn/config/settings-reducer.yaml.template')

global COMBINER_CONFIG
global CONTROLLER_CONFIG

STATESTORE_CONFIG = os.environ.get('FEDN_STATESTORE_CONFIG',
'/workspaces/fedn/config/settings-controller.yaml.template')
MODELSTORAGE_CONFIG = os.environ.get('FEDN_MODELSTORAGE_CONFIG',
'/workspaces/fedn/config/settings-controller.yaml.template')
COMBINER_CONFIG = os.environ.get('FEDN_COMBINER_CONFIG',
'/workspaces/fedn/config/settings-combiner.yaml.template')
CONTROLLER_CONFIG = os.environ.get('FEDN_CONTROLLER_CONFIG',
'/workspaces/fedn/config/settings-controller.yaml.template')

def read_config_file(file):
""" Read a yaml configuration file.
:param file: The configuration file path.
:type file: str
:return: The configuration as a dict.
:rtype: dict
"""
with open(file, 'r') as config_file:
try:
config = dict(yaml.safe_load(config_file))
except yaml.YAMLError as e:
raise (e)
return config

def get_statestore_config(file=None):
""" Get the statestore configuration from file.
""" Get the statestore configuration.
:param file: The statestore configuration file (yaml) path (optional).
:type file: str
Expand All @@ -56,31 +76,27 @@ def get_statestore_config(file=None):
"""
if file is None:
# check if environment variables are set
host = get_env("STATESTORE_HOST", "mongo")
host = get_env("FEDN_STATESTORE_HOST")
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"),
"port": int(get_env("FEDN_STATESTORE_PORT", 6534)),
"username": get_env("FEDN_STATESTORE_USER", "fedn_admin"),
"password": get_env("FEDN_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))
except yaml.YAMLError as e:
raise (e)
settings = read_config_file(file)
return settings["statestore"]


def get_modelstorage_config(file=None):
""" Get the model storage configuration from file.
""" Get the model storage configuration.
:param file: The model storage configuration file (yaml) path (optional).
:type file: str
Expand All @@ -89,29 +105,25 @@ def get_modelstorage_config(file=None):
"""
if file is None:
# check if environment variables are set
host = get_env("MODELSTORAGE_HOST", "minio")
host = get_env("FEDN_MODELSTORAGE_HOST")
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": get_boolean_env("MODELSTORAGE_SECURE_MODE", False),
"storage_port": int(get_env("FEDN_MODELSTORAGE_PORT", 9000)),
"storage_access_key": get_env("FEDN_MODELSTORAGE_ACCESS_KEY"),
"storage_secret_key": get_env("FEDN_MODELSTORAGE_SECRET_KEY"),
"storage_bucket": get_env("FEDN_MODELSTORAGE_BUCKET", "fedn-models"),
"context_bucket": get_env("FEDN_MODELSTORAGE_CONTEXT_BUCKET", "fedn-context"),
"storage_secure_mode": get_boolean_env("FEDN_MODELSTORAGE_SECURE_MODE", False),
}
}
else:
# else use the default file
# else use the config file
get_environment_config()
file = MODELSTORAGE_CONFIG
with open(file, 'r') as config_file:
try:
settings = dict(yaml.safe_load(config_file))
except yaml.YAMLError as e:
raise (e)
settings = read_config_file(file)
return settings["storage"]


Expand All @@ -131,29 +143,63 @@ def get_network_config(file=None):
else:
# else use the default file
get_environment_config()
# TODO: This is a temporary fix, network_id is the database name in the statestore
file = STATESTORE_CONFIG
with open(file, 'r') as config_file:
try:
settings = dict(yaml.safe_load(config_file))
except yaml.YAMLError as e:
raise (e)
settings = read_config_file(file)
return settings["network_id"]


def get_controller_config(file=None):
""" Get the controller configuration from file.
""" Get the controller configuration.
:param file: The controller configuration file (yaml) path (optional).
:type file: str
:return: The controller configuration as a dict.
:rtype: dict
"""
if file is None:
get_environment_config()
file = STATESTORE_CONFIG
with open(file, 'r') as config_file:
try:
settings = dict(yaml.safe_load(config_file))
except yaml.YAMLError as e:
raise (e)
# check if environment variables are set
host = get_env("FEDN_CONTROLLER_HOST")
if host is not None:
return {
"host": host,
"port": int(get_env("FEDN_CONTROLLER_PORT", 8092)),
"debug": get_boolean_env("FEDN_CONTROLLER_DEBUG", False),
}
else:
# else use the default file
get_environment_config()
file = CONTROLLER_CONFIG
settings = read_config_file(file)
return settings["controller"]

def get_combiner_config(file=None):
""" Get the combiner configuration.
:param file: The combiner configuration file (yaml) path (optional).
:type file: str
:return: The combiner configuration as a dict.
:rtype: dict
"""
if file is None:
# check if environment variables are set
host = get_env("FEDN_COMBINER_HOST")
if host is not None:
return {
"host": host,
"name": get_env("FEDN_COMBINER_NAME"),
"port": int(get_env("FEDN_COMBINER_PORT", 12080)),
"max_clients": int(get_env("FEDN_COMBINER_MAX_CLIENTS", 30)),
"network_id": get_network_config(),
"discovery_host": get_env("FEDN_CONTROLLER_HOST"),
"discovery_port": int(get_env("FEDN_CONTROLLER_PORT", 8092)),
"fqdn": get_env("FEDN_COMBINER_FQDN"),
"secure": get_boolean_env("FEDN_GRPC_SECURE", False),
"verify": get_boolean_env("FEDN_VERIFY_TLS", False),
}
else:
# else use the default file
get_environment_config()
file = COMBINER_CONFIG
settings = read_config_file(file)
return settings["combiner"]

0 comments on commit 3baafbb

Please sign in to comment.