Outline for the day ● Machine setup ○ Installation ○ Accounts ● Start project ● Manual deployment to Heroku ● Continuous Integration via CircleCI ● Continuous Deployment to Heroku ● Using GitHub Pull Requests for code review ● Provisioning external resources on Heroku ● Using Heroku Review Apps to enable manual testing ● Advanced topics as time allows
Install dependencies 1. Git command-line a. Optional: GitHub desktop client 2. Any code editor a. Recommendation: Atom 3. Heroku CLI 4. Python 3.6 5. Pipenv 6. MongoDB a. Optional: MongoDB client (e.g. Robomongo) Instructions continue on the next slide....
Initial Flask app 1. Create repository on GitHub 2. Clone it to your computer 3. Add a README.md 4. Define requirements in Pipfile 5. Create application file 6. Push files to GitHub Instructions continue on the next slide....
New file: README.md # webcalc Demo project for the 2017 Beer City Code workshop on Continuous Delivery. https://guides.github.com/features/mastering-markdown
Configure project for Heroku 1. Add gunicorn as a production web server 2. Create Procfile 3. Redeploy to Heroku 4. View site Instructions continue on the next slide....
Enable CircleCI 1. Add project to CircleCI 2. Attempt to build project 3. Add configuration file 4. Add status badge Instructions continue on the next slide....
Enable Continuous Deployment 1. Enable automatic deploys on Heroku 2. Push a bad change to webcalc.py 3. Watch build fail on CircleCI 4. Confirm no deployment on Heroku 5. Fix tests 6. Push again
Benefits of Pull Requests ● We don’t always want to deploy right away ● Team consensus ● Code reviews ● View CI status for each change ● Prioritize changes and detect conflicts
Create a Pull Request 1. Create a new branch 2. Add test for new functionality 3. Add new route for calculation 4. Push branch and create PR 5. Add collaborator and request review Instructions continue on the next slide....
Create Pull Request 1. Commit and push changes 2. Open Pull Request on GitHub 3. Add a collaborator on the Settings tab 4. Assign them for review https://help.github.com/articles/about-pull-requests/
Load math patterns from MongoDB 1. Create a new branch 2. Add test for new functionality 3. Load patterns from MongoDB 4. Push branch and create PR 5. Request review then merge PR Instructions continue on the next slide....
Create Pull Request 1. Create PR 2. Wait for review app to deploy 3. Request review from your collaborator 4. As the collaborator, review the code 5. Merge PR
Provision MongoDB on Heroku 1. Add free-tier MongoDB as resource 2. Open database editor 3. Create operations collection 4. Insert document: {"name": "x", "pattern": "{{ a * b }}"} 5. Try out the live app on production
Enable Heroku Review Apps 1. Create a Heroku pipeline 2. Add app.json to define resources 3. Add a seeds script 4. Create PR to see review app 5. Test feature on review app Instructions continue on the next slide....
Enable review apps 1. Enable review apps in the pipeline 2. Remove MONGODB_URI from the generated app.json 3. Allow Heroku to commit app.json to the repository 4. Pull down the latest master branch from GitHub https://devcenter.heroku.com/articles/github-integration-review-apps
New file: seeds.py from webcalc import app, mongo with app.app_context(): mongo.db.operations.insert( dict( name="+", pattern="{{ a + b }}" ) ) mongo.db.operations.insert( dict( name="x", pattern="{{ a * b }}" ) )
Create Pull Request 1. Create PR 2. Wait for review app to deploy 3. Request review from your collaborator 4. As the collaborator, review the code and test the review app 5. Merge PR