Build and Deploy Server #27
Workflow file for this run
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: Build and Deploy Server | |
on: | |
push: | |
branches: ["main"] | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- run: 'echo "${{secrets.SERVER_DEPLOYMENT_KEY}}" | base64' | |
- uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
- run: npm ci --prefix server | |
- name: Copy server files to EC2 server | |
uses: burnett01/[email protected] | |
with: | |
switches: --verbose --human-readable --archive --delete | |
path: server/ | |
remote_user: ec2-user | |
remote_host: ec2-54-177-26-87.us-west-1.compute.amazonaws.com | |
remote_path: /home/www | |
remote_key: ${{ secrets.SERVER_DEPLOYMENT_KEY }} | |
- name: Execute commands on server | |
uses: appleboy/[email protected] | |
with: | |
username: ec2-user | |
host: ec2-54-177-26-87.us-west-1.compute.amazonaws.com | |
key: ${{ secrets.SERVER_DEPLOYMENT_KEY }} | |
script: | | |
echo "Checking if pm2 installed" | |
if [ ! "$(which pm2 2>/dev/null)" ]; then | |
echo "Not found. Installing pm2" | |
sudo npm i -g pm2 | |
fi | |
echo "Deleting node server if exists" | |
pm2 delete /home/www/src/app.js 2> /dev/null | |
echo "Debug info" | |
ls -a /home/www | |
echo "Starting node server" | |
port=4000 pm2 start /home/www/src/app.js |