Deploy to VM #12
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 VM | |
on: | |
workflow_dispatch: | |
workflow_run: | |
workflows: ["Docker Build and Push"] | |
types: [completed] | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup SSH Key | |
run: | | |
echo "${{ secrets.VM_SSH_PRIVATE_KEY }}" > ssh_key | |
chmod 600 ssh_key | |
- name: Debug SSH Connection | |
run: | | |
ssh -o StrictHostKeyChecking=no -i ssh_key ${{ secrets.VM_USER }}@${{ secrets.VM_HOST }} "echo 'SSH Connection Successful!'" | |
- name: Deploy to VM | |
run: | | |
ssh -o StrictHostKeyChecking=no -i ssh_key ${{ secrets.VM_USER }}@${{ secrets.VM_HOST }} << 'EOF' | |
echo "Login SSH berhasil!" | |
echo ${{ secrets.DOCKER_PASSWORD }} | docker login --username ${{ secrets.DOCKER_USERNAME }} --password-stdin | |
docker pull ${{ secrets.DOCKER_USERNAME }}/whatsapp-blast:latest | |
docker stop whatsapp-blast || true | |
docker rm whatsapp-blast || true | |
docker run -d --name whatsapp-blast --restart unless-stopped \ | |
--env-file /home/${{ secrets.VM_USER }}/whatsapp-blast/.env \ | |
-v /home/${{ secrets.VM_USER }}/whatsapp-blast/sessions:/app/sessions \ | |
-p 3000:3000 ${{ secrets.DOCKER_USERNAME }}/whatsapp-blast:latest | |
EOF |