diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..202e68b04 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,73 @@ +name: Django-app workflow + +on: [push] + +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: | + python -m flake8 + 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 + uses: actions/checkout@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to Docker + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Push to Docker Hub + uses: docker/build-push-action@v2 + with: + push: true + tags: niksin1/infra_ac: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 }} + passphrase: ${{ secrets.PASSPHRASE }} + script: | + sudo docker pull niksin1/infra_ac + sudo docker stop $(sudo docker ps -a -q) + sudo docker run --rm -d -p 5000:5000 niksin1/infra_ac + + send_message: + runs-on: ubuntu-latest + needs: deploy + steps: + - name: send message + uses: appleboy/telegram-action@master + with: + to: ${{ secrets.TELEGRAM_TO }} + token: ${{ secrets.TELEGRAM_TOKEN }} + message: ${{ github.workflow }} успешно выполнен! diff --git a/infra_project/infra_app/tests.py b/infra_project/infra_app/tests.py index 77c89862c..dc049b18d 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 416b10259..9ba21a628 100644 --- a/infra_project/infra_app/urls.py +++ b/infra_project/infra_app/urls.py @@ -6,6 +6,5 @@ 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 06eb12fbd..a5d723bb2 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 012b314ae..93d5fcebf 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 = ['51.250.106.212', '51.250.106.212:5000'] # Application definition diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 000000000..129b8b886 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,15 @@ +[flake8] +ignore = + W503, + F811, + I001, + I003, + I005 +exclude = + tests/, + */migrations/, + venv/, + env/ +per-file-ignores = + */settings.py:E501 +max-complexity = 10