Skip to content

Instantly share code, notes, and snippets.

@ereyes01
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ereyes01/b36fb77013af85d338f8 to your computer and use it in GitHub Desktop.
Save ereyes01/b36fb77013af85d338f8 to your computer and use it in GitHub Desktop.
Containable - More Detailed Python Mockup
"""
A simple script that deploys the website deployment module to an EC2 server.
"""
import containable
import my_website
website_blueprint = my_website.MyWebsite(nginx_config_path="/work/my-nginx.conf",
git_url="http://github.com/me/website.git")
box = containable.Box(cores=1, ram="1GB", volume="8GB")
box.create(containable.AWS_EC2, api_key="my-api-key",
ssh_key="/my/ssh/key")
box.deploy(website_blueprint)
"""
This is a deployment for a simple web server with a web site using the Python binding.
The MyWebsite class encapsulates the deployment steps of the site and server. You
can import this in more complicated deployments, parameterize as you need, and scale
to as many servers as you like.
"""
import containable
class MyWebsite(containable.Deployment):
def __init__(self, nginx_config_path=None, git_url=None):
with open(nginx_config_path) as config_file:
config_contents = config_file.read()
self.nginx_config = containable.File(path="/etc/nginx/sites-available/my-website",
contents=config_contents)
self.site_enabled = containable.Symlink(path="/etc/nginx/sites-enabled/my-website",
target=self.nginx_config.path)
self.site_repo = containable.GitRepo(git_url, path="/opt/site", head="origin/master")
def deploy(self, box):
box.install_package("nginx")
box.deploy([self.site_repo, self.nginx_config, self.site_enabled])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment