Skip to content

Deploy Backend API

Deploy Backend API #36

name: Deploy Backend API
on:
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Tailscale
uses: tailscale/github-action@v3
with:
authkey: ${{ secrets.TAILSCALE_AUTHKEY }}
tags: tag:github-actions
- name: Setup SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.HOST_IP }} >> ~/.ssh/known_hosts
- name: Connect via SSH and run script
run: |
ssh -i ~/.ssh/id_rsa ${{ secrets.SSH_USER }}@${{ secrets.HOST_IP }} << 'EOF'
set -e
echo "Connected successfully to Server"
cd /opt/fakeoverflow/
sh deploy.sh
echo "Deployment completed successfully"
EOF
- name: Cleanup
if: always()
run: |
rm -f ~/.ssh/id_rsa