Skip to content

ekurtgl/app_deployment_ubuntu_fastapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

app_deployment_ubuntu_fastapi

  1. Get an ubuntu VM, setup authorization, create a new user and add it to sudoers.
    adduser emre
    usermod -aG sudo emre
  2. Update the machine via sudo apt update && sudo apt upgrade -y
  3. Install python and virtualenv if not available.
  4. Install and setup postgresql:
    • sudo apt install postgresql postgres-contrib -y
    • Disable peer authentiacation to access it from other users:
      su - postgres
      psql -U postgres
      \password postgres
      \q
      cd /etc/postgresql/12/main
      sudo vi postgresql.conf # here change listen_addresses = ['*']. This is not best practise. Consider limiting access to certain IP addresses/domains.
      sudo vi pg_hba.conf
      # here change the line [local all postgres peer] to [local all postgres md5]
      # change the line [host all all 127.0.0.1/32 md5] to [host all all 0.0.0.0/0 md5] --> meaning any IP address
      # change the line [host all all ::1/128 md5] to [host all all ::/0 md5]
      systemctl restart postgres # restart postgres app
  5. Setup project folder:
    mkdir app_name
    cd app_name
    virtualenv venv
    source venv/bin/activate
    mkdir src
    cd src
    git clone <git_repo.git> . # put dot to prevent new folder with the repo name
    pip install -r requirements.txt # if you get any errors, look for line with #include <libname.h>, then sudo apt install it, and retry
  6. Setup environment variables:
    cd ~
    touch .env
    vi .env # then copy paste .env file content from local to VM
    vi .profile # add this line to the end of file (enable env vars at reboot): set -o allexport; source /home/emre/.env; set +o allexport
  7. Update alembic tables:
    cd ~/app_name/src/
    alembic upgrade head
  8. Setup Gunicorn for automated app running on machine reboot:
    pip install gunicorn httptools uvloop
    # setup service for autostart of api on reboot
    cd /etc/systemd/system
    sudo vi api.service # copy content of ~/app_name/src/gunicorn.service file and modify as needed
    sudo systemctl enable api # this enables starting of service on reboot
    systemctl restart api
    systemctl status api # should look active

To observe the app process in VM:

ps -aef | grep -i gunicorn

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors