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

Running packaged deploys programmatically #989

Open
madisvain opened this issue Jun 12, 2023 · 1 comment
Open

Running packaged deploys programmatically #989

madisvain opened this issue Jun 12, 2023 · 1 comment

Comments

@madisvain
Copy link

I would like to use the packaged deployments from within Python code to build a more dynamic deployer system which would have a UI.

How would I go about running the packaged deployments this way? By just calling the packaged deploy I get a exception:
type object 'State' has no attribute 'config'

Is there a way to do this and could an example be provided? In the documentation currently only how to use the CLI is extensively described.
https://docs.pyinfra.com/en/2.x/deploy-process.html

@phlummox
Copy link

In case it's useful – I noticed that there's some information on how to use PyInfra via its API here: https://docs.pyinfra.com/en/2.x/api/index.html

However, it's not entirely clear from this how you'd invoke a packaged deploy. In the CLI code, it looks like the following function is responsible for loading a deploy script:

pyinfra/pyinfra_cli/util.py

Lines 191 to 193 in 9256e6a

def load_deploy_file(state: "State", filename):
state.current_deploy_filename = filename
_parallel_load_hosts(state, lambda: exec_file(filename), filename)

It's not entirely clear to me what the invoked _parallel_load_hosts function is doing, but if you look at it, it seems to be passing a pyinfra.api.state.State object to the current Context, and ultimately, compiling the packaged deploy and executing it with Python's builtin exec function (here).

(I have a somewhat similar problem, trying to execute a particular function programmatically – if I end up creating an issue for it, I'll link this one too, in case the answers might be of assistance to you too.)

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

2 participants