暫無描述

Nikola Kotur 33f282c638 app: production updates 10 年之前
bin 57c7338bfe app: added celery worker 10 年之前
conf 33f282c638 app: production updates 10 年之前
database 19873f6d6d app: task fixes 10 年之前
db_repository 33f282c638 app: production updates 10 年之前
phosic f0095260cb app, html: fixes 10 年之前
static 45edf586ee html: contact page 10 年之前
templates f0095260cb app, html: fixes 10 年之前
tests cdbaabbf9e Initial skeleton. 10 年之前
.gitignore 57c7338bfe app: added celery worker 10 年之前
Procfile cdbaabbf9e Initial skeleton. 10 年之前
README-flask_skeleton.md da4cc27c6b docs: moved flask skeleton readme away 10 年之前
README.md e88a4fcb93 app: reworked configuration handling 10 年之前
db_create.py 57c7338bfe app: added celery worker 10 年之前
db_downgrade.py 57c7338bfe app: added celery worker 10 年之前
db_migrate.py 57c7338bfe app: added celery worker 10 年之前
db_upgrade.py 57c7338bfe app: added celery worker 10 年之前
flask_app.py c8e79abaca app: added debug toolbar 10 年之前
main.py e9e26c304c app: added logging 10 年之前
requirements.txt 0830286e93 app: added missing requirement 10 年之前

README-flask_skeleton.md

Flask Skeleton

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.

Instructions

First, you'll need to clone the repo.

$ git clone https://github.com/nickhs/flask_skeleton.git
$ cd flask_skeleton

Then you'll need to downloand and install Vagrant if you don't have it already. You'll also need VirtualBox or an alternative Vagrant provider.

http://downloads.vagrantup.com/

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 pip:

$ 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

Note: ./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 heroku Ruby gem installed.

If you haven't signed up for Heroku, go ahead and do that. You should then be able to add your SSH key to Heroku, and also heroku login from the commandline.

Now, to upload your application, you'll first need to do the following -- and obviously change app_name to the name of your application:

$ 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

Next Steps

After you've got your application up and running, there a couple next steps you should consider following.

  1. Create a new README.md file.
  2. Add your Google Analytics ID to the base.html template.
  3. Adjust the author and description <meta> tags in the base.html template.
  4. Change the humans.txt and favicon.ico files in the static directory.
  5. Change the apple-touch icons in the static directory.

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.

75.101.163.44
75.101.145.87
174.129.212.2

Shout Outs

Based on the amazing work of both https://github.com/zachwill/flask_heroku and https://github.com/mattupstate/vagrant-ansible-tutorial

LICENSE

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.