Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infrastructure configuration #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 164 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

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

# 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/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
static/
nginx-dev.conf
Binary file added Arman-challenge-design.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.*
!.coveragerc
!.env
32 changes: 32 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM python:3.10
ENV PYTHONUNBUFFERED 1

WORKDIR /backend

COPY ./requirements.txt requirements.txt
RUN pip --no-cache-dir --timeout=1000 install -r requirements.txt

COPY . /backend/

# Install supervisor
RUN apt-get update && apt-get install -y supervisor

# Install netcat
RUN apt-get update && apt-get install -y netcat-openbsd

# Copy supervisor configuration
COPY scripts/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Ensure the entrypoint script is executable
RUN chmod +x scripts/entrypoint.sh

RUN mkdir -p /var/log
RUN chown -R nobody:nogroup /var/log

EXPOSE 8000

# Set the entrypoint script
ENTRYPOINT ["scripts/entrypoint.sh"]

# Default command to run supervisord
CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
38 changes: 38 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Django & DRF & JWT
django==5.0
djangorestframework==3.15.2
djangorestframework-simplejwt==5.3.1
# Control Cors headers
django_cors_headers==4.4.0
# Postgres client and dependencies
psycopg==3.2.1
psycopg-binary==3.2.1
psycopg-pool==3.2.2
# Load dotenv files
python-dotenv==1.0.1
django-environ==0.11.2
# uvicorn server
uvicorn==0.30.6
# Colorize test outputs
redgreenunittest==0.1.1
# Django redis client
django-redis==5.4.0
# Celery
celery==5.4.0
redis==5.0.8
amqp==5.2.0
msgpack==1.0.8
django-celery-results==2.5.1
django-celery-beat==2.7.0
flower==2.0.1
# SMSProvider
kavenegar==1.1.2
# Admin UI
django-jazzmin==3.0.0
# Formatting
ruff==0.6.4
mypy==1.11.2
# Swagger
drf-yasg==1.21.7
# Load testing
locust==2.31.6
44 changes: 44 additions & 0 deletions backend/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# Wait for the database and other services to start
echo "Waiting for PostgreSQL..."
while ! nc -z postgres 5432; do
sleep 0.1
done
echo "PostgreSQL started"

# Wait for the cache backend and message broker services to start
echo "Waiting for RabbitMQ..."
while ! nc -z rabbitmq 5672; do
sleep 0.1
done
echo "RabbitMQ started"

echo "Waiting for Redis..."
while ! nc -z redis 6379; do
sleep 0.1
done
echo "Redis started"

# Lint and Format code
echo "Running linter..."
ruff format
ruff check --fix

# Apply migrations
echo "Applying migrations..."
python /backend/manage.py migrate

# Run tests if in a testing environment
if [ "$DJANGO_ENV" == "testing" ]; then
echo "Running tests..."
python /backend/manage.py test
fi

# Collect static files
echo "Collecting static files..."
python /backend/manage.py collectstatic --noinput

# Start supervisord, which manages Django and Celery
echo "Starting supervisord..."
exec supervisord -c /etc/supervisor/conf.d/supervisord.conf
18 changes: 18 additions & 0 deletions backend/scripts/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[supervisord]
nodaemon=true

[program:django]
command=uvicorn apps.server:app
directory=/backend
autostart=true
autorestart=true
stdout_logfile=/var/log/django.log
stderr_logfile=/var/log/django_err.log

[program:celery]
command=celery -A apps.core worker -B --loglevel=INFO
directory=/backend
autostart=true
autorestart=true
stdout_logfile=/var/log/celery.log
stderr_logfile=/var/log/celery_err.log
Loading