stacker
stacker copied to clipboard
Document programatic way to use stacker
I have a use case where non-technical staff need access to build and destroy stacks. My goal is to put a simple web interface in place over top of whatever (trying to move away from my hand-coded stack builder). I can mimic command-line usage to run stacker commands, but have a sticking point with access to things like the output of info. Is there any documentation or suggestions on how I can accomplish this? Is there an official way to use stacker progamatically?
Hey @1ab23c - thanks for the issue. There currently isn't any attempt to document the best way to use stacker as a library, other than to share the API documentation. That said, a little while back someone asked a similar question in the stacker Slack team, and @ejholmes provided some guidance here:
https://gist.github.com/ejholmes/1cd43e07bbb761e5544bcac826b10daf
Does that help?
I'll have a play with that approach. What I have been using is code re-purposed from a test class (test_stacker) which uses parse_args to process an list of command-line arguments:
from stacker.commands import Stacker stacker = Stacker() args = stacker.parse_args([name, env, cfg]) stacker.configure(args) stacker.run(args)
where the name is "info", or "build" etc. and env and cfg are file paths.
My main stick point, however, is logging. I assumed that I could just add another handler to the logger object in either the main Stacker class or the action. So far that hasn't worked. Any tips in that regard?
I fixed the logging issue - a problem with my lack of familiarity with python logging :( - and now have working code that parses the configuration and environment files to build the context arguments; it all seems to work well. Maybe a section could be added to the documentation with the code from @ejholmes and some explanation. Other than that I'm happy to close this issue.
@1ab23c I'd be all for a new section in the documentation - if you're up for it, please submit a PR - otherwise I'll leave this open and change the title so someone can pick it up when they get the chance. Thanks again!