{"action":"created","comment":{"url":"https://api.github.com/repos/pydanny/cookiecutter-django/pulls/comments/41308951","id":41308951,"diff_hunk":"@@ -0,0 +1,249 @@\n+# -*- coding: utf-8 -*-\n+\"\"\"\n+This is a collection of useful utility functions when working with docker on different environments.\n+\n+In order to use these functions, install fabric on your local machine with::\n+\n+    pip install fabric\n+\n+Please note: Fabric is a remote code execution tool, NOT a remote configuration tool. While you can copy files\n+from here to there, it is not a good replacement for salt or ansible in this regard.\n+\n+There is a function called `production` where you need to fill in the details about your production machine(s).\n+\n+You can then run::\n+\n+    fab production status\n+\n+to get the status of your stack\n+\n+To list all available commands, run::\n+\n+    fab -l\n+\"\"\"\n+\n+from __future__ import absolute_import, print_function, unicode_literals\n+from fabric.operations import local as lrun, run, sudo\n+from fabric.api import *\n+from fabric.colors import green, red, yellow\n+from fabric.contrib.console import confirm\n+\n+\n+def local():\n+    \"\"\"\n+    Work on the local environment\n+    \"\"\"\n+    env.compose_file = \"dev.yml\"\n+    env.project_dir = \".\"\n+    env.run = lrun\n+    env.cd = lcd\n+\n+\n+def production():\n+    \"\"\"\n+    Work on the production environment\n+    \"\"\"\n+    env.hosts = [\"\"]  # list the ip addresses or domain names of your production boxes here\n+    env.port = 22  # ssh port\n+    env.user = \"root\"  # remote user, see `env.run` if you don't log in as root\n+\n+    env.compose_file = \"docker-compose.yml\"\n+    env.project_dir = \"\"  # this is the project dir where your code lives on this machine\n+\n+    # if you don't use key authentication, add your password here\n+    # env.password = \"foobar\"\n+    # if your machine has no bash installed, fall back to sh\n+    # env.shell = \"/bin/sh -c\"\n+\n+    env.run = run  # if you don't log in as root, replace with 'env.run = sudo'\n+    env.cd = cd\n+\n+\n+def rollback(commit=\"HEAD~1\"):\n+    \"\"\"\n+    Rollback to a previous commit and build the stack\n+    :param commit: Commit you want to roll back to. Default is the previous commit\n+    \"\"\"\n+    with env.cd(env.project_dir):\n+        env.run(\"git checkout {}\".format(commit))\n+\n+    docker_compose(\"build\")\n+\n+\n+def deploy():\n+    \"\"\"\n+    Pulls the latest changes from master, rebuilt and restarts the stack\n+    \"\"\"\n+    with env.cd(env.project_dir):\n+        env.run(\"git pull origin master\")\n+\n+    build()\n+    restart()\n+\n+\n+def scale(service, n):\n+    \"\"\"\n+    Scale a service\n+    :param service: Service to scale\n+    :param n: Number of containers\n+    \"\"\"\n+    if service not in [\"celeryworker\"]:\n+        print(red(\"{} is not scalabale, aborting\".format(service)))\n+        return\n+    docker_compose(\"scale {service} {n}\".format(service=service, n=n))\n+\n+\n+def restart():\n+    \"\"\"\n+    Restart all services\n+    \"\"\"\n+    docker_compose(\"restart\")\n+\n+\n+def build(cache=True):\n+    \"\"\"\n+    Builds the the stack\n+    :param cache: Use docker cache. Default is True\n+    \"\"\"\n+    docker_compose(\"build\" if cache else \"build --no-cache\")\n+\n+\n+def status():","path":"{{cookiecutter.repo_name}}/fabfile.py","position":111,"original_position":111,"commit_id":"d1fe1069c747ca542f11182ac15d0d783dfa0475","original_commit_id":"d1fe1069c747ca542f11182ac15d0d783dfa0475","user":{"login":"audreyr","id":74739,"avatar_url":"https://avatars.githubusercontent.com/u/74739?v=3","gravatar_id":"","url":"https://api.github.com/users/audreyr","html_url":"https://github.com/audreyr","followers_url":"https://api.github.com/users/audreyr/followers","following_url":"https://api.github.com/users/audreyr/following{/other_user}","gists_url":"https://api.github.com/users/audreyr/gists{/gist_id}","starred_url":"https://api.github.com/users/audreyr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/audreyr/subscriptions","organizations_url":"https://api.github.com/users/audreyr/orgs","repos_url":"https://api.github.com/users/audreyr/repos","events_url":"https://api.github.com/users/audreyr/events{/privacy}","received_events_url":"https://api.github.com/users/audreyr/received_events","type":"User","site_admin":false},"body":"I think `ps` would be easier to type/remember. But this is minor; I'm fine with leaving it as-is if you prefer.","created_at":"2015-10-06T19:14:49Z","updated_at":"2015-10-06T19:14:49Z","html_url":"https://github.com/pydanny/cookiecutter-django/pull/369#discussion_r41308951","pull_request_url":"https://api.github.com/repos/pydanny/cookiecutter-django/pulls/369","_links":{"self":{"href":"https://api.github.com/repos/pydanny/cookiecutter-django/pulls/comments/41308951"},"html":{"href":"https://github.com/pydanny/cookiecutter-django/pull/369#discussion_r41308951"},"pull_request":{"href":"https://api.github.com/repos/pydanny/cookiecutter-django/pulls/369"}}},"pull_request":{"url":"https://api.github.com/repos/pydanny/cookiecutter-django/pulls/369","id":46891146,"html_url":"https://github.com/pydanny/cookiecutter-django/pull/369","diff_url":"https://github.com/pydanny/cookiecutter-django/pull/369.diff","patch_url":"https://github.com/pydanny/cookiecutter-django/pull/369.patch","issue_url":"https://api.github.com/repos/pydanny/cookiecutter-django/issues/369","number":369,"state":"open","locked":false,"title":"WIP: docker-controls","user":{"login":"jayfk","id":2930472,"avatar_url":"https://avatars.githubusercontent.com/u/2930472?v=3","gravatar_id":"","url":"https://api.github.com/users/jayfk","html_url":"https://github.com/jayfk","followers_url":"https://api.github.com/users/jayfk/followers","following_url":"https://api.github.com/users/jayfk/following{/other_user}","gists_url":"https://api.github.com/users/jayfk/gists{/gist_id}","starred_url":"https://api.github.com/users/jayfk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jayfk/subscriptions","organizations_url":"https://api.github.com/users/jayfk/orgs","repos_url":"https://api.github.com/users/jayfk/repos","events_url":"https://api.github.com/users/jayfk/events{/privacy}","received_events_url":"https://api.github.com/users/jayfk/received_events","type":"User","site_admin":false},"body":"Adds utility functions for docker. Would love to see some testing before giving it a go.\r\n\r\nPlease take a look at the code to see what it does. Most of it is pretty straightforward and documented.\r\n\r\nTo do:\r\n- [ ] More documentation\r\n- [ ] Implement all database controls","created_at":"2015-10-06T11:31:56Z","updated_at":"2015-10-06T19:14:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c4590c5602a14154c468346453f16546a7d2d31b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pydanny/cookiecutter-django/pulls/369/commits","review_comments_url":"https://api.github.com/repos/pydanny/cookiecutter-django/pulls/369/comments","review_comment_url":"https://api.github.com/repos/pydanny/cookiecutter-django/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pydanny/cookiecutter-django/issues/369/comments","statuses_url":"https://api.github.com/repos/pydanny/cookiecutter-django/statuses/d1fe1069c747ca542f11182ac15d0d783dfa0475","head":{"label":"jayfk:docker-controls","ref":"docker-controls","sha":"d1fe1069c747ca542f11182ac15d0d783dfa0475","user":{"login":"jayfk","id":2930472,"avatar_url":"https://avatars.githubusercontent.com/u/2930472?v=3","gravatar_id":"","url":"https://api.github.com/users/jayfk","html_url":"https://github.com/jayfk","followers_url":"https://api.github.com/users/jayfk/followers","following_url":"https://api.github.com/users/jayfk/following{/other_user}","gists_url":"https://api.github.com/users/jayfk/gists{/gist_id}","starred_url":"https://api.github.com/users/jayfk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jayfk/subscriptions","organizations_url":"https://api.github.com/users/jayfk/orgs","repos_url":"https://api.github.com/users/jayfk/repos","events_url":"https://api.github.com/users/jayfk/events{/privacy}","received_events_url":"https://api.github.com/users/jayfk/received_events","type":"User","site_admin":false},"repo":{"id":39205615,"name":"cookiecutter-django","full_name":"jayfk/cookiecutter-django","owner":{"login":"jayfk","id":2930472,"avatar_url":"https://avatars.githubusercontent.com/u/2930472?v=3","gravatar_id":"","url":"https://api.github.com/users/jayfk","html_url":"https://github.com/jayfk","followers_url":"https://api.github.com/users/jayfk/followers","following_url":"https://api.github.com/users/jayfk/following{/other_user}","gists_url":"https://api.github.com/users/jayfk/gists{/gist_id}","starred_url":"https://api.github.com/users/jayfk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jayfk/subscriptions","organizations_url":"https://api.github.com/users/jayfk/orgs","repos_url":"https://api.github.com/users/jayfk/repos","events_url":"https://api.github.com/users/jayfk/events{/privacy}","received_events_url":"https://api.github.com/users/jayfk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jayfk/cookiecutter-django","description":"A cookiecutter template for creating Django projects quickly.","fork":true,"url":"https://api.github.com/repos/jayfk/cookiecutter-django","forks_url":"https://api.github.com/repos/jayfk/cookiecutter-django/forks","keys_url":"https://api.github.com/repos/jayfk/cookiecutter-django/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jayfk/cookiecutter-django/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jayfk/cookiecutter-django/teams","hooks_url":"https://api.github.com/repos/jayfk/cookiecutter-django/hooks","issue_events_url":"https://api.github.com/repos/jayfk/cookiecutter-django/issues/events{/number}","events_url":"https://api.github.com/repos/jayfk/cookiecutter-django/events","assignees_url":"https://api.github.com/repos/jayfk/cookiecutter-django/assignees{/user}","branches_url":"https://api.github.com/repos/jayfk/cookiecutter-django/branches{/branch}","tags_url":"https://api.github.com/repos/jayfk/cookiecutter-django/tags","blobs_url":"https://api.github.com/repos/jayfk/cookiecutter-django/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jayfk/cookiecutter-django/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jayfk/cookiecutter-django/git/refs{/sha}","trees_url":"https://api.github.com/repos/jayfk/cookiecutter-django/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jayfk/cookiecutter-django/statuses/{sha}","languages_url":"https://api.github.com/repos/jayfk/cookiecutter-django/languages","stargazers_url":"https://api.github.com/repos/jayfk/cookiecutter-django/stargazers","contributors_url":"https://api.github.com/repos/jayfk/cookiecutter-django/contributors","subscribers_url":"https://api.github.com/repos/jayfk/cookiecutter-django/subscribers","subscription_url":"https://api.github.com/repos/jayfk/cookiecutter-django/subscription","commits_url":"https://api.github.com/repos/jayfk/cookiecutter-django/commits{/sha}","git_commits_url":"https://api.github.com/repos/jayfk/cookiecutter-django/git/commits{/sha}","comments_url":"https://api.github.com/repos/jayfk/cookiecutter-django/comments{/number}","issue_comment_url":"https://api.github.com/repos/jayfk/cookiecutter-django/issues/comments{/number}","contents_url":"https://api.github.com/repos/jayfk/cookiecutter-django/contents/{+path}","compare_url":"https://api.github.com/repos/jayfk/cookiecutter-django/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jayfk/cookiecutter-django/merges","archive_url":"https://api.github.com/repos/jayfk/cookiecutter-django/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jayfk/cookiecutter-django/downloads","issues_url":"https://api.github.com/repos/jayfk/cookiecutter-django/issues{/number}","pulls_url":"https://api.github.com/repos/jayfk/cookiecutter-django/pulls{/number}","milestones_url":"https://api.github.com/repos/jayfk/cookiecutter-django/milestones{/number}","notifications_url":"https://api.github.com/repos/jayfk/cookiecutter-django/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jayfk/cookiecutter-django/labels{/name}","releases_url":"https://api.github.com/repos/jayfk/cookiecutter-django/releases{/id}","created_at":"2015-07-16T15:37:23Z","updated_at":"2015-07-16T15:37:24Z","pushed_at":"2015-10-06T11:24:51Z","git_url":"git://github.com/jayfk/cookiecutter-django.git","ssh_url":"git@github.com:jayfk/cookiecutter-django.git","clone_url":"https://github.com/jayfk/cookiecutter-django.git","svn_url":"https://github.com/jayfk/cookiecutter-django","homepage":"","size":2905,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pydanny:master","ref":"master","sha":"b22611a1a3c606a18c225e5ddbf666d6a94e9155","user":{"login":"pydanny","id":62857,"avatar_url":"https://avatars.githubusercontent.com/u/62857?v=3","gravatar_id":"","url":"https://api.github.com/users/pydanny","html_url":"https://github.com/pydanny","followers_url":"https://api.github.com/users/pydanny/followers","following_url":"https://api.github.com/users/pydanny/following{/other_user}","gists_url":"https://api.github.com/users/pydanny/gists{/gist_id}","starred_url":"https://api.github.com/users/pydanny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pydanny/subscriptions","organizations_url":"https://api.github.com/users/pydanny/orgs","repos_url":"https://api.github.com/users/pydanny/repos","events_url":"https://api.github.com/users/pydanny/events{/privacy}","received_events_url":"https://api.github.com/users/pydanny/received_events","type":"User","site_admin":false},"repo":{"id":12115269,"name":"cookiecutter-django","full_name":"pydanny/cookiecutter-django","owner":{"login":"pydanny","id":62857,"avatar_url":"https://avatars.githubusercontent.com/u/62857?v=3","gravatar_id":"","url":"https://api.github.com/users/pydanny","html_url":"https://github.com/pydanny","followers_url":"https://api.github.com/users/pydanny/followers","following_url":"https://api.github.com/users/pydanny/following{/other_user}","gists_url":"https://api.github.com/users/pydanny/gists{/gist_id}","starred_url":"https://api.github.com/users/pydanny/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pydanny/subscriptions","organizations_url":"https://api.github.com/users/pydanny/orgs","repos_url":"https://api.github.com/users/pydanny/repos","events_url":"https://api.github.com/users/pydanny/events{/privacy}","received_events_url":"https://api.github.com/users/pydanny/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pydanny/cookiecutter-django","description":"A Cookiecutter template for creating production-ready Django projects quickly.","fork":false,"url":"https://api.github.com/repos/pydanny/cookiecutter-django","forks_url":"https://api.github.com/repos/pydanny/cookiecutter-django/forks","keys_url":"https://api.github.com/repos/pydanny/cookiecutter-django/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pydanny/cookiecutter-django/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pydanny/cookiecutter-django/teams","hooks_url":"https://api.github.com/repos/pydanny/cookiecutter-django/hooks","issue_events_url":"https://api.github.com/repos/pydanny/cookiecutter-django/issues/events{/number}","events_url":"https://api.github.com/repos/pydanny/cookiecutter-django/events","assignees_url":"https://api.github.com/repos/pydanny/cookiecutter-django/assignees{/user}","branches_url":"https://api.github.com/repos/pydanny/cookiecutter-django/branches{/branch}","tags_url":"https://api.github.com/repos/pydanny/cookiecutter-django/tags","blobs_url":"https://api.github.com/repos/pydanny/cookiecutter-django/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pydanny/cookiecutter-django/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pydanny/cookiecutter-django/git/refs{/sha}","trees_url":"https://api.github.com/repos/pydanny/cookiecutter-django/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pydanny/cookiecutter-django/statuses/{sha}","languages_url":"https://api.github.com/repos/pydanny/cookiecutter-django/languages","stargazers_url":"https://api.github.com/repos/pydanny/cookiecutter-django/stargazers","contributors_url":"https://api.github.com/repos/pydanny/cookiecutter-django/contributors","subscribers_url":"https://api.github.com/repos/pydanny/cookiecutter-django/subscribers","subscription_url":"https://api.github.com/repos/pydanny/cookiecutter-django/subscription","commits_url":"https://api.github.com/repos/pydanny/cookiecutter-django/commits{/sha}","git_commits_url":"https://api.github.com/repos/pydanny/cookiecutter-django/git/commits{/sha}","comments_url":"https://api.github.com/repos/pydanny/cookiecutter-django/comments{/number}","issue_comment_url":"https://api.github.com/repos/pydanny/cookiecutter-django/issues/comments{/number}","contents_url":"https://api.github.com/repos/pydanny/cookiecutter-django/contents/{+path}","compare_url":"https://api.github.com/repos/pydanny/cookiecutter-django/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pydanny/cookiecutter-django/merges","archive_url":"https://api.github.com/repos/pydanny/cookiecutter-django/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pydanny/cookiecutter-django/downloads","issues_url":"https://api.github.com/repos/pydanny/cookiecutter-django/issues{/number}","pulls_url":"https://api.github.com/repos/pydanny/cookiecutter-django/pulls{/number}","milestones_url":"https://api.github.com/repos/pydanny/cookiecutter-django/milestones{/number}","notifications_url":"https://api.github.com/repos/pydanny/cookiecutter-django/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pydanny/cookiecutter-django/labels{/name}","releases_url":"https://api.github.com/repos/pydanny/cookiecutter-django/releases{/id}","created_at":"2013-08-14T17:43:31Z","updated_at":"2015-10-05T21:08:35Z","pushed_at":"2015-10-06T17:54:47Z","git_url":"git://github.com/pydanny/cookiecutter-django.git","ssh_url":"git@github.com:pydanny/cookiecutter-django.git","clone_url":"https://github.com/pydanny/cookiecutter-django.git","svn_url":"https://github.com/pydanny/cookiecutter-django","homepage":"","size":5076,"stargazers_count":913,"watchers_count":913,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":339,"mirror_url":null,"open_issues_count":40,"forks":339,"open_issues":40,"watchers":913,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pydanny/cookiecutter-django/pulls/369"},"html":{"href":"https://github.com/pydanny/cookiecutter-django/pull/369"},"issue":{"href":"https://api.github.com/repos/pydanny/cookiecutter-django/issues/369"},"comments":{"href":"https://api.github.com/repos/pydanny/cookiecutter-django/issues/369/comments"},"review_comments":{"href":"https://api.github.com/repos/pydanny/cookiecutter-django/pulls/369/comments"},"review_comment":{"href":"https://api.github.com/repos/pydanny/cookiecutter-django/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pydanny/cookiecutter-django/pulls/369/commits"},"statuses":{"href":"https://api.github.com/repos/pydanny/cookiecutter-django/statuses/d1fe1069c747ca542f11182ac15d0d783dfa0475"}}}}