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 Vultr | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Set up SSH | ||
uses: webfactory/[email protected] | ||
with: | ||
ssh-private-key: ${{ secrets.VULTR_SSH_PRIVATE_KEY }} | ||
- name: Verify SSH connection | ||
run: ssh -o StrictHostKeyChecking=no root@${{ secrets.VULTR_IP }} "echo 'SSH connection successful'" | ||
# Add a step to install dependencies and build the project | ||
- name: Install dependencies and build project | ||
run: | | ||
npm install | ||
npm run build | ||
# Git clone instead of SCP | ||
- name: Deploy code to Vultr | ||
run: ssh -o StrictHostKeyChecking=no root@${{ secrets.VULTR_IP }} "cd /root/deploy/happiness-backend && git pull || git clone https://github.com/YOUR_REPO/happiness-backend.git /root/deploy/happiness-backend" | ||
- name: Restart Docker container | ||
run: | | ||
ssh -o StrictHostKeyChecking=no root@${{ secrets.VULTR_IP }} " | ||
CONTAINER_ID=\$(docker ps -q -f name=happiness-backend); | ||
if [ ! -z \"\$CONTAINER_ID\" ]; then | ||
docker container stop \$CONTAINER_ID; | ||
fi; | ||
CONTAINER_ID=\$(docker ps -a -q -f name=happiness-backend); | ||
if [ ! -z \"\$CONTAINER_ID\" ]; then | ||
docker container rm \$CONTAINER_ID; | ||
fi; | ||
docker container run -d -p 80:3010 --name happiness-backend /root/deploy/happiness-backend | ||
" |