Skip to content

Commit

Permalink
Merge pull request #275 from ZUS666/develop
Browse files Browse the repository at this point in the history
test
  • Loading branch information
ZUS666 authored Nov 16, 2023
2 parents 5937aca + ccedcbd commit 7a8710e
Show file tree
Hide file tree
Showing 36 changed files with 1,908 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ AWS_SECRET_ACCESS_KEY=секретный_ключ_s3
AWS_S3_ENDPOINT_URL=энд_поинт_s3
AWS_S3_REGION_NAME=регион_s3

FLOWER_BASIC_AUTH=username:password
FLOWER_BASIC_AUTH=username:password
38 changes: 19 additions & 19 deletions .github/workflows/api_spot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
source: "infra/docker-compose.yml"
target: ${{ secrets.DEPLOY_PATH }}
overwrite: true

send_nginx:
name: Send nginx
runs-on: ubuntu-latest
Expand All @@ -43,20 +43,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker
uses: docker/login-action@v2
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 Docker Hub
uses: docker/build-push-action@v4
uses: docker/build-push-action@v4
with:
context: ./api_spot/
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.IMAGE_NAME }}:latest
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.IMAGE_NAME }}:latest

deploy:
runs-on: ubuntu-latest
Expand All @@ -68,15 +68,15 @@ jobs:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
password: ${{ secrets.PASSWORD }}
key: ${{ secrets.SSH_KEY }}
key: ${{ secrets.SSH_KEY }}
script: |
cd ${{ secrets.DEPLOY_PATH }}
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.IMAGE_NAME }}:latest
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.IMAGE_NAME }}:latest
sudo docker rmi $(sudo docker images -f dangling=true)
rm .env
touch .env
echo ALLOWED_HOSTS=${{ secrets.ALLOWED_HOSTS }} >> .env
echo HOST=${{ secrets.HOST }} >> .env
echo SECRET_KEY=${{ secrets.SECRET_KEY }} >> .env
Expand All @@ -100,19 +100,19 @@ jobs:
echo GMAIL_API_CLIENT_ID=${{ secrets.GMAIL_API_CLIENT_ID }} >> .env
echo GMAIL_API_CLIENT_SECRET=${{ secrets.GMAIL_API_CLIENT_SECRET }} >> .env
echo GMAIL_API_REFRESH_TOKEN=${{ secrets.GMAIL_API_REFRESH_TOKEN }} >> .env
echo COMPANY_NAME=${{ secrets.COMPANY_NAME }} >> .env
echo SITE_URL=${{ secrets.SITE_URL }} >> .env
echo AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} >> .env
echo AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} >> .env
echo AWS_S3_ENDPOINT_URL=${{ secrets.AWS_S3_ENDPOINT_URL }} >> .env
echo AWS_S3_REGION_NAME=${{ secrets.AWS_S3_REGION_NAME }} >> .env
cd infra
sudo docker-compose stop
sudo docker-compose rm backend
sudo docker-compose rm celery
sudo docker-compose rm celery_beat
sudo docker-compose up -d
sudo docker-compose exec -d backend python manage.py migrate
sudo docker compose stop
sudo docker compose rm backend
sudo docker compose rm celery
sudo docker compose rm celery_beat
sudo docker compose up -d
sudo docker compose exec -d backend python manage.py migrate
13 changes: 6 additions & 7 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ jobs:
flake8:
runs-on: ubuntu-latest
steps:
-
-
uses: actions/checkout@v2
-
-
name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11.0
-
-
name: Install dependencies
run: |
python -m pip install --upgrade pip
run: |
python -m pip install --upgrade pip
pip install flake8 pep8-naming flake8-broken-line flake8-isort
pip install -r api_spot/requirements.txt
-
-
name: Test with flake8
run: |
python -m flake8
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,4 @@ static/
**/locconf.py

*.json
*.sql
*.sql
49 changes: 49 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
hooks:
- id: trailing-whitespace # убирает лишние пробелы
- id: check-added-large-files # проверяет тяжелые файлы на изменения
- id: check-yaml # проверяет синтаксис .yaml файлов
- id: check-json # проверяет синтаксис .json файлов
exclude: launch.json
- id: check-case-conflict # проверяет файлы, которые могут конфликтовать в файловых системах без учета регистра.
- id: check-merge-conflict # проверяет файлы, содержащие конфликтные строки слияния.
- id: double-quote-string-fixer # заменяет " на '
- id: end-of-file-fixer # добавляет пустую строку в конце файла

# Отсортировывает импорты в проекте
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)

# Обновляет синтаксис Python кода в соответствии с последними версиями
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
hooks:
- id: pyupgrade
args: [--py310-plus]

# Форматирует код под PEP8
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v2.0.1
hooks:
- id: autopep8
args: [--max-line-length=80, --in-place]

# Сканер стилистических ошибок, нарушающие договоренности PEP8
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
exclude: "__init__.py"
args: ["--ignore=F821,F403,F405"]

# Проверка статических типов с помощью mypy
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
exclude: 'migrations'
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,29 @@ docker compose exec web python manage.py collectstatic --noinput
## Запуск проекта на локальной машине Linux

* Создать виртуальное окружение и активировать его
* Установить зависимости
* Установить зависимости
```
sudo apt install python3.10-venv
python3 -m vevn venv
source venv/bin/activate
pip install -r requirements.txt
```
* Или установить [pipenv](https://pipenv.pypa.io/en/latest/) и работать в нем
```
$ pip install --user pipenv
```
* Проверить установку
```
$ pipenv --version
pipenv, version 2023.10.24
```
* Перейти в папку api_spot и активировать pipenv
```
cd api_spot
pipenv sync
pipenv shell
```


* Установите Redis в качестве брокера Celery и серверной части базы данных
```
Expand Down Expand Up @@ -155,7 +171,7 @@ python manage.py runserver
celery -A api_spot flower --port=5001
```

* Для заполнения или обновления базы данных исползовать https://localhost/admin
* Для заполнения или обновления базы данных исползовать https://localhost/admin
* в Postman тестировать api


Expand Down
2 changes: 1 addition & 1 deletion api_spot/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ COPY . .
RUN python -m pip install --upgrade pip
RUN pip install -r requirements.txt --no-cache-dir

CMD ["gunicorn", "api_spot.wsgi:application", "--bind", "0:8000" ]
CMD ["gunicorn", "api_spot.wsgi:application", "--bind", "0:8000" ]
35 changes: 35 additions & 0 deletions api_spot/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
boto3 = "==1.28.66"
celery = {extras = ["redis"], version = "==5.3.4"}
django = "==4.2.5"
django-celery-beat = "==2.5.0"
django-cors-headers = "==3.8.0"
django-filter = "==23.2"
django-gmailapi-backend = "==0.3.2"
django-phonenumber-field = {extras = ["phonenumberslite"], version = "==7.1.0"}
django-cleanup = "==8.0.0"
django-ckeditor = "==6.7.0"
djangorestframework = "==3.14.0"
django-storages = "==1.14.2"
djoser = "==2.2.0"
drf-api-logger = "==1.1.14"
drf-spectacular = "==0.26.4"
flower = "==2.0.1"
gunicorn = "==21.2.0"
phonenumbers = "==8.13.20"
pillow = "==10.0.1"
psycopg2-binary = "==2.9.7"
python-dotenv = "==1.0.0"
django-celery-results = "==2.5.1"
pre-commit = "*"

[dev-packages]

[requires]
python_version = "3.11"
python_full_version = "3.11.0"
Loading

0 comments on commit 7a8710e

Please sign in to comment.