Giter Site home page Giter Site logo

self-destruct's Introduction

lad

bento-box

A python web developer's box of goodies.

code-sizecode-sizelicense

Table of Contents

Setup

Set Up the Vagrant box

  1. get the deps:
    • Vagrant
    • Virtualbox
    • optional: winscp, putty, puttygen
  2. open terminal/cmd in this dir
  3. vagrant up

SSH to the machine

2 options:

  • vagrant ssh
  • your ssh client of choice

Putty setup (optional)

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:
  1. 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
  2. configure putty session:
    • user: vagrant
    • host: localhost
    • port: 2222
    • private key: ./.vagrant/machines/default/virtualbox/private.ppk

Install on AWS, Google, Digital Ocean, etc

  1. make sure your instance is running almalinux 8.x
  2. clone repo in /var/www/modules
  3. run install.sh

Get Started

What you get

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)

Creating a new module

**for the sake of example, we'll act like we're adding a module named 'carbs'

  1. create a new dir in the root of this repo (/carbs/)
  2. 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
  3. 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)
  4. restart nginx
    • 'systemctl restart nginx

Creating a new db schema

**for the sake of example, we'll act like we're adding a schema named 'carbs'

  1. add a schema create file in the db dir (/db/carbs_schema.sql)
    • this file should start with 'CREATE SCHEMA carbs;'
  2. 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

Creating a new cron job

**for the sake of example, we'll act like we're adding a cron named 'carbs'

  1. create the new dir in /crons/carbs
  2. make sure it has the following (probably best to copy the example_cron)
    • carbs.logrotate
    • carbs.py (main python cron job)
  3. 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
  4. add a line to /provision/crons.sh
    • crons+=(carbs)

Architecture

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

Note on db versioning/migrations

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

License

MIT © John Zechlin

self-destruct's People

Contributors

johnzech avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.