Deploy bot on prod #1
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 prod | |
on: | |
workflow_run: | |
workflows: [Create and publish a Docker image] | |
types: [completed] | |
branches: [master] | |
jobs: | |
on-success: | |
runs-on: ubuntu-latest | |
environment: | |
name: prod_deploy | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Prepare infra/prod | |
run: | | |
mkdir ../build | |
cp -TR ./infra/prod ../build | |
tar -cvf deploy.tar ../build/ | |
- name: copy infra/prod | |
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/prod/ | |
- 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/prod/ | |
tar -xvf deploy.tar --strip-components 1 | |
rm deploy.tar | |
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 | |
# Cleaning unused containers, images, networks | |
docker system prune --force | |
# Installing defend service for app | |
sudo cp -f /home/deploy/spread_wings_bot/infra/prod/spread_wings_bot_prod.service /etc/systemd/system/spread_wings_bot_prod.service | |
sudo systemctl daemon-reload | |
sudo systemctl restart spread_wings_bot_prod.service | |
# Applying initialization commands | |
sleep 7 | |
docker exec spread-wings-bot python manage.py migrate | |
docker exec spread-wings-bot python manage.py collectstatic --noinput |