Learn to write modules month: a few new ideas for the taking: git and pip


#1

I opened a few tickets for some good module ideas to write:

git and pip.

The git module should probably support checkouts using SSH protocol first, and to do this, we can make sure the command class already forwards SSH_AUTH_SOCK if set in the parent environment. In other words, the SSH keys of the push invocation should be usable and like magic, not have to be specified.

An option for extra flags can be provided to avoid creating too many options.

While it could extend from a generic Scm Type, I'm not sure that's actually important. It's clearer to see "Git()" in the policy than "Scm()"

Another easy idea is to add a pip module.

This can use the provider.copy_file() feature in the current code, so maybe the requirements file is the only thing we support. That keeps it super easy.

If no one wants to take either of these, I'm going to do them, I just wanted to share them as I think they are easy ideas that will get a lot of mileage.

In the coming push implementation, if you install remote dependencies instead of letting mitogen push them (like jinja2) they actually offer some additional speedups, so that will benefit everyone with the pip module.

git is of course used everywhere, but the most common use case is deploying your applications direct from source control (common for dynamic language apps if not so much compiled apps) so it's going to be one of the most used modules in opsmop for sure.


#2

Suggested syntaxes might look like this, but can probably be improved/upgraded?

Package("dill", version=">=0.2.8.2", method='pip'), # we really should support the basic way of doing it anyway

Package(from_file="files/requirements.txt", method='pip')

Git("/opt/checkout/dir", branch="", from_repo="ssh://...", options="...")

Where options is just any extra CLI flags to add. It would be a very basic wrapper.

In addition to "branch", it should also take a parameter "version" (takes a sha) and "tag", which are all set as mutually_exclusive in the provider code.


#3

Another good idea is the Shell module, which would look like this:

Shell("/path/to/script")

Which simply runs a script.

If we use "self.slurp()" to implement it ... we automatically make it work in the local mode and also in the upcoming (today!) push mode.

What it would need to do is write the script to a temporary file, chmod +x it, and then execute it with "self.run(...)"

This would be a really short module!


#4

I attempted to write a pip module however, after doing a version check it doesn't "do apply"

It appears to be just like your other modules which work fine for me. Any ideas on where to look? Here is what I have so far:


#5

Nvm, I was using version in the wrong way, but it is now fixed and working.


#6

Excellent!

Let me know if you have any more questions!