Skip to content

Technical: Deployment

Ethan-Strominger edited this page Oct 27, 2023 · 38 revisions

Prerequisites

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

Knowledgebase

Setup for Script to Convert Google Doc to Markdown

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. It will prompt you to create or select a Google Cloud Project.
    • Manual Process
      • Create 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

  • 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)

Local Django Server and Database Setup

Prerequisites

First Time Set up:

  1. Install and start PostGres
  2. Fork repository in github
  3. Clone fork
  4. From terminal:
cd DjangoApisPostgreSQL
python3 -m venv venv
source ./activate.sh
pip install -r requirements.txt
# runs migration on database, creates admin user, and starts server
./start-dev.sh

From a second terminal:

cd DjangoApisPostgreSQL
./activate.sh
./populate-seedddata.sh

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

Start Server

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

or

./start-dev.sh

Activate Python when you open terminal

If you need to open the terminal for other reasons than running start-dev.sh, you can manually run:

source ./activate.sh

Modifying Schema

  1. Modify models.py.
  2. Kill server started with ./start-dev.sh
  3. ./start-dev.sh will automatically migrate.

Regenerating Migration Scripts

  1. Kill server started with ./start-dev.sh
  2. From postgres using postgres db: `delete from django_migrations where app='knowledgebase'
  3. From postgres IDE: drop any tables that begin with postgres
  4. Remove knowledgebase/migrations directory using gui or with command rm -rf knowledgebase/migrations
  5. ./start-dev.sh will automatically regenerate migrate scripts.
  6. localhost:8000/admin
  7. Log in with admin for username and password
  8. Populate Gdoc table, set Google ID to 1rGLToDtbpnhKtkIcdcVQA3N3hWbyKFEs_BUmuD90VaE