Skip to content

Commit

Permalink
Merge branch 'dev' into feat/create_ambassadors_app
Browse files Browse the repository at this point in the history
  • Loading branch information
Diavolution committed Mar 4, 2024
2 parents 5e624ac + 11cfff5 commit 78bded8
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 41 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
venv
.git
db.sqlite3
.env
.idea
.vscode
50 changes: 38 additions & 12 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@
name: Upload coverage reports to Codecov
name: Workflow

on:
push:
branches:
- main
- dev

jobs:
build:
tests:
runs-on: ubuntu-latest

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

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

- name: Run tests with coverage
- name: Install dependencies
run: |
pip install coverage
coverage run -m unittest discover
coverage report -m
python -m pip install --upgrade pip
pip install -r requirements_mini.txt
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4.0.1
- name: Check with flake8
run: python -m flake8 crm_yandex/

build_and_push_to_docker_hub:
name: Push Docker image to DockerHub
runs-on: ubuntu-latest
needs: tests
steps:
- name: Check out the repo
uses: actions/checkout@v3

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

- name: Login to Docker
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Push to DockerHub
uses: docker/build-push-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: CRM-for-Yandex-ambassadors/backend
push: true
tags: margoloko/ya_crm_backend:latest
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,3 @@ cython_debug/
.vscode/

migrations/

18 changes: 6 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
repos:
- repo: https://github.com/commitizen-tools/commitizen
rev: 3.5.3
rev: 3.6.0
hooks:
- id: commitizen
stages: [commit-msg]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -15,14 +15,8 @@ repos:
- id: check-merge-conflict
- id: check-json

- repo: https://github.com/commitizen-tools/commitizen
rev: 3.6.0
hooks:
- id: commitizen
stages: [commit-msg]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
exclude: (migrations)
Expand All @@ -32,16 +26,16 @@ repos:
rev: 6.1.0
hooks:
- id: flake8
exclude: (apps|__init__|migrations|backend/demand_oracle/demand_oracle/settings/)
exclude: (apps|__init__|migrations|backend/crm_yandex/crm_yandex/settings/)
additional_dependencies:
- flake8-docstrings
args:
- --max-line-length=91
- --ignore=D100, D105, D106

- repo: https://github.com/ambv/black
rev: 23.7.0
rev: 24.2.0
hooks:
- id: black
exclude: (migrations|backend/demand_oracle/demand_oracle/settings/)
exclude: (__init__|migrations|backend/crm_yandex/crm_yandex/settings/)
args: [--line-length=88]
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.11

WORKDIR /backend

RUN pip install gunicorn==20.1.0

COPY requirements.txt .

RUN pip install -r requirements.txt --no-cache-dir

RUN apt-get update && apt-get install -y nano

COPY crm_yandex/ .

