Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
web: gunicorn project.wsgi:application
web: uwsgi uwsgi.ini
scheduler: python manage.py celery worker -B -E --concurrency=2 --maxtasksperchild=1000
worker: python manage.py celery worker -E --concurrency=2 --maxtasksperchild=1000
multiworker: python manage.py celery worker -E --concurrency=2 --maxtasksperchild=1000
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ applications, plus all the tools to easily deploy between them.


### Prerequisites
Djeroku requires pip, virtualenv, git, and fabric. Install them however makes
Djeroku requires pip, virtualenv, and git. Install them however makes
sense on your system (brew, apt-get, etc).


Expand All @@ -21,16 +21,16 @@ and leave you with some instructions and tools for what you can do next.


#### Provisioning your Staging and Production heroku apps
Djeroku projects have a fabfile.py that provides some helpful management
Djeroku projects have a djeroku.py that provides some helpful management
commands, including the automatic creating and setup of your staging and
production apps on heroku. You will need fabric installed to use them.
production apps on heroku.

`fab heroku_setup`
`python djeroku.py heroku_setup`


#### Other Fabric Commands
You can see all the commands available via the fabric file by running:
`fab --list`
#### Other Djeroku Commands
You can see all the commands available via djeroku.py by running:
`python djeroku.py --help`


#### Creating a new app
Expand Down
23 changes: 14 additions & 9 deletions create_djeroku_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'virtualenv_folder': 'venv',
'valid_project_name_regex': r'^[a-zA-Z]+[a-zA-Z0-9_-]*$',
'temp_project_path_format': '_djeroku_temp_project_%d',
'django_pip_version': '"django>=1.8,<1.9"',
'django_pip_version': '"django>=1.9,<1.10"',
# point this to a local folder if you cloned djeroku locally
'djeroku_template_path':
'https://github.com/djeroku/djeroku/archive/master.zip',
Expand Down Expand Up @@ -150,7 +150,7 @@ def _check_dependency(command):

def run_django_setup(project_name):
logging.info('running django setup commands')
venv(project_name, 'python %s/manage.py syncdb' % project_name)
venv(project_name, 'python %s/manage.py makemigrations' % project_name)
venv(project_name, 'python %s/manage.py migrate' % project_name)
venv(
project_name,
Expand All @@ -159,11 +159,11 @@ def run_django_setup(project_name):


def print_welcome_message(project_name):
print """
print("""
%(project_name)s project created successfully!

Thanks for using djeroku! You now have an empty django project skeleton in
%(project_name)s/ ready for you to use. There is a new fabfile.py in your
%(project_name)s/ ready for you to use. There is a new djeroku.py in your
project folder that contains helpful commands you will likely use while
developing.

Expand All @@ -173,27 +173,32 @@ def print_welcome_message(project_name):
%(venv_command)s

# Run the one-time setup script to create your heroku projects:
fab heroku_setup
python djeroku.py heroku_setup

# Create a new app inside the project/apps folder:
mkdir project/apps/newappname
django-admin.py startapp newappname project/apps/newappname

# Run the dev server to view your project in your browser (localhost:8000)
fab serve
python djeroku.py serve

# Check out the other djeroku.py helper commands
python djeroku.py --help

Remember, while developing, make sure you activate your virtualenvironment
first or you will get errors about django or other libraries not being found.
first or you will get errors about django or other libraries not being found
(djeroku.py does this for you automatically).

When you add new libraries to your project, be sure to add them to
reqs/common.txt so heroku correctly includes them in your builds.

Please file any issues at https://github.com/collingreen/djeroku.

Happy coding!""" % dict(
Happy coding!""".format(
project_name=project_name,
venv_command=get_venv_command()
)
))


def main():
parser = argparse.ArgumentParser()
Expand Down
53 changes: 25 additions & 28 deletions deployment_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ also need to sign up for a heroku account.


## Setting up the staging and production heroku applications
The fabric script in the top project directory has a useful function that
The djeroku.py script in the top project directory has a useful function that
basically handles the entire heroku setup process for you, including creating
two (nearly) identical environments (staging and production), a bunch of free
addons for each, and a deployment pipeline from staging to production. You
should really have a look in the file to see what is happening under the hood.
You can easily edit the addons or environment variables you want set inside the
file.
two (nearly) identical environments (staging and production), setting everything
up, and provisioning a bunch of free addons for each. You should really have a
look in the file to see what is happening under the hood. You can easily edit
the addons or environment variables you want set inside the file.

