Skip to content

NiKuma0 CI/CD process... #330

NiKuma0 CI/CD process...

NiKuma0 CI/CD process... #330

Workflow file for this run

name: CI/CD sobitie
run-name: ${{ github.actor }} CI/CD process...
on:
workflow_dispatch:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pep8-naming flake8-broken-line flake8-return flake8-isort
- name: flake8
run: |
python -m flake8 --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics
build_and_push_to_docker_hub:
name: Push 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 sobitie to Docker Hub
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/sobitie:latest
deploy:
name: Deploy to server
runs-on: ubuntu-latest
needs: build_and_push_to_docker_hub
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: copy file via ssh key
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
source: "docker-compose.yaml, nginx/*.conf"
target: "/home/deployment-user/"
- name: executing remote ssh commands to deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
key: ${{ secrets.SSH_KEY }}
script: |
sudo docker-compose stop
sudo docker system prune -af
touch .env
cat /dev/null > .env
echo DJ_SECRET_KEY="${{ secrets.DJ_SECRET_KEY }}" >> .env
echo VK_APP_SERVICE_KEY="${{ secrets.VK_APP_SERVICE_KEY }}" >> .env
echo VK_ACCESS_TOKEN="${{ secrets.VK_ACCESS_TOKEN }}" >> .env
echo VK_GROUP_ID="${{ secrets.VK_GROUP_ID }}" >> .env
echo TELEGRAM_TOKEN="${{ secrets.TELEGRAM_TOKEN }}" >> .env
echo API_ADDRESS="${{ secrets.API_ADDRESS }}" >> .env
echo DEPLOY_PATH="${{ secrets.DEPLOY_PATH }}" >> .env
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/sobitie:latest
sudo docker-compose up -d
sudo docker-compose exec -it web python manage.py migrate
sudo docker-compose exec -it web python manage.py collectstatic --no-input
echo "OK"