CMD ["gunicorn", "crm_yandex.wsgi:application", "--bind", "0.0.0.0:8000", "--reload"]
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# backend CRM
![example workflow](https://github.com/CRM-for-Yandex-ambassadors/backend/actions/workflows/workflow.yaml/badge.svg)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

![python version](https://img.shields.io/badge/Python-3.11-green)
![django version](https://img.shields.io/badge/Django-4.2-green)
![djangorestframework version](https://img.shields.io/badge/DRF-3.14-green)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![codecov](https://codecov.io/gh/CRM-for-Yandex-ambassadors/backend/graph/badge.svg?token=AWKLAD8MLB)](https://codecov.io/gh/CRM-for-Yandex-ambassadors/backend)
### Оглавление:
- [backend CRM](#backend-crm)
- [Оглавление:](#оглавление)
- [О проекте:](#о-проекте)
- [О проекте](#о-проекте)
- [Запуск приложения](#запуск-приложения)
- [Запуск приложения на локальном сервере](#запуск-приложения-на-локальном-сервере)
- [Запуск тестов](#запуск-тестов)
Expand Down Expand Up @@ -150,4 +150,4 @@ cz c
- [Балахонова Марина](https://github.com/margoloko)
- [Виноградов Сергей](https://github.com/yan-gabala)
- [Раскатов Андрей](https://github.com/Diavolution)
- [Смирнов Артем](https://github.com/BeardedDev1911)
- [Климов Артем](https://github.com/grinchomsk)
18 changes: 13 additions & 5 deletions crm_yandex/crm_yandex/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""

import os
from datetime import timedelta
from pathlib import Path

from dotenv import load_dotenv

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

Expand All @@ -21,12 +24,12 @@
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-ir8*tzr*o!cqe@h)a35pht8($4*-+rqn6qp$f0g$*o9+g(a79n"
SECRET_KEY = os.getenv("SECRET_KEY")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ["127.0.0.1", "localhost", "158.160.13.137", "crm-yandex.ddns.net"]


# Application definition
Expand Down Expand Up @@ -80,8 +83,12 @@

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
"ENGINE": "django.db.backends.postgresql",
"NAME": os.getenv("POSTGRES_DB"),
"USER": os.getenv("POSTGRES_USER"),
"PASSWORD": os.getenv("POSTGRES_PASSWORD"),
"HOST": os.getenv("DB_HOST"),
"PORT": os.getenv("DB_PORT"),
}
}

Expand Down Expand Up @@ -136,6 +143,7 @@
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = "static/"
STATIC_ROOT = os.path.join(BASE_DIR, "static/")

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
Expand Down
4 changes: 2 additions & 2 deletions crm_yandex/crm_yandex/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@

urlpatterns = [
path("admin/", admin.site.urls),
path("auth/", include("djoser.urls")),
path("auth/", include("djoser.urls.jwt")),
path("authorize/", include("djoser.urls")),
path("authorize/", include("djoser.urls.jwt")),
]
Binary file added crm_yandex/db.sqlite3
Binary file not shown.
Binary file added crm_yandex/db.sqlite3.bak
Binary file not shown.
2 changes: 2 additions & 0 deletions infra/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM nginx:1.22.1
COPY nginx.conf /etc/nginx/templates/default.conf.template
35 changes: 35 additions & 0 deletions infra/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3'

volumes:
pg_data:

services:
db:
image: postgres:13.10
env_file: ../.env
volumes:
- pg_data:/var/lib/postgresql/data

backend:
image: margoloko/ya_crm_backend:latest
restart: always
build: ../.
env_file: ../.env
depends_on:
- db

#frontend:
# image: margoloko/ya_crm_frontend:latest
# volumes:
# - ...
# env_file: ../.env
# depends_on:
# - backend

nginx:
build: .
# Ключ ports устанавливает
# перенаправление всех запросов с порта 8000 хоста
# на порт 80 контейнера.
ports:
- 8000:80
8 changes: 5 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ django-oauth-toolkit==2.3.0
django-rest-framework-social-oauth2==1.2.0
django-templated-mail==1.1.1
djangorestframework==3.14.0
# djangorestframework-jwt==1.11.0
djangorestframework-simplejwt==4.7.2
djangorestframework-jwt
djangorestframework-simplejwt
djoser==2.1.0
filelock==3.13.1
identify==2.5.35
Expand All @@ -33,14 +33,16 @@ packaging==23.2
pathspec==0.12.1
platformdirs==4.2.0
pre-commit==3.6.2
psycopg2-binary==2.9.3
pycparser==2.21
PyJWT==2.8.0
python-dotenv==1.0.1
python3-openid==3.2.0
pytz==2024.1
PyYAML==6.0.1
requests==2.31.0
requests-oauthlib==1.3.1
six==1.16.0
social-auth-core==4.5.3
sqlparse==0.4.4
tomli==2.0.1
typing_extensions==4.9.0
Expand Down
19 changes: 19 additions & 0 deletions requirements_mini.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
asgiref==3.7.2
black==24.2.0
Django==4.2
django-oauth-toolkit==2.3.0
djangorestframework==3.14.0
django-templated-mail==1.1.1
djangorestframework-jwt
djangorestframework-simplejwt
djoser==2.1.0
flake8==6.1.0
flake8-isort==6.0.0
psycopg2-binary==2.9.3
python-dotenv==1.0.1
pytz==2024.1
sqlparse==0.4.4
typing_extensions==4.9.0
tzdata==2024.1
urllib3==2.2.1
virtualenv==20.25.1
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ exclude =
tests/,
*/migrations/,
venv/,
env/
*/venv/,
env/,
*/env/
per-file-ignores =
*/settings.py:E501
max-complexity = 10

0 comments on commit 78bded8

Please sign in to comment.