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

Feat/backend accounts app #4

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4cc1467
Design of whole system added
osmanmakhtoom Sep 24, 2024
8c735b6
Docker compose and docker files added
osmanmakhtoom Sep 24, 2024
d0b33f9
Gitignore added
osmanmakhtoom Sep 24, 2024
24015d4
Merge pull request #1 from osmanmakhtoom/infrastructure
osmanmakhtoom Sep 24, 2024
cee1112
coverage package added to have code test coverage
osmanmakhtoom Sep 24, 2024
340b428
backend apps folder structure and .coverage config added
osmanmakhtoom Sep 24, 2024
15a3dd3
postgres initi sql and dockerignore in backend added
osmanmakhtoom Sep 24, 2024
319d3cc
Merge pull request #2 from osmanmakhtoom/infrastructure
osmanmakhtoom Sep 24, 2024
e4c3bc8
Merge pull request #3 from osmanmakhtoom/feat/django-structure
osmanmakhtoom Sep 24, 2024
38af37f
makefile added to handle project simple ever
osmanmakhtoom Sep 24, 2024
5fcbc8c
CI/CD using github actions added to project, testing and deploying
osmanmakhtoom Sep 24, 2024
e877d84
Merge pull request #4 from osmanmakhtoom/feat/ci-cd
osmanmakhtoom Sep 24, 2024
fc26f79
accounts tests added
osmanmakhtoom Sep 24, 2024
0f5b672
accounts tests added and registered
osmanmakhtoom Sep 24, 2024
b2bc15c
Accounts models and managers added
osmanmakhtoom Sep 24, 2024
762e11a
tasks comment added
osmanmakhtoom Sep 24, 2024
958f22c
Accounts serializers added
osmanmakhtoom Sep 24, 2024
587f7c9
Accounts views added
osmanmakhtoom Sep 24, 2024
38b0f1c
Accounts urls added as router
osmanmakhtoom Sep 24, 2024
d7d03d9
Merge pull request #5 from osmanmakhtoom/feat/backend-accounts-app
osmanmakhtoom Sep 24, 2024
f00da19
cache manager and ip_address helper modules added
osmanmakhtoom Sep 27, 2024
21e8e0d
Model mixins added as util modules
osmanmakhtoom Sep 27, 2024
69106e2
Enum utils added
osmanmakhtoom Sep 27, 2024
b3cd28a
Rate limiter helper class added
osmanmakhtoom Sep 27, 2024
ccd34a0
User model corrected imports and staff fields added
osmanmakhtoom Sep 27, 2024
edbb3bc
Tests finalized
osmanmakhtoom Sep 27, 2024
af82cee
Serializer fields corrected
osmanmakhtoom Sep 27, 2024
1547a66
imports in init files organized to pass ruff check
osmanmakhtoom Sep 27, 2024
235d51c
FilterActiveManager added to utils managers
osmanmakhtoom Sep 27, 2024
9f8db96
Merge branch 'feat/backend-utils-app' into feat/backend-accounts-app
osmanmakhtoom Sep 27, 2024
4d52d1d
Filter Active added to UserManager as a father class
osmanmakhtoom Sep 27, 2024
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
36 changes: 36 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Deployment

on:
push:
branches: ["main"]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the source code
uses: actions/checkout@v3

- name: Install SSH KEY
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: unneccesarry

- name: Adding known_hosts
run: ssh-keyscan -p ${{ secrets.SSH_PORT }} -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts


- name: Deploy with rsync
run: rsync -avz -e "ssh -p ${{ secrets.SSH_PORT }}" . ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/var/www/

- name: executing remote ssh commands using password
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd /var/www/
make docker-restart
45 changes: 45 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Testing CI

on:
push:
branches: ["testing"]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the source code
uses: actions/checkout@v3

- name: Make envfile
uses: SpicyPizza/[email protected]
with:
envkey_DEBUG: true
envkey_CELERY_BROKER: ${{ secrets.CELERY_BROKER }}
envkey_CELERY_BACKEND: ${{ secrets.CELERY_BACKEND }}
envkey_CORS_ALLOW_ALL_ORIGINS: true
envkey_CORS_ALLOWED_ORIGIN: ${{ secrets.CORS_ALLOWED_ORIGIN }}
envkey_DJANGO_SETTINGS_MODULE: "apps.core.settings"
envkey_SECRET_KEY: ${{ secrets.SECRET_KEY }}
envkey_DJANGO_ALLOWED_HOSTS: ${{ secrets.DJANGO_ALLOWED_HOSTS }}
envkey_DATABASE_URL: ${{ secrets.DATABASE_URL }}
envkey_CACHE_URL: ${{ secrets.CACHE_URL }}
envkey_POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
envkey_POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
envkey_POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
envkey_RABBITMQ_DEFAULT_USER: ${{ secrets.RABBITMQ_DEFAULT_USER }}
envkey_RABBITMQ_DEFAULT_PASS: ${{ secrets.RABBITMQ_DEFAULT_PASS }}
envkey_RABBITMQ_DEFAULT_VHOST: ${{ secrets.RABBITMQ_DEFAULT_VHOST }}
envkey_SMS_PHONE_NUMBER: ${{ secrets.SMS_PHONE_NUMBER }}
envkey_SMS_CLIENT_ID: ${{ secrets.SMS_CLIENT_ID }}
envkey_ENV: ${{ secrets.ENV }}
directory: .
file_name: .env
fail_on_empty: false
sort_keys: false

