You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the detailed report, @paras41617 🙏 We need to do some maintenance work first because currently our tests are failing on the head commit. We will look into it afterwards.
Lets say you have the above str, if you run app.py from inside the api dir and outside with ``python3 api/app.pyboth will yield diff results, as most probably config written wrt$(pwd)/api/` (because we decided to pu config in api dir).
All you need to do is be consistent with how you envoke app.py in Dockerfile and in local machine.
There could be a 2 better way to deal with this:
If foca restricts config to only absolute path (which I don't think is ideal).
Consumers of foca should use jinja templating to create a temporary config files. This IMO solves another imp problem of setting up a dev env. Lets say I wanted to test my API with my mongo atlas, but my prod should be a pod or a container. This would make more sense and be less pain to inject values in jinja. Take a look at below.
fromjinja2importEnvironment, FileSystemLoaderimportosfrompathlibimportPathimporttempfiledefmain():
config_path=Path(__file__).parent/"config.yaml"ifnotconfig_path.exists():
raiseFileNotFoundError(f"Config file not found: {config_path}")
environment=os.getenv('ENV', 'dev') # Default to 'dev' if ENV is not setdb_port=os.getenv('DB_PORT', '5432') # Default to '5432' if DB_PORT is not setenv=Environment(loader=FileSystemLoader(config_path.parent))
template=env.get_template(config_path.name)
rendered_config=template.render(environment=environment, db_port=db_port)
# Create a temporary config file with the rendered templatewithtempfile.NamedTemporaryFile(delete=False, suffix='.yaml') astmp_config_file:
tmp_config_file.write(rendered_config.encode())
tmp_config_path=tmp_config_file.name# Create app object using the temporary config filefoca=Foca(
config_file=tmp_config_path,
custom_config_model="service_models.custom_config.CustomConfig",
)
foca.config_fileapp=foca.create_app()
# Optionally delete the temporary file after creating the appos.remove(tmp_config_path)
if__name__=="__main__":
main()
I think there are other options as well, e.g., anchoring the relative path not to the caller's current working directory, but to some other reference, e.g., the repository root path. I will take care of that when refactoring FOCA.
I will think about the templating suggestion as well (another good point), though I feel that that is another issue. We should probably take the config.yaml files out of the code package and put them in deployment/, together with the docker-compose.yml files. We could then also think about creating a config map in Kubernetes, so that params can be adjusted on running services (another long-standing open issue).
The reported error is caused by relative paths in the config being resolved against the current working directory, so the app only works when started from one specific directory. Decision:
Relative paths in a config file are resolved against the directory of the base config file (the first file in config_file, see feat: Adding DEV, PROD, TEST environment variables #247), not the working directory. Without a config file (config built in code), they fall back to the current working directory, as today.
Applies to all file paths FOCA reads: api.specs[].path, security.access_control.api_specs and security.access_control.model. Absolute paths are unchanged.
Implementation: ConfigParser validates with Config.model_validate(data, context={"base_dir": ...}); the path validators in SpecConfig and AccessControlConfig use info.context. Expose the resolved base directory (e.g. Foca.config_dir) so apps can resolve paths in custom the same way.
Breaking changes
Configs with relative paths written for the working directory (e.g. Docker images with WORKDIR above the config directory) must be relative to the config file's directory instead. Check proTES and cloud-registry configs and Dockerfiles.
Planned PR
9 (feat(config): config overlays, relative paths), together with #247.
Activity
uniqueg commentedon May 18, 2024
Thanks for the detailed report, @paras41617 🙏 We need to do some maintenance work first because currently our tests are failing on the head commit. We will look into it afterwards.
uniqueg commentedon May 20, 2024
Currently blocked by #188
JaeAeich commentedon May 24, 2024
TL;DR: relative path causing issues, check this fix.
@uniqueg
The issue (well not really an issue), is that configs use relative paths.
Lets say you have the above str, if you run
app.pyfrom inside theapidir and outside with ``python3 api/app.pyboth will yield diff results, as most probably config written wrt$(pwd)/api/` (because we decided to pu config in api dir).All you need to do is be consistent with how you envoke
app.pyinDockerfileand in local machine.There could be a 2 better way to deal with this:
focarestricts config to only absolute path (which I don't think is ideal).podor acontainer. This would make more sense and be less pain to inject values injinja. Take a look at below.uniqueg commentedon May 24, 2024
Thanks @JaeAeich.
I think there are other options as well, e.g., anchoring the relative path not to the caller's current working directory, but to some other reference, e.g., the repository root path. I will take care of that when refactoring FOCA.
I will think about the templating suggestion as well (another good point), though I feel that that is another issue. We should probably take the
config.yamlfiles out of the code package and put them indeployment/, together with thedocker-compose.ymlfiles. We could then also think about creating a config map in Kubernetes, so that params can be adjusted on running services (another long-standing open issue).uniqueg commentedon Oct 18, 2026
Refined proposal
The reported error is caused by relative paths in the config being resolved against the current working directory, so the app only works when started from one specific directory. Decision:
config_file, see feat: AddingDEV,PROD,TESTenvironment variables #247), not the working directory. Without a config file (config built in code), they fall back to the current working directory, as today.api.specs[].path,security.access_control.api_specsandsecurity.access_control.model. Absolute paths are unchanged.ConfigParservalidates withConfig.model_validate(data, context={"base_dir": ...}); the path validators inSpecConfigandAccessControlConfiguseinfo.context. Expose the resolved base directory (e.g.Foca.config_dir) so apps can resolve paths incustomthe same way.DEV,PROD,TESTenvironment variables #247) use the same base directory, so a path means the same thing whichever file sets it.Acceptance criteria
status: blockedlabel; no longer depends on build: add support for Connexion 3+ #188.Breaking changes
Configs with relative paths written for the working directory (e.g. Docker images with
WORKDIRabove the config directory) must be relative to the config file's directory instead. Check proTES and cloud-registry configs and Dockerfiles.Planned PR
9 (
feat(config): config overlays, relative paths), together with #247.