From 1be9a48aa07b4f2e4ba76e6f311aff6da7b9bcde Mon Sep 17 00:00:00 2001 From: Nate Aune Date: Thu, 26 Sep 2013 14:46:14 -0400 Subject: [PATCH] move the deploy docs to docs/deploy.rst --- {{cookiecutter.repo_name}}/README.rst | 33 +---- {{cookiecutter.repo_name}}/docs/deploy.rst | 137 ++++++++++++++++++++- 2 files changed, 137 insertions(+), 33 deletions(-) diff --git a/{{cookiecutter.repo_name}}/README.rst b/{{cookiecutter.repo_name}}/README.rst index 3c71050f..e9ee8726 100644 --- a/{{cookiecutter.repo_name}}/README.rst +++ b/{{cookiecutter.repo_name}}/README.rst @@ -6,35 +6,4 @@ LICENSE: BSD -Deployment ------------- - -Run these commands to deploy the project to Heroku:: - -.. code-block:: bash - - $ heroku create - $ heroku addons:add heroku-postgresql:dev - $ heroku addons:add pgbackups - $ heroku addons:add sendgrid:starter - $ heroku addons:add memcachier:dev - $ heroku pg:promote HEROKU_POSTGRESQL_COLOR - $ heroku config:add DJANGO_CONFIGURATION=Production - $ heroku config:add DJANGO_SECRET_KEY=RANDOM_SECRET_KEY - $ heroku config:add DJANGO_AWS_ACCESS_KEY_ID=YOUR_ID - $ heroku config:add DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_KEY - $ heroku config:add DJANGO_AWS_STORAGE_BUCKET_NAME=BUCKET - $ git push heroku master - $ heroku run python {{cookiecutter.repo_name}}/manage.py syncdb --noinput --settings=config.settings - $ heroku run python {{cookiecutter.repo_name}}/manage.py migrate --settings=config.settings - $ heroku run python {{cookiecutter.repo_name}}/manage.py collectstatic --settings=config.settings - -Run this script: (TODO - automate this) - -.. code-block:: python - - from django.contrib.sites.models import Site - site = Site.objects.get() - site.domain = "{{cookiecutter.domain_name}}" - site.name = "{{cookiecutter.project_name}}" - site.save() +For instructions on how to deploy this project to Heroku, look in docs/deploy.rst. diff --git a/{{cookiecutter.repo_name}}/docs/deploy.rst b/{{cookiecutter.repo_name}}/docs/deploy.rst index 1e642c79..cf229ef5 100644 --- a/{{cookiecutter.repo_name}}/docs/deploy.rst +++ b/{{cookiecutter.repo_name}}/docs/deploy.rst @@ -1,4 +1,139 @@ Deploy ======== -This is where you describe how the project is deployed in production. +From within your project's directory, run these commands to deploy the project to Heroku:: + +.. code-block:: bash + + $ heroku create {{cookiecutter.project_name}} + Creating {{cookiecutter.project_name}}... done, stack is cedar + http://{{cookiecutter.project_name}}.herokuapp.com/ | git@heroku.com:{{cookiecutter.project_name}}.git + + $ git init + Initialized empty Git repository in /path/to/your/project/{{cookiecutter.project_name}}/.git/ + + +Add the Heroku git repo as a remote, so that we can push to it. + +.. code-block:: bash + + $ git remote add heroku git@heroku.com:{{cookiecutter.project_name}}.git + + +Add a PostgreSQL database. Note that you will probably get a color other than "GOLD". This is normal. + +.. code-block:: bash + + $ heroku addons:add heroku-postgresql:dev + Adding heroku-postgresql:dev on {{cookiecutter.project_name}}... done, v3 (free) + Attached as HEROKU_POSTGRESQL_GOLD_URL + Database has been created and is available + ! This database is empty. If upgrading, you can transfer + ! data from another database with pgbackups:restore. + +Add pgbackups to handle backups of the PostgreSQL database:: + +.. code-block:: bash + + $ heroku addons:add pgbackups + Adding pgbackups on {{cookiecutter.project_name}}... done, v4 (free) + You can now use "pgbackups" to backup your databases or import an external backup. + Use `heroku addons:docs pgbackups` to view documentation. + +Add sendgrid to handle the sending of emails:: + +.. code-block:: bash + + $ heroku addons:add sendgrid:starter + Adding sendgrid:starter on {{cookiecutter.project_name}}... done, v5 (free) + Use `heroku addons:docs sendgrid` to view documentation. + +Add memcachier for memcached service:: + +.. code-block:: bash + + $ heroku addons:add memcachier:dev + Adding memcachier:dev on {{cookiecutter.project_name}}... done, v7 (free) + MemCachier is now up and ready to go. Happy bananas! + Use `heroku addons:docs memcachier` to view documentation. + +Promote the database you just created. Please note that your database might be called something other than "GOLD". + +.. code-block:: bash + + $ heroku pg:promote HEROKU_POSTGRESQL_GOLD + Promoting HEROKU_POSTGRESQL_GOLD_URL to DATABASE_URL... done + +Set the DJANGO_CONFIGURATION environment variable so that Heroku knows we're in production. + +.. code-block:: bash + + $ heroku config:add DJANGO_CONFIGURATION=Production + Setting config vars and restarting {{cookiecutter.project_name}}... done, v8 + DJANGO_CONFIGURATION: Production + +Don't forget to replace the secret key with a random string. + +.. code-block:: bash + + $ heroku config:add DJANGO_SECRET_KEY='!!!REPLACE-ME!!!' + Setting config vars and restarting {{cookiecutter.project_name}}... done, v9 + DJANGO_SECRET_KEY: abcdefghijklmnopqrstuvwxyz + +If you're using AWS S3 to serve up static assets, then you need to set these values. + +.. code-block:: bash + + $ heroku config:add DJANGO_AWS_ACCESS_KEY_ID=YOUR_ID + $ heroku config:add DJANGO_AWS_SECRET_ACCESS_KEY=YOUR_KEY + $ heroku config:add DJANGO_AWS_STORAGE_BUCKET_NAME=BUCKET + +Commit all the files in your project, and now we're finally ready to push the code to Heroku! + +.. code-block:: bash + + $ git commit -a + $ git push heroku master + Counting objects: 75, done. + Delta compression using up to 8 threads. + Compressing objects: 100% (67/67), done. + Writing objects: 100% (75/75), 28.12 KiB, done. + Total 75 (delta 4), reused 0 (delta 0) + + -----> Python app detected + -----> No runtime.txt provided; assuming python-2.7.4. + -----> Preparing Python runtime (python-2.7.4) + -----> Installing Distribute (0.6.36) + -----> Installing Pip (1.3.1) + -----> Noticed pylibmc. Bootstrapping libmemcached. + -----> Installing dependencies using Pip (1.3.1) + ... + Successfully installed pylibmc django django-configurations django-secure django-cache-url dj-database-url django-braces django-crispy-forms django-floppyforms South django-model-utils Pillow django-allauth psycopg2 unicode-slugify django-autoslug django-avatar gunicorn django-storages gevent boto six python-openid requests-oauthlib requests django-appconf greenlet oauthlib + Cleaning up... + -----> Discovering process types + Procfile declares types -> web + + -----> Compiled slug size: 40.8MB + -----> Launching... done, v10 + http://{{cookiecutter.project_name}}.herokuapp.com deployed to Heroku + + To git@heroku.com:{{cookiecutter.project_name}}.git + * [new branch] master -> master + + $ heroku run python {{cookiecutter.repo_name}}/manage.py syncdb --noinput --settings=config.settings + $ heroku run python {{cookiecutter.repo_name}}/manage.py migrate --settings=config.settings + $ heroku run python {{cookiecutter.repo_name}}/manage.py collectstatic --settings=config.settings + +TODO: Explain how to serve static files with dj-static_. + +.. _dj-static: https://github.com/kennethreitz/dj-static + +Run this script: (TODO - automate this) + +.. code-block:: python + + from django.contrib.sites.models import Site + site = Site.objects.get() + site.domain = "{{cookiecutter.domain_name}}" + site.name = "{{cookiecutter.project_name}}" + site.save()