Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users specify the user-specific config via an environmental variable #1361

Closed
gerases opened this issue Apr 19, 2024 · 7 comments
Closed

Comments

@gerases
Copy link

gerases commented Apr 19, 2024

Ability to specify location of the user mock.cfg with an environmental variable

I would like to be able to specify an additional location for the user-based mock.cfg file based on an environmental variable. Currently these locations are:

  1. .mock/user.cfg
  2. .config/mock.cfg

The reason is that I have tens of projects with different customizations and unless it's done it's difficult to manage.

@xsuchy
Copy link
Member

xsuchy commented Apr 19, 2024

???
While mock -r foo searches for the files you mentioned, you can still use mock -r some/path/foo.cfg and mock will use this full path.
When the parameter has suffix .cfg it is interpreted as a path.
Is this sufficient for you?

@gerases
Copy link
Author

gerases commented Apr 20, 2024

So I have the main configuration files (e.g. centos7) under /etc/mock and mock is already called with something like -r /etc/mock/centos7.

Now, if I want to tweak something without changing that system wide config, I could override a config opt by putting my them into ~/.config/mock.cfg, right? But that's not great for my case because each of my builds may require a different override and I would have to change ~/.config/mock.cfg for each custom build, no?

If the above is how it works, then I would like to instruct mock to look into an additional place for the overrides - via an environment variable perhaps.

Let me know if this makes sense or not

@gerases
Copy link
Author

gerases commented Apr 20, 2024

Here's what I'm proposing:

diff --git a/mock/py/mockbuild/config.py b/mock/py/mockbuild/config.py
index 2178c5b7..0f8116f0 100644
--- a/mock/py/mockbuild/config.py
+++ b/mock/py/mockbuild/config.py
@@ -891,6 +891,9 @@ def load_config(config_path, name):
     cfg = os.path.join(os.path.expanduser(
         '~' + pwd.getpwuid(os.getuid())[0]), '.config/mock.cfg')
     do_update_config(log, config_opts, cfg, name)
+    cfg = os.environ.get("MOCK_CFG_PATH", None)
+    if cfg:
+        do_update_config(log, config_opts, cfg, name)

@xsuchy
Copy link
Member

xsuchy commented Apr 21, 2024

I understand what you are trying to achieve. But I think this add unnecessary complexity to Mock.

You can achieve the same by

$ cat ~/my/configs/for/tests/one.cfg
include('/etc/mock/centos+epel-7-x86_64.cfg')
#your specific overrides
config_opts['foo1'] = 'bar1'

$ cat ~/my/configs/for/tests/two.cfg
include('/etc/mock/centos+epel-7-x86_64.cfg')
#your specific overrides
config_opts['foo2'] = 'bar2'

$ WHAT=one
$ mock -r  ~/my/configs/for/tests/${WHAT}.cfg  some.src.rpm

or

$ cat ~/testdir1/centos7.cfg
include('/etc/mock/centos+epel-7-x86_64.cfg')
#your specific overrides
config_opts['foo1'] = 'bar1'

$ cat ~/testdir2/centos7.cfg
include('/etc/mock/centos+epel-7-x86_64.cfg')
#your specific overrides
config_opts['foo2'] = 'bar2'

$ WHAT=testdir2
$ mock -r  ~/${WHAT}/centos7.cfg  some.src.rpm

The last one does exactly what you are trying to achieve. Right?

@praiskup
Copy link
Member

Or, can you use something like this wrapper?

$ cat ~/bin/mymock 
#! /bin/sh
test -n "$MOCK_CFG_PATH" && exec mock -r "$MOCK_CFG_PATH" "$@"
exec mock "$@"

@gerases
Copy link
Author

gerases commented Apr 21, 2024

I understand what you are trying to achieve. But I think this add unnecessary complexity to Mock.

You can achieve the same by

$ cat ~/my/configs/for/tests/one.cfg
include('/etc/mock/centos+epel-7-x86_64.cfg')
#your specific overrides
config_opts['foo1'] = 'bar1'

$ cat ~/my/configs/for/tests/two.cfg
include('/etc/mock/centos+epel-7-x86_64.cfg')
#your specific overrides
config_opts['foo2'] = 'bar2'

$ WHAT=one
$ mock -r  ~/my/configs/for/tests/${WHAT}.cfg  some.src.rpm

or

$ cat ~/testdir1/centos7.cfg
include('/etc/mock/centos+epel-7-x86_64.cfg')
#your specific overrides
config_opts['foo1'] = 'bar1'

$ cat ~/testdir2/centos7.cfg
include('/etc/mock/centos+epel-7-x86_64.cfg')
#your specific overrides
config_opts['foo2'] = 'bar2'

$ WHAT=testdir2
$ mock -r  ~/${WHAT}/centos7.cfg  some.src.rpm

The last one does exactly what you are trying to achieve. Right?

Ah yeah this could work indeed. The problem include directive is crucial here. I can go with this and post here in case there’s some unexpected complication. Thank you!!

@gerases gerases closed this as completed Apr 21, 2024
@gerases
Copy link
Author

gerases commented Apr 21, 2024

i am closing this for now.

@nikromen nikromen moved this from Needs triage to Done in CPT Kanban Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants