fix: deploy on master branch #22
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 to DigitalOcean | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup SSH and known hosts | |
uses: webfactory/ssh-agent@v0.5.3 | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Add DigitalOcean droplet to known_hosts | |
run: ssh-keyscan ${{ secrets.DROPLET_IP }} >> ~/.ssh/known_hosts | |
- name: Copy project files to the server | |
run: rsync -avz --exclude '/node_modules/' --exclude '/.git/' ./ root@${{ secrets.DROPLET_IP }}:/root/abibliadigital/ | |
- name: Build container | |
run: ssh root@${{ secrets.DROPLET_IP }} "cd /root/abibliadigital/ && docker-compose up -d --build" | |
- name: Environment setup | |
run: | | |
ssh root@${{ secrets.DROPLET_IP }} "echo 'MONGODB_URI=${{ secrets.MONGODB_URI }}' >> /root/abibliadigital/.env" | |
ssh root@${{ secrets.DROPLET_IP }} "echo 'SECRET_KEY=${{ secrets.SECRET_KEY }}' >> /root/abibliadigital/.env" | |
ssh root@${{ secrets.DROPLET_IP }} "echo 'SENDGRID_KEY=${{ secrets.SENDGRID_KEY }}' >> /root/abibliadigital/.env" | |
- name: Restart the application | |
run: ssh root@${{ secrets.DROPLET_IP }} "cd /root/abibliadigital/ && docker-compose down && docker-compose up -d" |