Deploy to Production Instances
Right now you have two environments. Your computer is a dev environment and you've been pushing code to a Heroku instance for hosting. This has worked well for learning. However, if you were going to offer the CRM Easy application to real customers you'd want to do things differently.
If you recall back to the Django Configuration chapter, you learned that there are typically three environments in a production setting; dev, staging, and production. You already have two environments up. Your computer will remain a dev environment and the current Heroku instance will become production. In this lesson you'll learn how to create a third environment for staging.
Open your terminal and activate your virtual environment. Note that your Heroku app names will be different than those shown below.
1. Rename the current Heroku instance to prod
At the terminal, issue these commands
1 2 3 4 5 6 7 8
(venv)$ git remote -v heroku git@heroku.com:arcane-caverns-9181.git (fetch) heroku git@heroku.com:arcane-caverns-9181.git (push) (venv)$ git remote rename heroku prod (venv)$ git remote -v prod git@heroku.com:arcane-caverns-9181.git (fetch) prod git@heroku.com:arcane-caverns-9181.git (push)
2. Create a new Heroku environment, rename it, and push to it
At the terminal issue these commands to create a new Heroku for production.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
(venv)$ heroku create Creating glacial-wildwood-4145... done, stack is cedar http://glacial-wildwood-4145.herokuapp.com/ | git@heroku.com:glacial-wildwood-4145.git Git remote heroku added (venv)$ git remote -v heroku git@heroku.com:glacial-wildwood-4145.git (fetch) heroku git@heroku.com:glacial-wildwood-4145.git (push) prod git@heroku.com:arcane-caverns-9181.git (fetch) prod git@heroku.com:arcane-caverns-9181.git (push) (venv)revomac:crmeasy tobias$ git remote rename heroku staging (venv)revomac:crmeasy tobias$ git remote -v staging git@heroku.com:glacial-wildwood-4145.git (fetch) staging git@heroku.com:glacial-wildwood-4145.git (push) prod git@heroku.com:arcane-caverns-9181.git (fetch) prod git@heroku.com:arcane-caverns-9181.git (push) (venv)$ git push staging master
3. Add keys to the new staging environment
The new Heroku staging environment won't work unless the correct keys are added. Follow these two steps to set them.
First, set the Django secret key. You can get the secret key from the prod environment.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# display Heroku prod app name (venv)$ git remote -v prod git@heroku.com:arcane-caverns-9181.git (fetch) prod git@heroku.com:arcane-caverns-9181.git (push) staging git@heroku.com:glacial-wildwood-4145.git (fetch) staging git@heroku.com:glacial-wildwood-4145.git (push) # get the secret key from prod (venv)$ heroku config:get SECRET_KEY --app arcane-caverns-9181 'your secret key will display here' # set secret key on staging (venv)$ heroku config:set SECRET_KEY='copy your secret key here' --app arcane-caverns-9181 Setting config vars and restarting arcane-caverns-9181... done, v22 SECRET_KEY: 'yours will display here'
Second, set the Stripe keys. Use the test Stripe keys as this is staging. You can get these keys from the Stripe dashboard.
1 2 3 4 5 6 7 8
# set the Stripe keys (venv)$ heroku config:set STRIPE_PUBLISHABLE_KEY='your test publishable key' --app glacial-wildwood-4145 Setting config vars and restarting glacial-wildwood-4145... done, v8 STRIPE_PUBLISHABLE_KEY: 'your test publishable key' (venv)$ heroku config:set STRIPE_SECRET_KEY='your test secret key here' --app glacial-wildwood-4145 Setting config vars and restarting glacial-wildwood-4145... done, v9 STRIPE_SECRET_KEY: 'your test secret key here'
Lastly, set the ENV_ROLE to 'staging'
1 2 3 4
# set ENV_ROLE to staging (venv)$ heroku config:set ENV_ROLE=staging --app glacial-wildwood-4145 Setting config vars and restarting glacial-wildwood-4145... done, v9 ENV_ROLE: staging