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: Deploy bot on stage | |
on: | |
workflow_run: | |
workflows: [Create and publish a Docker image] | |
types: [completed] | |
branches: [develop] | |
jobs: | |
on-success: | |
runs-on: ubuntu-latest | |
environment: | |
name: stage_deploy | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- name: Run a multi-line script | |
uses: actions/checkout@v2 | |
run: | | |
mkdir ../spread_wings_bot/infra/dev/ | |
cp -TR . ../spread_wings_bot/infra/dev/ | |
tar -cvf deploy.tar ../spread_wings_bot/infra/dev/ | |
- name: copy service file | |
uses: appleboy/scp-action@v0.1.4 | |
with: | |
host: ${{ secrets.VM_HOST }} | |
username: ${{ secrets.VM_USER }} | |
password: ${{ secrets.VM_PASSWORD }} | |
source: "deploy.tar" | |
target: /home/deploy/spread_wings_bot/infra/dev/ | |
- name: ssh pull and start | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.VM_HOST }} | |
username: ${{ secrets.VM_USER }} | |
password: ${{ secrets.VM_PASSWORD }} | |
script: | | |
cd /home/deploy/spread_wings_bot/infra/dev/ | |
rm .env | |
touch .env | |
echo NGINX_HOST=${{ secrets.NGINX_HOST }} >> .env | |
echo NGINX_PORT=${{ secrets.NGINX_PORT }} >> .env | |
echo TELEGRAM_TOKEN=${{ secrets.TELEGRAM_TOKEN }} >> .env | |
echo WEBHOOK_ENABLED=${{ secrets.WEBHOOK_ENABLED }} >> .env | |
echo WEBHOOK_URL=${{ secrets.WEBHOOK_URL }} >> .env | |
echo WEBHOOK_SECRET_KEY=${{ secrets.WEBHOOK_SECRET_KEY }} >> .env | |
echo REDIS_HOST=${{ secrets.REDIS_HOST }} >> .env | |
echo REDIS_PORT=${{ secrets.REDIS_PORT }} >> .env | |
echo REDIS=${{ secrets.REDIS }} >> .env | |
echo DJANGO_SECRET_KEY=${{ secrets.DJANGO_SECRET_KEY }} >> .env | |
echo DEBUG=False >> .env | |
echo ALLOWED_HOSTS=${{ secrets.ALLOWED_HOSTS }} >> .env | |
echo POSTGRES_HOST=${{ secrets.POSTGRES_HOST }} >> .env | |
echo POSTGRES_PORT=${{ secrets.POSTGRES_PORT }} >> .env | |
echo POSTGRES_DB=${{ secrets.POSTGRES_DB }} >> .env | |
echo POSTGRES_USER=${{ secrets.POSTGRES_USER }} >> .env | |
echo POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} >> .env | |
echo EMAIL_BACKEND=${{ secrets.EMAIL_BACKEND }} >> .env | |
echo DEFAULT_EMAIL_ADDRESS=${{ secrets.DEFAULT_EMAIL_ADDRESS }} >> .env | |
echo EMAIL_ACCOUNT=${{ secrets.EMAIL_ACCOUNT }} >> .env | |
echo EMAIL_HOST=${{ secrets.EMAIL_HOST }} >> .env | |
echo EMAIL_PASSWORD=${{ secrets.EMAIL_PASSWORD }} >> .env | |
echo EMAIL_PORT=${{ secrets.EMAIL_PORT }} >> .env | |
echo DJANGO_SUPERUSER_EMAIL=${{ secrets.DJANGO_SUPERUSER_EMAIL }} >> .env | |
echo DJANGO_SUPERUSER_PASSWORD=${{ secrets.DJANGO_SUPERUSER_PASSWORD }} >> .env | |
# Cleaning unused containers, images, networks | |
docker system prune --force | |
# Installing defend service for app | |
# Шаг с копированием в строках 16-23 можно заменить командой ниже - нужно тестировать | |
# scp infra/dev/spread_wings_bot.service ${{ secrets.VM_USER }}@${{ secrets.VM_HOST }}:/spread_wings_bot/infra/dev/ | |
sudo cp -f /home/deploy/spread_wings_bot/infra/dev/spread_wings_bot.service /etc/systemd/system/spread_wings_bot.service | |
sudo systemctl daemon-reload | |
sudo systemctl restart spread_wings_bot.service | |
# Installing the app | |
docker-compose -f docker-compose.stage.yaml stop | |
docker-compose -f docker-compose.stage.yaml pull | |
docker-compose -f docker-compose.stage.yaml up -d | |
# Applying initialization commands | |
docker exec spread-wings-bot python manage.py migrate | |
docker exec spread-wings-bot python manage.py collectstatic --noinput |