A python web 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 almalinux 8.x
- clone repo in /var/www/modules
- run
install.sh
vagrant up
Gets you...
- almalinux
- all rpms updated
- python38 installed
- fastapi installed
- hypercorn installed
- postgres 13 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 fastapi 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 fastapi app here)
- carbs.toml ( hypercorn config items)
- carbs.service (systemd service file)
- carbs_conf_d.conf (nginx config file (conf.d dir) - loaded outside of the server directive)
- carbs.conf (nginx config file (default.d dir) - loaded inside of the server directive)
- ./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 /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 /provision/schemas.sh
- runuser -l postgres -c "psql -U bento -f /var/www/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/modules/crons/carbs && /bin/python3 /var/www/modules/crons/carbs/carbs.py >> /var/log/carbs/carbs.log
- in our case
- add a line to
/provision/crons.sh
crons+=(carbs)
The following bash output is the directory structure and organization of bento-box:
tree
.
├── 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_conf_d.conf
│ ├── example_api.py
│ ├── example_api.service
│ ├── example_api.toml
│ └── __init__.py
├── generate_putty_key.bat
├── hello_world
│ ├── hello_world.conf
│ ├── hello_world_conf_d.conf
│ ├── hello_world.py
│ ├── hello_world.service
│ ├── hello_world.toml
│ ├── __init__.py
│ └── templates
│ └── hello_world.html
├── __init__.py
├── install.sh
├── LICENSE
├── provision
│ ├── crons.sh
│ ├── dev_env.sh
│ ├── enable_ssl.sh
│ ├── modules.sh
│ ├── nginx_conf
│ ├── nginx.sh
│ ├── packages.sh
│ ├── postgres.sh
│ ├── schemas.sh
│ └── static.conf
├── README.md
├── root_app
│ ├── __init__.py
│ ├── root_app.conf
│ ├── root_app_conf_d.conf
│ ├── root_app.py
│ ├── root_app.service
│ ├── root_app.toml
│ ├── templates
│ │ ├── base_template.html
│ │ └── index.html
│ └── wsgi.py
├── static
│ ├── css
│ │ └── root.css
│ ├── favicon.ico
│ └── image
│ ├── Bento.png
│ └── title_logo.png
├── utils
│ ├── db.py
│ ├── __init__.py
│ └── __pycache__
│ ├── db.cpython-36.pyc
│ ├── db.cpython-38.pyc
│ ├── __init__.cpython-36.pyc
│ └── __init__.cpython-38.pyc
└── Vagrantfile
14 directories, 55 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