Skip to content

Commit

Permalink
tests6
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduard-Bodreev committed Feb 10, 2025
1 parent 9ffe01f commit 697b7ec
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 110 deletions.
220 changes: 110 additions & 110 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,110 +1,110 @@
# name: CI/CD for Kittygram

# on:
# push:
# branches:
# - main

# jobs:
# lint:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout Repository
# uses: actions/checkout@v4

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

# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# pip install flake8

# - name: Run PEP8 check
# run: |
# flake8 backend --count --max-complexity=10 --max-line-length=119 --show-source --statistics

# test:
# runs-on: ubuntu-latest
# needs: lint
# steps:
# - name: Checkout Repository
# uses: actions/checkout@v4

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

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

# - name: Run backend tests
# run: |
# pytest tests/

# - name: Run frontend tests
# run: |
# cd frontend && npm install && npm test

# deploy:
# runs-on: ubuntu-latest
# needs: test
# steps:
# - name: Checkout Repository
# uses: actions/checkout@v4

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

# - name: Log in to DockerHub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}

# - name: Build and push backend image
# run: |
# docker build -t ${{ secrets.DOCKER_USERNAME }}/kittygram_backend:latest ./backend
# docker push ${{ secrets.DOCKER_USERNAME }}/kittygram_backend:latest

# - name: Build and push frontend image
# run: |
# docker build -t ${{ secrets.DOCKER_USERNAME }}/kittygram_frontend:latest ./frontend
# docker push ${{ secrets.DOCKER_USERNAME }}/kittygram_frontend:latest

# - name: Build and push gateway image
# run: |
# docker build -t ${{ secrets.DOCKER_USERNAME }}/kittygram_gateway:latest ./nginx
# docker push ${{ secrets.DOCKER_USERNAME }}/kittygram_gateway:latest

# - name: Deploy to Server
# uses: appleboy/ssh-action@v1.0.3
# with:
# host: ${{ secrets.SSH_HOST }}
# username: ${{ secrets.SSH_USER }}
# key: ${{ secrets.SSH_KEY }}
# script: |
# cd ~/kittygram
# docker pull ${{ secrets.DOCKER_USERNAME }}/kittygram_backend:latest
# docker pull ${{ secrets.DOCKER_USERNAME }}/kittygram_frontend:latest
# docker pull ${{ secrets.DOCKER_USERNAME }}/kittygram_gateway:latest
# docker-compose -f docker-compose.production.yml down
# docker-compose -f docker-compose.production.yml up -d
# docker exec backend python manage.py migrate
# docker exec backend python manage.py collectstatic --noinput
# docker restart gateway

# notify:
# runs-on: ubuntu-latest
# needs: deploy
# steps:
# - name: Send Telegram Notification
# run: |
# curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
# -d "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \
# -d "text=🎉 Kittygram успешно задеплоен!"
name: CI/CD for Kittygram

on:
push:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Run PEP8 check
run: |
flake8 backend --count --max-complexity=10 --max-line-length=119 --show-source --statistics
test:
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout Repository
uses: actions/checkout@v4

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

- name: Install backend dependencies
run: |
python -m pip install --upgrade pip
pip install -r backend/requirements.txt
- name: Run backend tests
run: |
pytest tests/
- name: Run frontend tests
run: |
cd frontend && npm install && npm test
deploy:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout Repository
uses: actions/checkout@v4

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

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

- name: Build and push backend image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/kittygram_backend:latest ./backend
docker push ${{ secrets.DOCKER_USERNAME }}/kittygram_backend:latest
- name: Build and push frontend image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/kittygram_frontend:latest ./frontend
docker push ${{ secrets.DOCKER_USERNAME }}/kittygram_frontend:latest
- name: Build and push gateway image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/kittygram_gateway:latest ./nginx
docker push ${{ secrets.DOCKER_USERNAME }}/kittygram_gateway:latest
- name: Deploy to Server
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_KEY }}
script: |
cd ~/kittygram
docker pull ${{ secrets.DOCKER_USERNAME }}/kittygram_backend:latest
docker pull ${{ secrets.DOCKER_USERNAME }}/kittygram_frontend:latest
docker pull ${{ secrets.DOCKER_USERNAME }}/kittygram_gateway:latest
docker-compose -f docker-compose.production.yml down
docker-compose -f docker-compose.production.yml up -d
docker exec backend python manage.py migrate
docker exec backend python manage.py collectstatic --noinput
docker restart gateway
notify:
runs-on: ubuntu-latest
needs: deploy
steps:
- name: Send Telegram Notification
run: |
curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
-d "chat_id=${{ secrets.TELEGRAM_CHAT_ID }}" \
-d "text=🎉 Kittygram успешно задеплоен!"
10 changes: 10 additions & 0 deletions backend/kittygram_backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ def index(request):

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

import logging
from django.http import HttpResponse

logger = logging.getLogger(__name__)

def index(request):
print("Запрос на / дошел до Django!")
logger.info("Запрос на / дошел до Django!")
return HttpResponse("Kittygram is running!")

0 comments on commit 697b7ec

Please sign in to comment.