Gnefil is deploying blog to production server #36
This file contains hidden or 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 production server | |
| run-name: ${{ github.actor }} is deploying blog to production server | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| workflow_dispatch: | |
| jobs: | |
| Deploy: | |
| runs-on: ubuntu-latest | |
| env: | |
| ssh-prefix: ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no ubuntu@13.40.196.20 | |
| scp-prefix: scp -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no -r | |
| temp-dir: /home/ubuntu/blog | |
| prod-dir: /var/www/html/blog | |
| esc-prod-dir: \/var\/www\/html\/blog | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Clean install dependencies | |
| run: npm ci | |
| - name: Build | |
| run: npm run build | |
| - name: Deploy to remote server | |
| run: | | |
| mkdir -p ~/.ssh/ | |
| echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| ssh-keyscan 13.40.196.20 >> ~/.ssh/known_hosts | |
| mv ./public ./blog | |
| ${{ env.ssh-prefix }} rm -rf ${{ env.temp-dir }} | |
| ${{ env.scp-prefix }} ./blog ubuntu@13.40.196.20:${{ env.temp-dir }} | |
| - name: Check content existence | |
| run: ${{ env.ssh-prefix }} 'if [ -d ${{ env.temp-dir }} ]; then echo "temporal folder is not empty"; else echo "temporal folder is empty"; fi' | |
| - name: Update production folder | |
| run: | | |
| ${{ env.ssh-prefix }} sudo rm -rf ${{ env.prod-dir }} | |
| ${{ env.ssh-prefix }} sudo mv ${{ env.temp-dir }} ${{ env.prod-dir }} | |