switch to yarn (#9) #4
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 Runner to DigitalOcean | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
name: Build and Deploy Node.js App | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "18" | |
- name: Configure SSH | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.STAGING_SSH_PRIVATE_KEY }}" > ~/.ssh/nodejs_do_key | |
chmod 600 ~/.ssh/nodejs_do_key | |
ssh-keyscan -H ${{ secrets.STAGING_DROPLET_IP }} >> ~/.ssh/known_hosts | |
- name: Install Dependencies and Build | |
run: | | |
npm install | |
npm run build | |
ls dist # Debug: Check if dist directory exists and its contents | |
# Create necessary directories first | |
- name: Create Remote Directories | |
run: | | |
ssh -i ~/.ssh/nodejs_do_key ${{ secrets.STAGING_DROPLET_USER }}@${{ secrets.STAGING_DROPLET_IP }} "mkdir -p ~/node-app/dist" | |
# Then copy files | |
- name: Copy Built Files to Droplet | |
run: | | |
scp -i ~/.ssh/nodejs_do_key -r dist/* ${{ secrets.STAGING_DROPLET_USER }}@${{ secrets.STAGING_DROPLET_IP }}:~/node-app/dist/ | |
scp -i ~/.ssh/nodejs_do_key package.json ${{ secrets.STAGING_DROPLET_USER }}@${{ secrets.STAGING_DROPLET_IP }}:~/node-app/ | |
scp -i ~/.ssh/nodejs_do_key package-lock.json ${{ secrets.STAGING_DROPLET_USER }}@${{ secrets.STAGING_DROPLET_IP }}:~/node-app/ | |
- name: Set Up .env File | |
run: | | |
ssh -i ~/.ssh/nodejs_do_key ${{ secrets.STAGING_DROPLET_USER }}@${{ secrets.STAGING_DROPLET_IP }} "echo '${{ secrets.STAGING_RUNNER_SECRET_FILE }}' > ~/node-app/.env" | |
- name: Install Dependencies and Start App | |
run: | | |
ssh -i ~/.ssh/nodejs_do_key ${{ secrets.STAGING_DROPLET_USER }}@${{ secrets.STAGING_DROPLET_IP }} << 'EOF' | |
cd ~/node-app | |
npm install --production | |
ls dist # Debug: Check if dist directory exists on server | |
if pm2 list | grep -q node-app; then | |
echo "Restarting existing app..." | |
pm2 restart node-app | |
else | |
echo "Starting new app..." | |
pm2 start dist/server.js --name node-app | |
fi | |
pm2 save | |
EOF |