Skip to content
This repository was archived by the owner on Mar 23, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
4b58487
feat: add user registration and email verification
smm-1383 Nov 6, 2024
151d3d2
feat: add user login and reset password
KianYari Nov 6, 2024
d9dc31c
Merge pull request from feat/authentication
smm-1383 Nov 6, 2024
51e898b
feat: swagger added to project
smm-1383 Nov 6, 2024
7b28b0f
feat: CICD added to project
KianYari Nov 6, 2024
a6611ff
Update liara.yaml
KianYari Nov 6, 2024
5b08a6e
update liara.yaml
KianYari Nov 6, 2024
5802c2d
Update liara.yaml
KianYari Nov 6, 2024
fa8d86b
testing (#5)
KianYari Nov 6, 2024
39e8d80
Update liara.yaml
KianYari Nov 6, 2024
0dd137b
fix: hopefully last commit to fix CICD
KianYari Nov 6, 2024
651bb15
change CICD to trigger on merge instead of push
KianYari Nov 6, 2024
2ef87ef
Delete test
KianYari Nov 6, 2024
2daa30c
update .gitignore
KianYari Nov 6, 2024
17a7acf
update .gitignore
KianYari Nov 7, 2024
5e59cdf
fix: corsheaders add
KianYari Nov 8, 2024
2204403
test
KianYari Nov 9, 2024
eb2eaeb
feat: registration policy modified
KianYari Nov 10, 2024
aba78f4
fix: registration modified
KianYari Nov 10, 2024
3c35baa
Update CICD configuration
KianYari Nov 10, 2024
bff6c5b
fix: refresh token added
KianYari Nov 12, 2024
a76f8ae
fix: refresh token added
KianYari Nov 12, 2024
7d00e3b
User CRUD
smm-1383 Nov 13, 2024
13e7ea1
Dev/group crud
KianYari Nov 14, 2024
73caa99
Dev/core
KianYari Nov 17, 2024
3615aef
Dev/profile pic-cloud storage
smm-1383 Nov 18, 2024
aa6a38b
fix: user retrieve and update modified
KianYari Nov 21, 2024
d24f6c5
Fix/general for sprint 2
KianYari Nov 25, 2024
f50974a
Merge branch 'main' into develop
KianYari Nov 25, 2024
74501d4
feat: add group pic (#16)
KianYari Nov 25, 2024
1efa1d8
feat: add change password (#17)
KianYari Nov 26, 2024
cdff379
Refactor/service layer (#18)
KianYari Nov 26, 2024
7a67500
Feat/pagination (#19)
KianYari Nov 26, 2024
5e2e40f
Feat/filter-sort-search (#20)
KianYari Nov 27, 2024
a09b930
Feat/chat (#21)
smm-1383 Nov 27, 2024
be3508c
Feat/Live Chat (#22)
KianYari Nov 29, 2024
48b860d
feat: add filter by timeslot (#23)
smm-1383 Dec 1, 2024
ebdeb3d
Feat/notification (#24)
KianYari Dec 3, 2024
a759c99
Fix/sprint3 (#25)
KianYari Dec 9, 2024
fc13a15
Merge branch 'main' into develop
KianYari Dec 9, 2024
8d5ba85
Fix/websocket header (#27)
KianYari Dec 15, 2024
16bcc83
Testing/configuration (#28)
KianYari Dec 15, 2024
8a10ff7
fix: group time slot not found error (#29)
KianYari Dec 15, 2024
b6f31c1
Feat/monitoring (#30)
KianYari Dec 15, 2024
29d8b37
Fix/image names (#31)
KianYari Dec 16, 2024
dd7c165
Feat/profiling logging (#32)
KianYari Dec 16, 2024
c33c234
Feat/user and group deletion (#33)
KianYari Dec 17, 2024
53eec4f
feat: redis setup on server (#34)
KianYari Dec 17, 2024
af73c1f
Feat/ci/cd (#35)
KianYari Dec 18, 2024
66a602f
Fix/separate CI and CD(#36)
KianYari Dec 18, 2024
c8774bc
Feat/status 500 handling (#37)
smm-1383 Dec 19, 2024
8ce6c67
Feat/suggestion algorithm (#38)
smm-1383 Dec 19, 2024
8629450
Feat/celery deployment (#39)
KianYari Dec 19, 2024
d6189bd
Feat/dashboarding (#40)
KianYari Dec 21, 2024
7125887
Fix/sprint4 (#41)
KianYari Dec 21, 2024
f916ec9
Fix/sprint issues (#42)
KianYari Dec 26, 2024
8138f57
Merge branch 'main' into develop
KianYari Dec 26, 2024
4b777ce
Testing/accounts (#44)
smm-1383 Dec 30, 2024
7dc4cf9
Refactor/forget password (#45)
KianYari Dec 30, 2024
657eb72
Feat/all notifs (#46)
KianYari Dec 30, 2024
e9ce136
Fix/change password (#47)
KianYari Dec 30, 2024
803d457
Fix/permissions (#48)
smm-1383 Dec 30, 2024
80620e8
Fix/chat notif (#49)
KianYari Dec 31, 2024
65f9357
Fix/authentication issues (#50)
KianYari Dec 31, 2024
839038a
Fix/sprint5 issues (#51)
KianYari Jan 29, 2025
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
74 changes: 74 additions & 0 deletions .github/workflows/CD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: CD

on:
push:
branches:
- fix/sprint_issues
pull_request:
branches:
- develop
types:
- closed

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Write .env file
run: echo "${{ secrets.ENV_FILE }}" > .env

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.USERNAME }}
password: ${{ secrets.TOKEN }}

- name: Install Docker Compose
run: |
sudo curl -L "https://github.com/docker/compose/releases/download/v2.23.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

- name: Build and Push Docker Image
run: |
docker-compose build
docker-compose push

- name: Copy files to server via SSH
uses: appleboy/scp-action@v0.1.0
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
password: ${{ secrets.SERVER_PASSWORD }}
source: "docker-compose.yml, prometheus.yml, alert_rules.yml"
target: "/home/fd/"

- name: Copy files and deploy
uses: appleboy/ssh-action@v0.1.8
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
password: ${{ secrets.SERVER_PASSWORD }}
script: |

cd /home/fd

echo "${{ secrets.ENV_FILE }}" > .env
echo "${{ secrets.ALERT_MANAGER}}" > alertmanager.yml

chmod 644 .env

docker compose pull web

docker compose down

docker compose up -d

36 changes: 36 additions & 0 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
pull_request:
branches:
- develop
types:
- opened

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Write .env file
run: echo "${{ secrets.ENV_FILE }}" > .env

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Run Tests
env:
ENV_FILE: ${{ secrets.ENV_FILE }}
run: |
python manage.py test --keepdb

6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ Makefile
venv/
.env
**/__pycache__/
Dockerfile
docker-compose.yml
.Dockerignore
.env.docker
alertmanager.yml
.vscode/
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.12-alpine

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /app

RUN apk add --no-cache gcc musl-dev mariadb-connector-c-dev mariadb-dev pkgconfig

COPY requirements.txt /app/
RUN pip install --no-cache-dir -r requirements.txt

COPY . /app/

EXPOSE 8000

CMD ["daphne", "FD.asgi:application", "--bind", "0.0.0.0", "--port", "8000"]
3 changes: 3 additions & 0 deletions FD/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .celery import app as celery_app

__all__ = ('celery_app',)
23 changes: 23 additions & 0 deletions FD/celery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os
from celery import Celery
from celery.schedules import crontab

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'FD.settings')

app = Celery('FD')

app.config_from_object('django.conf:settings', namespace='CELERY')
app.conf.broker_connection_retry_on_startup = True

app.autodiscover_tasks()

app.conf.beat_schedule = {
'cache-matching-groups': {
'task': 'home.tasks.cache_matching_groups',
'schedule': crontab(hour=2),
},
'test-celery': {
'task': 'home.tasks.test_celery',
'schedule': crontab(minute=1),
},
}
43 changes: 34 additions & 9 deletions FD/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from datetime import timedelta
from pathlib import Path
from dotenv import load_dotenv


import os

load_dotenv()
Expand Down Expand Up @@ -31,6 +33,8 @@
'storages',
'django_filters',
'channels',
'django_prometheus',


'authentication',
'groups',
Expand All @@ -42,7 +46,9 @@
]

MIDDLEWARE = [
'django_prometheus.middleware.PrometheusBeforeMiddleware',
'corsheaders.middleware.CorsMiddleware',


'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand All @@ -51,6 +57,8 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',

'django_prometheus.middleware.PrometheusAfterMiddleware',
]

CORS_ALLOW_ALL_ORIGINS = True
Expand All @@ -74,7 +82,7 @@
},
]

# WSGI_APPLICATION = 'FD.wsgi.application'

ASGI_APPLICATION = "FD.asgi.application"


Expand Down Expand Up @@ -131,7 +139,7 @@
'rest_framework_simplejwt.authentication.JWTAuthentication',
),
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
'PAGE_SIZE': 1
'PAGE_SIZE': 3
}

SPECTACULAR_SETTINGS = {
Expand Down Expand Up @@ -169,18 +177,35 @@



import urllib.parse
import redis

redis_url = os.environ.get('REDIS_URL')
parsed_url = urllib.parse.urlparse(redis_url)

CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [f"rediss://{parsed_url.netloc}"],
# "hosts": [("127.0.0.1", 6379)],
"hosts": [(os.getenv("REDIS_URL"))],
},
},
}
}



REDIS_URL = os.getenv("REDIS_URL")

CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": REDIS_URL,
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
}
}

CELERY_BROKER_URL = os.getenv("REDIS_URL")
CELERY_RESULT_BACKEND = os.getenv("REDIS_URL")
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Asia/Tehran'

41 changes: 41 additions & 0 deletions FD/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
from django.contrib import admin
from django.urls import include, path
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView
from django_prometheus import exports
from rest_framework.response import Response
from rest_framework import status

def trigger_error(request):
division_by_zero = 1 / 0

from rest_framework.decorators import api_view

@api_view(['GET'])
def trigger_400(request):
return Response("Bad Request", status=status.HTTP_400_BAD_REQUEST)

@api_view(['GET'])
def trigger_401(request):
return Response("Unauthorized", status=status.HTTP_401_UNAUTHORIZED)

@api_view(['GET'])
def trigger_403(request):
return Response("Forbidden", status=status.HTTP_403_FORBIDDEN)

@api_view(['GET'])
def trigger_404(request):
return Response("Not Found", status=status.HTTP_404_NOT_FOUND)

@api_view(['GET'])
def trigger_500(request):
return Response("Internal Server Error", status=status.HTTP_500_INTERNAL_SERVER_ERROR)


urlpatterns = [
path('trigger_error/', trigger_error),
path('', include('django_prometheus.urls')),

path('admin/', admin.site.urls),

path('authentication/', include('authentication.urls')),
Expand All @@ -12,4 +44,13 @@

path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
path('api/schema/docs/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),

path('notifications/', include('notifications.urls')),

path('trigger_400/', trigger_400),
path('trigger_401/', trigger_401),
path('trigger_403/', trigger_403),
path('trigger_404/', trigger_404),
path('trigger_500/', trigger_500),

]
29 changes: 29 additions & 0 deletions alert_rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
groups:
- name: website
rules:
- alert: WebsiteDown
expr: up{job="website"} == 0
for: 1m
labels:
severity: critical
annotations:
summary: "Website is down"
description: "The website has been down for more than 1 minute"

- alert: HighResponseTime
expr: prometheus_http_request_duration_seconds{job="website"} > 2
for: 5m
labels:
severity: warning
annotations:
summary: "High response time"
description: "Website response time is above 2 seconds for 5 minutes"

- alert: HighErrorRate
expr: rate(django_http_responses_total_by_status_total{status=~"5.."}[5m]) > 0
for: 0s
labels:
severity: warning
annotations:
summary: "High error rate"
description: "Website is returning too many 5xx errors"
18 changes: 0 additions & 18 deletions authentication/migrations/0002_user_profile_image.py

This file was deleted.

24 changes: 24 additions & 0 deletions authentication/migrations/0004_otp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 5.1.2 on 2024-12-27 16:54

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('authentication', '0003_alter_tempuser_otp'),
]

operations = [
migrations.CreateModel(
name='OTP',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('otp', models.CharField(max_length=6)),
('date_created', models.DateTimeField(auto_now_add=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='forget_password_otp', to=settings.AUTH_USER_MODEL)),
],
),
]
Loading