You make lots of simple Flask CRUD apps. You want deployment to be super easy.
What is this?
A template to get your Flask app running anywhere as fast as possible. For added convenience, the templates use Twitter's Bootstrap project to help reduce the amount of time it's takes you as a developer to go from an idea to a working site.
Uses Vagrant for development so everyone on your team has the exact same environment.
Ansible to provision Vagrant and other environments.
Flask-SQLAlchemy is also included to handle all database (PostgresSQL) interactions.
The skeleton is engineered to run on any Debian/Ubuntu based system, while remaining compatible with Heroku. It splits up its web and database components allowing you to scale up with ease.
Really Quick Start
Make sure you have Vagrant and Ansible installed.
Get a development environment running:
$ vagrant up web $ vagrant ssh $ cd /srv/flask_skeleton && python main.py Open http://192.168.100.10
Put it in production:
Edit ops/vars.yml Edit ops/hosts $ ./deploy.sh
Or deploy to Heroku as you normally would.
First, you'll need to clone the repo.
$ git clone https://github.com/nickhs/flask_skeleton.git $ cd flask_skeleton
You'll also need to have Ansbile (the provisioning mechanism) installed. The easiest method is to do:
$ sudo pip install ansible
Don't have pip? You can grab it with:
$ sudo easy_install pip
Finally let Vagrant do the rest. Don't worry if it seems noisy:
$ vagrant up db $ vagrant up web $ vagrant ssh web $ cd /srv/flask_skeleton $ python main.py
Visit the site at 192.168.100.10.
Deploying to a box
Deploying your application to your EC2/Linode/DigitalOcean/server somewhere is a cinch.
If you don't already have Ansbile, the provisioning system, you'll need to download it.
Your easiest bet is to install it via
$ sudo pip install ansible
Make sure you edit the
ops/vars.yml file to specify the application name,
repository location and generate secret keys and database passwords.
Add the server(s) in
ops/hosts, note this is an
Ansible hosts file
and you can pass the relevant parameters accordingly.
For example your hosts file could look like this:
# Production webservers go here [webservers] web1.server.com ansible_ssh_user=ubuntu ansible_ssh_private_key_file=~/secrets/main.pem # Production databases go here # Want just one box? Make them the same [dbservers] db.server.com ansible_ssh_user=ubuntu ansible_ssh_private_key_file=~/secrets/main.pem [production:children] dbservers webservers
If you want everything on the same box just enter the same host under both sections. Don't want a database? Leave the dbservers section blank.
Once you're done defining your hosts do:
./deploy.sh is idempotent, don't be afraid to run it over and over again.
From then on out to just update the code you can do:
$ ./deploy.sh --fast
Deploying to Heroku
Make sure you have the
Ruby gem installed.
Now, to upload your application, you'll first need to do the
following -- and obviously change
app_name to the name of your
$ heroku create app_name -s cedar
And, then you can push your application up to Heroku.
$ git push heroku master $ heroku scale web=1
Finally, we can make sure the application is up and running.
$ heroku ps
Now, we can view the application in our web browser.
$ heroku open
After you've got your application up and running, there a couple next steps you should consider following.
- Create a new
- Add your Google Analytics ID to the
- Adjust the
<meta>tags in the
- Change the
favicon.icofiles in the
- Change the
apple-touchicons in the
Heroku Custom Domains
If your account is verified -- and your credit card is on file -- you can also easily add a custom domain to your application.
$ heroku addons:add custom_domains $ heroku domains:add www.mydomainname.com
You can add a naked domain name, too.
$ heroku domains:add mydomainname.com
Lastly, add the following A records to your DNS management tool.
126.96.36.199 188.8.131.52 184.108.40.206
Based on the amazing work of both https://github.com/zachwill/flask_heroku and https://github.com/mattupstate/vagrant-ansible-tutorial
The MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.