try15 #16
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 DigitalOcean | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v3 | |
| - name: Set up SSH | |
| uses: webfactory/[email protected] | |
| with: | |
| ssh-private-key: ${{ secrets.DEPLOY_KEY }} | |
| - name: Install Bun | |
| run: | | |
| curl -fsSL https://bun.sh/install | bash | |
| echo "$HOME/.bun/bin" >> $GITHUB_PATH | |
| - name: Install dependencies | |
| run: bun install | |
| - name: Build project | |
| run: bun run build | |
| - name: Sync files to droplet | |
| run: | | |
| rsync -avz --delete --exclude='.git' --exclude='node_modules' --exclude='.env' \ | |
| -e "ssh -o StrictHostKeyChecking=no" ./ root@${{ secrets.DROPLET_IP }}:/root/your-app-directory | |
| - name: Run on droplet | |
| env: | |
| DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
| JWT_SECRET: ${{ secrets.JWT_SECRET }} | |
| run: | | |
| ssh -o StrictHostKeyChecking=no root@${{ secrets.DROPLET_IP }} << 'EOF' | |
| set -e | |
| cd /root/your-app-directory | |
| # Ensure system dependencies | |
| if ! command -v apt-get &> /dev/null; then | |
| echo "apt-get not found. Are you on a minimal OS?" | |
| exit 1 | |
| fi | |
| if ! command -v npm &> /dev/null; then | |
| apt-get update && apt-get install -y nodejs npm | |
| fi | |
| if ! command -v pm2 &> /dev/null; then | |
| npm install -g pm2 | |
| fi | |
| if ! command -v bun &> /dev/null; then | |
| curl -fsSL https://bun.sh/install | bash | |
| fi | |
| export PATH="/root/.bun/bin:$PATH" | |
| # Stop old process | |
| pm2 delete excalidraw || true | |
| # Start new process with working directory | |
| DATABASE_URL="${DATABASE_URL}" \ | |
| JWT_SECRET="${JWT_SECRET}" \ | |
| pm2 start "/root/.bun/bin/bun run start" \ | |
| --name excalidraw \ | |
| --cwd /root/your-app-directory | |
| pm2 save | |
| EOF |