A flask developer's box of goodies.
- get the deps:
- Vagrant
- Virtualbox
- optional: winscp, putty, puttygen
- open terminal/cmd in this dir
- vagrant up
2 options:
- vagrant ssh
- your ssh client of choice
TO USE PUTTY, convert the autogenerated private key to ppk
- autogenerated: ./.vagrant/machines/default/virtualbox/private_key (pem)
- putty: ./.vagrant/machines/default/virtualbox/private.ppk (putty) To Convert:
- run generate_putty_key.bat after 'vagrant up' completes
- NOTE: you'll need winscp in your path for this step to work
- ALTERNATIVELY: convert the key manually using puttygen
- configure putty session:
- user: vagrant
- host: localhost
- port: 2222
- private key: ./.vagrant/machines/default/virtualbox/private.ppk
- make sure your instance is running centos8
- clone repo in /var/www/flask-modules
- run
cloud_install.sh
vagrant up
Gets you...
- centos8
- all rpms updated
- python36 installed
- flask installed
- postgres 12 and postgis 3 installed
- also a starter database called 'bento' and a schema called test
- migra installed
- empty 'root_app' module listening on the '/' path
- hello world flask app installed and configured in nginx
- example api module installed (with an actual database schema behind it)
**for the sake of example, we'll act like we're adding a module named 'carbs'
- create a new dir in the root of this repo (/carbs/)
- make sure it has the following (probably best to copy one of the examples)
- __init__.py (empty - if you're reading this in an editor... otherwise known as init.py)
- carbs.py (main flask app here)
- carbs.ini (uwsgi config items)
- carbs.service (systemd service file)
- wsgi.py (boilerplate - a bootstrapper for uwsgi to point to)
- carbs.conf (nginx config file - be sure to change a few references)
- ./templates/ dir (optional, if your module has a web ui) **If copy/pasting, make sure to review each of the above files
- add a line to /vagrant_provision/modules.sh for your new carbs module
- will run next time your vagrant box provisions
- to run the provision step manually (just for your module), comment out accordingly and run modules.sh
- this step:
- installs your module as a uwsgi proc running as a service
- adds the nginx config to the appropriate dir
- systemctl command will match the filename of your .service file (systemctl start carbs)
- restart nginx
- 'systemctl restart nginx
**for the sake of example, we'll act like we're adding a schema named 'carbs'
- add a schema create file in the db dir (/db/carbs_schema.sql)
- this file should start with 'CREATE SCHEMA carbs;'
- add a line to /vagrant_provision/schemas.sh
- runuser -l postgres -c "psql -U bento -f /var/www/flask-modules/db/carbs_schema.sql"
- note: this will install the carbs schema to the bento database - if you've created your own database, use that
**for the sake of example, we'll act like we're adding a cron named 'carbs'
- create the new dir in
/crons/carbs
- make sure it has the following (probably best to copy the example_cron)
- carbs.logrotate
- carbs.py (main python cron job)
- add a line to
/crons/crontab
(make sure that there is a newline at the end of the file)- in our case
*/1 * * * * cd /var/www/flask-modules/crons/carbs && /bin/python3 /var/www/flask-modules/crons/carbs/carbs.py >> /var/log/carbs/carbs.log
- in our case
- add a line to
/vagrant_provision/crons.sh
crons+=(carbs)
The following bash output is the directory structure and organization of bento-box:
tree
.
├── cloud_install.sh
├── config.py
├── crons
│ ├── crontab
│ └── example_cron
│ ├── example_cron.logrotate
│ ├── example_cron.py
│ └── say_hello.py
├── db
│ ├── create_database.sql
│ └── test_schema.sql
├── example_api
│ ├── example_api.conf
│ ├── example_api.ini
│ ├── example_api.py
│ ├── example_api.service
│ ├── __init__.py
│ └── wsgi.py
├── generate_putty_key.bat
├── hello_world
│ ├── hello_world.conf
│ ├── hello_world.ini
│ ├── hello_world.py
│ ├── hello_world.service
│ ├── __init__.py
│ ├── templates
│ │ └── entrees.html
│ └── wsgi.py
├── __init__.py
├── LICENSE
├── README.md
├── root_app
│ ├── __init__.py
│ ├── root_app.conf
│ ├── root_app.ini
│ ├── root_app.py
│ ├── root_app.service
│ ├── templates
│ │ ├── base_template.html
│ │ └── index.html
│ └── wsgi.py
├── static
│ ├── favicon.ico
│ └── image
│ ├── Bento.png
│ └── title_logo.png
├── utils
│ ├── db.py
│ └── __init__.py
├── Vagrantfile
└── vagrant_provision
├── crons.sh
├── dev_env.sh
├── modules.sh
├── nginx.sh
├── packages.sh
├── postgres.sh
├── schemas.sh
└── static.conf
12 directories, 47 files
bento-box does not solve for db versioning at the moment. But it does include migra, a db diff tool. That's a good start toward a sane db "non-versioning" scheme. Read up on it here: https://djrobstep.com/docs/migra/quickstart
MIT © John Zechlin