Hadron / carthage

Carthage is an Infrastructure as Code (IAC) framework
Other
8 stars 4 forks source link

Overriding base_dir in config results in incorrect path #61

Closed srak289 closed 3 months ago

srak289 commented 7 months ago

carthage_plugin.yml

config:
  plugins:
  - https://github.com/hadron/carthage_aws
  authorized_keys: data/authorized_keys
  production_ssh_agent: true
  base_dir: ./output

Traceback:

Traceback (most recent call last):
  File "/root/project/blueteam_layout/../carthage/bin/carthage-runner", line 204, in <module>
    base_injector(carthage.plugins.load_plugin, plugin)
  File "/root/project/blueteam_layout/../carthage/carthage/dependency_injection/base.py", line 485, in __call__
    return self._instantiate(
           ^^^^^^^^^^^^^^^^^^
  File "/root/project/blueteam_layout/../carthage/carthage/dependency_injection/base.py", line 722, in _instantiate
    res = handle_result(mark_instantiation_done=(_instantiation_context is not None))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/project/blueteam_layout/../carthage/carthage/dependency_injection/base.py", line 620, in handle_result
    res = cls(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^
  File "/root/project/blueteam_layout/../carthage/carthage/plugins.py", line 107, in load_plugin
    _handle_plugin_config(injector, metadata, metadata_path, ignore_import_errors=ignore_import_errors)
  File "/root/project/blueteam_layout/../carthage/carthage/plugins.py", line 267, in _handle_plugin_config
    config.load_yaml(yaml.dump(metadata['config']), path=path, ignore_import_errors=ignore_import_errors)
  File "/root/project/blueteam_layout/../carthage/carthage/config/layout.py", line 110, in load_yaml
    enable_plugin(p, ignore_import_errors=ignore_import_errors)
  File "/root/project/blueteam_layout/../carthage/carthage/config/layout.py", line 135, in enable_plugin
    base_injector(load_plugin, plugin, ignore_import_errors=ignore_import_errors)
  File "/root/project/blueteam_layout/../carthage/carthage/dependency_injection/base.py", line 620, in handle_result
    res = cls(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^
  File "/root/project/blueteam_layout/../carthage/carthage/plugins.py", line 94, in load_plugin
    raise FileNotFoundError(f'{metadata_path} not found')
FileNotFoundError: /root/project/blueteam_layout/output/checkout/carthage_aws/carthage_plugin.yml not found
make: *** [Makefile:11: deploy] Error 1

Actual file path:

root@carthage:~/project/blueteam_layout# ls output/checkout/output/checkout/carthage_aws/carthage_plugin.yml 
output/checkout/output/checkout/carthage_aws/carthage_plugin.yml
hartmans commented 4 months ago

Let me make sure I'm understanding. If you override base_dir in a plugin to a relative path, then the checkout_path evaluated between the time of checkout is different than the path used to look into the checkout. Have I got that right?

This definitely looks like a bug that I will fix. Be aware though that overriding base_dir in a plugin will definitely produce strange results if that plugin is ever a dependency of anything else.

srak289 commented 3 months ago

So I usually want all of the local carthage artifacts to be in the directory where I'm running my layout and I like base_dir: . for that.

I saw the issue again this morning where running the layout caused carthage-base to be checked out to ./checkout/checkout/carthage-base but the plugin finder was expecting to find ./checkout/carthage-base/carthage_plugin.yml, but I simply moved past it at the time by moving ./checkout/checkout up one level rather than debugging it.