Skip to content

Latest commit

 

History

History
89 lines (77 loc) · 2.11 KB

File metadata and controls

89 lines (77 loc) · 2.11 KB

To run development version

  • install dependencies
pipenv shell
pipenv install --dev
  • set environment variable with the name of the project, this will be used in settings.py
if os.getenv("MYAPP_ENVIRONMENT") == "dev":
    from dotenv import find_dotenv, load_dotenv

    load_dotenv(find_dotenv(), override=True)
  • to set env variable using fish shell
set -Ux MYAPP_ENVIRONMENT dev
  • make sure .env file is in place
  • navigate to /app/src and run
drs

OR

python manage.py runserver
  • in your browser, visit
http://localhost:8000/api/simpleapi

To run the Dockerized version

  • copy .env files
cp .env.app.example .env.app.production
cp .env.postgres.example .env.postgres.production
  • add new machine's ip address to .env file
ALLOWED_HOSTS=localhost app 127.0.0.1 put_ip_here [::1]
  • spin up the containers
docker compose -f docker-compose.production.yml up --build
  • run
docker compose -f docker-compose.production.yml exec app python ./src/manage.py collectstatic --no-input
docker compose -f docker-compose.production.yml exec app python ./src/manage.py migrate --no-input

How to log exceptions

import traceback
from datetime import datetime
with open("/applogs/exceptions.log", "a") as file:
    file.write(
        f"an error happened at {datetime.datetime.now()}\n"
    )
    file.write(f"Exception details: {str(e)}\n")
    file.write(f"Full traceback: \n{traceback.format_exc()}\n")
    file.write("-------------------------------------------------------")

To run the django app individually to test static changes

docker build -f ./app/Dockerfile -t hello_django:latest ./app
docker run -d \
    -p 8006:8000 \
    -e "SECRET_KEY=please_change_me" -e "DEBUG=1" -e "DJANGO_ALLOWED_HOSTS=*" \
    hello_django python /usr/src/app/manage.py runserver 0.0.0.0:8000

to execute a command into a container

docker-compose exec app python manage.py flush --no-input
docker-compose exec app python manage.py migrate