diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000000..73f27f0515 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,73 @@ +name: Django-app workflow + +on: + push: + branches: [ main ] + +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pep8-naming flake8-broken-line flake8-return flake8-isort + pip install -r requirements.txt + + - name: Test with flake8 and django tests + run: | + # запуск проверки проекта по flake8 + python -m flake8 + # перейти в папку, содержащую manage.py — + #<корневая_папка_infra_actions>/<папка_проекта>/manage.py + cd infra_project/ + # запустить написанные разработчиком тесты + python manage.py test + + build_and_push_to_docker_hub: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + needs: tests + steps: + - name: Check out the repo + # Проверка доступности репозитория Docker Hub для workflow + uses: actions/checkout@v2 + - name: Set up Docker Buildx + # Вызов сборщика контейнеров docker + uses: docker/setup-buildx-action@v1 + - name: Login to Docker + # Запуск скрипта авторизации на Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Push to Docker Hub + # Пуш образа в Docker Hub + uses: docker/build-push-action@v2 + with: + push: true + tags: dmay92/infra_actions:latest + + deploy: + runs-on: ubuntu-latest + needs: build_and_push_to_docker_hub + steps: + - name: executing remote ssh commands to deploy + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USER }} + key: ${{ secrets.SSH_KEY }} + script: | + # Выполняет pull образа с DockerHub + sudo docker pull dmay92/infra_actions + #остановка всех контейнеров + sudo docker stop $(sudo docker ps -a -q) + sudo docker run --rm -d -p 5000:5000 dmay92/infra_actions \ No newline at end of file diff --git a/infra_project/infra_app/tests.py b/infra_project/infra_app/tests.py index 77c89862cb..dc049b18d9 100644 --- a/infra_project/infra_app/tests.py +++ b/infra_project/infra_app/tests.py @@ -1,4 +1,5 @@ from http import HTTPStatus + from django.test import Client, TestCase diff --git a/infra_project/infra_app/urls.py b/infra_project/infra_app/urls.py index 416b10259e..55822a6f33 100644 --- a/infra_project/infra_app/urls.py +++ b/infra_project/infra_app/urls.py @@ -6,6 +6,6 @@ urlpatterns = [ path('', views.index, name='index'), - path('second/', views.second_page, name='second_page'), + path('second_page/', views.second_page, name='second_page'), ] diff --git a/infra_project/infra_app/views.py b/infra_project/infra_app/views.py index 06eb12fbd3..a5d723bb2b 100644 --- a/infra_project/infra_app/views.py +++ b/infra_project/infra_app/views.py @@ -6,4 +6,4 @@ def index(request): def second_page(request): - return HttpResponse('А это вторая страница') + return HttpResponse('А это вторая страница!') diff --git a/infra_project/infra_project/settings.py b/infra_project/infra_project/settings.py index 012b314ae9..38c62e7005 100644 --- a/infra_project/infra_project/settings.py +++ b/infra_project/infra_project/settings.py @@ -25,7 +25,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['84.252.136.185'] # Application definition diff --git a/infra_project/infra_project/urls.py b/infra_project/infra_project/urls.py index 10c002baed..1e9393d952 100644 --- a/infra_project/infra_project/urls.py +++ b/infra_project/infra_project/urls.py @@ -1,20 +1,5 @@ -"""infra_project URL Configuration - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/2.2/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.urls import include, path - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) -""" from django.contrib import admin -from django.urls import path, include +from django.urls import include, path urlpatterns = [ path('', include('infra_app.urls', namespace='infra_app')), diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000000..52cdd9f7aa --- /dev/null +++ b/setup.cfg @@ -0,0 +1,12 @@ +[flake8] +ignore = + W503, + F811 +exclude = + tests/, + */migrations/, + venv/, + env/ +per-file-ignores = + */settings.py:E501 +max-complexity = 10 \ No newline at end of file