Skip to content

Technical: Deployment

Toe Arkar edited this page Nov 16, 2023 · 38 revisions

Prerequisites

Tools

  • Installed Git, NodeJS, python, postgres, python IDE (pycharm or vscode recommended), postgres IDE (for example, DBVisualizer)

Knowledge

  • Git
  • Python Click here and read up to and including "Data Structures". This will be enough to get you started, although the other sections are commended
  • Django Part 1 and Part 2 of "Writing your first Django app"

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

Knowledgebase / BOP Catalog Setup

First Time Set up:

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

Since you started the server in the previous step, you can skip the next section.

Windows Users ( This only needs to be done once )

To avoid potential 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 .

Start Docker

From the terminal, type:

docker build -t kb-web-image . # this only needs to be done once
docker-compose up

Manually Running Python or Django

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

Open terminal in Docker for django-hfla-web Run

cd django_root
source ./activate.sh

Running Locally

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

  1. Start Postgres
  2. From terminal:
cd django_root
source ./start-dev.sh

Modifying Schema

  1. Modify models.py and admin.py. Look for "tool" for example of code to add. DO NOT MODIFY 0001_initial.py. The scripts in the directory for this file are autogenerated when makemigrations is run.
  2. Kill server started with ./start-dev.sh
  3. ./start-dev.sh will automatically run makemigrations and migrate.

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
  6. Populate Gdoc table, set Google ID to 1rGLToDtbpnhKtkIcdcVQA3N3hWbyKFEs_BUmuD90VaE

================================================================= STOP HERE IF NOT WORKING ON MARKDOWN CONVERSION

Setup for Google Doc to Markdown Conversion

Configure Source

Google Account and Cloud Project Setup (one time)

  • Log into Google with your account or create a Google account to use for development.
  • Identify Google Drive directory that holds the contents of the markdown to be converted. Copy Google Docs from Website Google Drive (??? URL) if not already done or create your own.
  • Create a token either manually or using a script. If you use the script, it will prompt you to create or select a Google Cloud project and it will create the credentials (CLIENT_ID and CLIENT_SECRET).
    • Automated process:
      • From bash, run ./generate-google-token.sh.
      • You will see an option to "Open in Browser" preceded by ">". Press Enter. Google Cloud application will be displayed in a browser.
      • If you have never created a Google Project, it will prompt you to create a project. After you create a project, you will be prompted to create credentials.
      • If you already have existing projects, it will prompt you to create credentials for the last selected project. You can select a different one or create a new one.
      • When prompted to create a credential, select "Web Application" for application type and press Save.
      • A screen will be displayed showing client id and client secret. Keep that window open.
      • From the bash terminal, you will be prompted to enter client id and client secret. Copy those from the Google credential screen.
      • Next, the script will ask you to enable the API. Again, press Enter to open Enable API screen in browser.
      • Click through to enable API.
      • From the bash terminal, you will see a prompt "Press any key to continue". Press return (other keys won't work!).
      • Script will prompt you to "Open in my browser" to authorize the API.
    • Manual Process NOTE: Since there is an automated script, detailed steps not provided
      • Create or select a Google Cloud project
      • Generate credentials for the project
      • Using the credentials, generate a token
      • Add or update .env in the root directory for credentials and token generated in previous section:
           GOOGLE_OAUTH_CLIENT_ID
           GOOGLE_OAUTH_CLIENT_SECRET
           GOOGLE_DOCS_TOKEN

Configure Output

Option 1 - Write Directly to Website Repo on GitHub

?? Add step for entering user

  • Fork Website repository
  • Generate a personal GitHub token
  • Log into GitHub
  • Click here or manually:
    • Under your profile icon or photo, open [Settings=>Developer Settings=>Personal Tokens=>Tokens Classic=>Generate new token=>Generate new token (classic))]
  • Enter Note for the token (e.g., Generate Markdown)
  • Select public_repo for scope
  • Click Generate token button
  • Copy the token after it is created - you won't be able to copy it once you navigate away from the create token screen. You will use it when creating a .env file.
  • Add or update GITHUB_TOKEN value in .env in root folder. If it does not exist, copy .env.EXAMPLE to .env

Web Hook

This is TBD. A webhook will be created in a designated Google Drive directory. Any time a Google Document is created, updated, or deleted the webhook will generate a markdown and write that markdown to a designated Github location. This has not yet been implemented.

Install npm packages

cd utils yarn cd gdocs2md yarn cd ../googleoauth2-utils yarn cd .. ./generate-markdown-actual.sh (used in test temporarily)