- name: Run Project and Tests
run: |
make docker-up
make docker-lint
make docker-test
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.
128 changes: 128 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Makefile

# Variables
PROJECT_NAME = arman
PYTHON = python3
PIP = pip3
DJANGO_MANAGE = $(PYTHON) backend/manage.py
DOCKER_COMPOSE = docker compose

# Default environment file
ENV_FILE = .env

# Help command to display available tasks
.PHONY: help
help:
@echo "Available commands:"
@echo " make setup - Set up the project environment"
@echo " make run - Run the Django development server"
@echo " make migrate - Apply database migrations"
@echo " make superuser - Create a Django superuser"
@echo " make test - Run tests"
@echo " make lint - Lint the codebase"
@echo " make clean - Clean up project artifacts"
@echo " make docker-up - Start Docker services"
@echo " make docker-down - Stop Docker services"
@echo " make docker-restart - Restart all Docker services"
@echo " make docker-logs - View logs for all Docker services"
@echo " make docker-migrate - Run Docker Django migrations"
@echo " make docker-superuser - Create Docker Django superuser"
@echo " make docker-lint - Run Docker Django linter"
@echo " make docker-test - Run Docker Django tests"

# Set up the project environment
.PHONY: setup
setup:
@echo "Setting up the project environment..."
$(PIP) install -r backend/requirements.txt
$(DJANGO_MANAGE) migrate
$(DJANGO_MANAGE) collectstatic --noinput

# Run the Django development server
.PHONY: run
run:
@echo "Starting the Django development server..."
$(DJANGO_MANAGE) runserver 0.0.0.0:8000

# Apply migrations
.PHONY: migrate
migrate:
@echo "Applying migrations..."
$(DJANGO_MANAGE) migrate

# Create a Django superuser
.PHONY: superuser
superuser:
@echo "Creating a Django superuser..."
$(DJANGO_MANAGE) createsuperuser

# Run tests
.PHONY: test
test:
@echo "Running tests..."
$(DJANGO_MANAGE) test

# Lint the codebase
.PHONY: lint
lint:
@echo "Running linter..."
ruff format
ruff check --fix

# Clean up the project directory
.PHONY: clean
clean:
@echo "Cleaning up project artifacts..."
find . -name '*.pyc' -delete
find . -name '__pycache__' -delete

# Run initial database setup (optional)
.PHONY: initdb
initdb:
@echo "Initializing the database..."
$(DJANGO_MANAGE) makemigrations
$(DJANGO_MANAGE) migrate

# ---- Docker commands ----

# Start Docker services
.PHONY: docker-up
docker-up:
@echo "Starting Docker services..."
$(DOCKER_COMPOSE) up --build -d

# Stop Docker services
.PHONY: docker-down
docker-down:
@echo "Stopping Docker services..."
$(DOCKER_COMPOSE) down --remove-orphans

# Restart all services
.PHONY: docker-restart
docker-restart:
$(DOCKER_COMPOSE) down && $(DOCKER_COMPOSE) up -d

# View logs
.PHONY: docker-logs
docker-logs:
$(DOCKER_COMPOSE) logs -f

# Apply migrations
.PHONY: docker-migrate
docker-migrate:
$(DOCKER_COMPOSE) exec backend python manage.py migrate

# Create superuser
.PHONY: docker-superuser
docker-superuser:
$(DOCKER_COMPOSE) exec backend python manage.py createsuperuser

# Run linter
.PHONY: docker-lint
docker-lint:
$(DOCKER_COMPOSE) exec backend ruff format && $(DOCKER_COMPOSE) exec backend ruff check --fix

# Run tests
.PHONY: docker-test
docker-test:
$(DOCKER_COMPOSE) exec backend python manage.py test
9 changes: 9 additions & 0 deletions backend/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[run]
branch = True
omit = *migrations*,
*urls*,
*test*,
*admin*,
./manage.py,
./apps/config/*,
*__init__*
3 changes: 3 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.*
!.coveragerc
!.env
Loading