Skip to content

Commit

Permalink
feat: dockerised backend
Browse files Browse the repository at this point in the history
  • Loading branch information
hrideshmg committed Aug 6, 2024
1 parent df063a2 commit 84f296e
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 5 deletions.
89 changes: 89 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Git
.git
.gitignore
.gitattributes


# CI
.codeclimate.yml
.travis.yml
.taskcluster.yml

# Docker
docker-compose.yml
Dockerfile
.docker
.dockerignore

# Byte-compiled / optimized / DLL files
**/__pycache__/
**/*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Virtual environment
.env
.venv/
venv/

# PyCharm
.idea

# Python mode for VIM
.ropeproject
**/.ropeproject

# Vim swap files
**/*.swp

# VS Code
.vscode/
2 changes: 0 additions & 2 deletions attendence_tracker/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@

import django
from celery import Celery
from dotenv import load_dotenv

if "WEBSITE_HOSTNAME" in os.environ:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "attendence_tracker.production")
broker_url = os.getenv("REDIS_BROKER_CONNECTIONSTRING")
else:
load_dotenv("./.creds")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "attendence_tracker.settings")
broker_url = os.getenv("BROKERLOCATION")

Expand Down
50 changes: 50 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This is an Extension: https://github.com/compose-spec/compose-spec/blob/main/spec.md#extension
x-environment: &env
environment:
DBNAME: development
DBUSER: development
DBPASS: development
DBHOST: postgres
CACHELOCATION: redis://redis:6379/0
BROKERLOCATION: redis://redis:6379/1
SECRET_KEY: django-insecure-ys)is-uls_$yaa(f%iyy^^7pe4a@ql)3thr9loszz#!8l4m4fk

services:
django:
build:
context: .
dockerfile: ./docker/web/Dockerfile
entrypoint: ./docker/web/docker-entrypoint.sh
volumes:
- ./:/app # Mount the current directory to /app within the container
ports:
- "8000:8000"
depends_on:
- redis
- postgres
<<: *env # This is a YAML merge

celery:
build:
context: .
dockerfile: ./docker/celery/Dockerfile
volumes:
- ./:/app
depends_on:
- django # Migrations need to be run before celery can start because of django-celery-results
<<: *env

redis:
image: redis:alpine

postgres:
image: postgres:alpine
volumes:
- db-vol:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=development
- POSTGRES_USER=development
- POSTGRES_DB=development

volumes:
db-vol:
6 changes: 6 additions & 0 deletions docker/celery/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM python:alpine
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD celery -A attendence_tracker worker -l info
8 changes: 8 additions & 0 deletions docker/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:alpine
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD python manage.py runserver 0.0.0.0:8000
EXPOSE 3000
ENTRYPOINT [ "./docker-entrypoint.sh" ]
6 changes: 6 additions & 0 deletions docker/web/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
echo "Running Migrations"
python manage.py migrate

echo "Starting Server"
python manage.py runserver 0.0.0.0:8000
3 changes: 0 additions & 3 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import os
import sys

from dotenv import load_dotenv


def main():
"""Run administrative tasks."""
Expand All @@ -14,7 +12,6 @@ def main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "attendence_tracker.production")
else:
print("Loading environment variables for .env file")
load_dotenv("./.creds")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "attendence_tracker.settings")

try:
Expand Down

0 comments on commit 84f296e

Please sign in to comment.