Skip to content

Technical: Deployment

Ethan-Strominger edited this page Feb 21, 2024 · 38 revisions

Prerequisites

Tools

  • Installed Git, Python, Postgres, Python IDE (pycharm or vscode recommended), Postgres IDE (for example, DBVisualizer)

Knowledge

=================================================================

Knowledgebase / BOP Catalog Setup

First Time Set up:

  1. If using your account
    • Fork repository in github
    • Clone fork
    • Create a branch
  2. If you have maintain privileges for this repo, just clone this repo directly

Windows Users ( This only needs to be done once )

To avoid issues with Git line endings, disable Git EOL conversion before running the Docker script.
From the bash terminal, type:

git config --global core.autocrlf false
git add --renormalize .

If you don't do this, after docker-compose up, you might get ./start-docker.sh: no such file or directory. Even if running locally, there may be issues if you don't do the above.

Install Python Packages Locally (for both running application in Docker or locally)

  • Install Python locally if not installed From django_root directiory in terminal, run:
pip install -r requirements.txt

Using Docker

Install Python Packages Locally (optional)

Installing Python packages locally will improve Intellisense and compile errors in IDE such as VSCode.

  • Install Python locally
  • From django_root directory:
pip install -r requirements.txt

Create Docker Image and Container

  • Start Docker
  • From the terminal, type:
docker build -t kb-web-image . # this only needs to be done once
docker-compose up

Manually Run Python or Django In Docker Terminal

If you need to open the Docker terminal to try some Django or Python commands:

  • From Docker UI, open terminal in Docker for django-hfla-web container.
  • From a terminal, run
cd django_root
source ./activate.sh
  • From terminal in previous steps, run Python or Django commands

Running Locally

Install Python Packages Locally

Installing Python packages locally will improve Intellisense and compile errors in IDE such as VSCode.

  • Install Python locally
  • From django_root directory:
pip install -r requirements.txt

Start App Locally

Docker is the preferred method for starting. If Docker is not working or you have some other reason to run it locally:

cd django_root
cp .env.local-example .env.local # only needs to be done once
source ./start-dev.sh

Run Scripts Locally

  • Open terminal
  • From a terminal, run
cd django_root
source ./activate.sh
source ./loadenv.sh .env.local
  • From terminal in previous steps, run Python or Django commands

Modifying Schema

  1. Modify models.py and admin.py. Look for "tool" for example of code to add. DO NOT MODIFY any of the scripts in the migrations folders. The scripts in the directory for this file are autogenerated when makemigrations is run.
  2. Kill Docker container or kill server started with ./start-dev.sh
  3. Follow instructions in previous sections to start the application in Docker or locally. In both cases, manage.py makemigrations and migrate will be run.

Regenerating Migration Scripts

This would only be done if the development team wants fewer migration scripts to make it easier to read.

  1. Drop all tables under public schema
  2. Remove django_kp_app/migrations directory using gui or with command rm -rf django_kb_app/migrations
  3. Starting Docker (or running ./start-dev.sh locally) will automatically regenerate migrate scripts.
  4. localhost:8000/admin
  5. Log in with admin for username and password