`fab heroku_setup`
`python djeroku.py heroku_setup`

There are several prompts along the way and it will warn you if something fails.
The most frustrating part of the entire process (assuming it works) is that
Expand Down Expand Up @@ -92,9 +91,9 @@ urlpatterns = [
It's time to run the project locally. First, navigate back up to the
djeroku_site folder that holds manage.py

Run the djeroku fabric `serve` command -- this just runs the standard
django syncdb, migrate, collecstatic, and then runserver commands
`fab serve`
Run the djeroku `serve` command -- this just runs the standard
django migrate, collecstatic, and then runserver commands
`python djeroku.py serve`

Test it by going to 127.0.0.1:8000 and confirming you can see the Djeroku
test content we created above (or whatever view you routed from '/').
Expand All @@ -103,13 +102,13 @@ TODO: insert screenshot


### Commit it?
Look at all that amazing work we did. Better commit it. The `fab setup_heroku`
command earlier created a git repository for us, so all we need to do is add and
commit.
Look at all that amazing work we did. Better commit it. The
`python djeroku.py setup_heroku` command earlier created a git repository for
us, so all we need to do is add and commit.

~~~
git add .
git commit -m"Initial Djeroku Template Commit"
git commit -m"initial djeroku template commit"
~~~


Expand All @@ -119,10 +118,10 @@ uses git pushes for deployment, so you can just call `git push staging master`.
You may also need to run database creation or migration scripts, and you may
need to collect your static assets
(`heroku run python manage.py <commands> --app yourapp-staging`). You can also
just use the djeroku fabric file again which wraps all of those up into one
just use the djeroku.py script again which wraps all of those up into one
command:

`fab deploy_staging`
`python djeroku.py deploy staging`

That's it! Heroku will churn away and crunch our commit into a working 'app
slug' and turn our new staging app on.
Expand All @@ -146,21 +145,15 @@ fail while DEBUG is false. Update your settings if this is happening to you.


## Deploying to Production
Now that we feel confident that the site is working in staging, we can take
advantage of the pipeline created by the heroku_setup script and simply promote
the slug from staging downstream to production.
`heroku pipeline:promote --app=djeroku-site-staging`
Now that we feel confident that the site is working in staging, we can deploy
to production in exactly the same way as before:
`git push production master`

You can also just call `fab promote_production`
You can also just call `python djeroku.py deploy production`

Now the production site is up as well, at the production url,
djeroku-site.herokuapp.com.

NOTE: you CAN push directly to production, just like staging:
`git push production master`
or
`fab deploy_production`


Now, if this was a public app, I would leave it up (and probably set up a real
domain pointing to it, not just the .herokuapp.com one), but for now I put both
Expand Down Expand Up @@ -188,16 +181,20 @@ my-development-folder
|-- reqs (holds the requirements files for dev vs production)
|-- dev.txt (the python packages you need for development)
|-- prod.txt (the python packages you need for production)
|-- common.txt (the python packages shared for both dev and production)
|-- Procfile (defines the web, scheduler, and worker processes - also how heroku knows this is a python project)
|-- wsgi.py (the python wsgi file that gunicorn actually uses)
|-- fabfile.py (the fabric script that helps set everything up on heroku)
|-- uwsgi.ini (config for uwsgi)
|-- djeroku.py (the script that helps set everything up on heroku)
|-- urls.py (top level django url management)
|-- tox.ini (tox config file)
|-- manage.py (the django script that, well, manages everything)
|-- project (the folder containing the code)
|-- settings (all the settings for dev vs production)
|-- common.py (settings used in both dev and production)
|-- dev.py (settings for local development - generally easy setup)
|-- prod.py (settings for production use - real settings and services)
|-- static (this is where all the static assets will be collected - generally don't add anything here directly)
|-- celery.py (config for celery - mainly for auto-task discovery)
|-- apps (the folder that will contain all the individual apps you write)
|-- djeroku_app (finally, the app that actually drives the site -- will have all the models, tests, templates etc)
~~~
Loading