LoveJustice / tinyhands

Searchlight - Human Trafficking Data Center
6 stars 0 forks source link

Dream Suite

Love Justice International

Codeship Status

Setup

Docker

  1. Make sure you install Docker here and docker-compose by executing: sudo pip install docker-compose
  2. Clone the repository and cd into it
  3. execute the setup.sh script in the root of the repo (this might take a few minutes)
  4. run docker-compose up -d to start running the project
  5. The created local.env file may need some secrets before the project will run. Ask for the secrets from whoever is helping you get started
  6. If all of the steps were successful, you can find the application running on port 80 on localhost.
  7. If you can't figure this out, contact Austin Munn.

Running on Pycharm in Windows

This assumes that you have the database set up already and have been working with the docker containers before. I will enhance this guide with a more complete set-up process from a clean machine at a later date.

  1. Install Python 3.12 on your Windows machine
  2. Make a new Python Interpreter with a Virtual Environment (venv) using Python 3.12
  3. Under Tools -> Python Integrated Tools specify your requirements.txt as build\base\requirements.txt
  4. Install C++ build tools (for face recognition dependencies)
    1. Download and run CMake Windows 64bit installer https://cmake.org/download/
    2. Verify cmake works in terminal (may need to restart PC)
    3. Download and install Visual Studio C++ Build tools via Microsoft Visual Studio Installer - https://visualstudio.microsoft.com/visual-cpp-build-tools/
    4. Choose Desktop Development with C++ (2 GB download, have good internet!)
  5. Navigate to build\base\requirements.txt and click the yellow banner "Install Dependencies" (must finish indexing if you restarted)
  6. Go into the Python Interpreter from step 2, hit the plus button and choose opencv-python, check specify version at 3.4.18.65
  7. Make a Pycharm run configuration for docker compose for 'docker compose up' on service 'db'
  8. Make a Pycharm run configuration for python with script pointed at manage.py
    1. params: runserver 9001 --settings dreamsuite.settings.local
    2. working directory: application
    3. Modify Options -> Before Launch -> Run another configuration -> configuration from last step
  9. Make sure Docker Desktop is running
  10. Add the following to your local.env
    1. DREAMSUITE_LOG=./log/dreamsuite.log
    2. DB_HOST=localhost
    3. DB_PORT=7654
  11. Launch the configuration from step 8
  12. Visit localhost:9001/api/me/ and verify you get some page with "Authentication credentials were not provided"
  13. Use postman to hit the endpoint that you want

Installing Sanitized Test Data

execute docker-compose run --rm web sh /data/bin/install_test_db.sh

The sanitized database has two accounts preconfigured for testing both of which have the password 'pass'

Installing Production Backup Data

  1. Ask someone for a backup or use sftp <your_ssh_username>@<server_name> from the directory you want it in if you have ssh access
  2. get db_restore.sh file from someone and run it

Docker/Docker-Compose Cheat Sheet

Some useful :commands

local.env and common.env files

In the root project directory there are three files used that contain environment variables. These files are used inside of the containers. If you look at the docker-compose.yml file you can see that these are imported into all of the containers.

Testing

Django Unit Tests:

Execute the ./manage.py test command in a new container. eg. docker-compose run web ./manage.py test

Deployment Process

Building containers

I have created a build script to automate the build process of docker-containers. Just run the script and manually check to see if there were any problems in the build process. Note that at the end, it provides a build number with which the images have been tagged. This version number is automatically put into a file called dreamsuite_tag in the root of the repository as well so that you do not have to remember it.

execute: ./build-containers.sh

Pushing containers

There is a push containers script in the root of the repository. This script takes in a version number as the 1st argument and pushes the containers to DockerHub with the specified tag. The following command pushes the docker containers with the tag number that was generated by the build-containers script.

./push-containers.sh `cat dreamsuite_tag`

Refreshing certificate

As of 2023-02-06, we are not using certbot automatic Lets Encrypt refreshing, and instead manually refreshing the certificate every 90 days.

To do this:

After that: