Skip to content

Commit

Permalink
added basic logging and updated environment variables
Browse files Browse the repository at this point in the history
- added github actions testing
- updated enviroment variables in settings
  • Loading branch information
daniel-gray-tangent committed Apr 30, 2024
1 parent 835f688 commit 607898b
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SECRET_KEY='django-insecure-w!h85bp^$$e8gm%c23r!0%9i7yzd=6w$$s&ic+6!%306&kj8@k*5'
DEBUG=True
DB_HOST=db
DB_PORT=5432
DB_NAME=term_db
DB_USER=sadilar
DB_PASSWORD=sadilar
LOGGING_FILE=logs/debug.log
LOGGING_HANDLERS_LEVEL=INFO
LOGGING_LOGGERS_LEVEL=INFO
LOGGING_LOGGERS_DJANGO_LEVEL=INFO
11 changes: 11 additions & 0 deletions .env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SECRET_KEY='django-insecure-w!h85bp^$$e8gm%c23r!0%9i7yzd=6w$$s&ic+6!%306&kj8@k*5'
DEBUG=True
DB_HOST=db
DB_PORT=5432
DB_NAME=term_db
DB_USER=sadilar
DB_PASSWORD=sadilar
LOGGING_FILE=logs/debug.log
LOGGING_HANDLERS_LEVEL=INFO
LOGGING_LOGGERS_LEVEL=INFO
LOGGING_LOGGERS_DJANGO_LEVEL=INFO
22 changes: 22 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Testing Django
on: [ pull_request, push ] # activates the workflow when there is a push or pull request in the repo
jobs:
test_project:
runs-on: ubuntu-latest # operating system your code will run on
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-test.txt
- name: Run linting tools
run: |
cd app/
ruff format .
- name: Run Tests
run: |
cp .env.testing app/.env
cd app/
mkdir static_files
python manage.py test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ venv.bak/
app/static_files/
/app/documents/
app/media/
/app/logging/
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@ About the project:
3. Run `make run` to run the docker container
4. Run `make stop` to stop the docker container

## Production

### Plugins installed

#### Django Simple History

https://django-simple-history.readthedocs.io/en/latest/

#### Basic setup for production

### environment variables

please use .env.example as example
58 changes: 58 additions & 0 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@
"""

import os
import sys
from pathlib import Path

import environ

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Take environment variables from .env file
environ.Env.read_env(os.path.join(BASE_DIR, ".env"))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/

Expand Down Expand Up @@ -98,6 +104,9 @@
}
}

if "test" in sys.argv or "test_coverage" in sys.argv: # Covers regular testing and django-coverage
DATABASES["default"]["ENGINE"] = "django.db.backends.sqlite3"

# Password validation
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators

Expand Down Expand Up @@ -154,3 +163,52 @@
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"


if DEBUG:
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"class": "logging.StreamHandler",
},
},
"root": {
"handlers": ["console"],
"level": "DEBUG",
},
}
else:
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"class": "logging.StreamHandler",
},
"file": {
"level": os.environ.get("LOGGING_HANDLERS_LEVEL", "WARNING"),
"class": "logging.FileHandler",
"filename": os.environ.get("LOGGING_FILE", "logging/debug.log"),
"formatter": "verbose",
},
},
"root": {
"handlers": ["console", "file"],
"level": os.environ.get("LOGGING_LOGGERS_LEVEL", "WARNING"),
},
"loggers": {
"django": {
"handlers": ["file"],
"level": os.environ.get("LOGGING_LOGGERS_DJANGO_LEVEL", "WARNING"),
"propagate": True,
},
},
"formatters": {
"verbose": {
"format": "{asctime} {levelname} - {name} {module}.py (line: {lineno:d}). - {message}",
"style": "{",
},
},
}
3 changes: 3 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-r requirements.txt
django-extensions
ruff
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
django==5.0.2
psycopg2-binary
django-environ
django-simple-history
gunicorn
psycopg2-binary
whitenoise
django-simple-history

0 comments on commit 607898b

Please sign in to comment.