Fix backend and gateway issues3 #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 успешно задеплоен!" |