I have a simple node application running on the EC2 instance, everything is working just fine and I want to integrate this application with CircleCI for the continuous deployment. I have been following this article where it says to SSH to the EC2 instances and then run your deployment commands.
I've created a basic
deploy.sh file in the EC2 instance, where I simply change the directory to project directory and then run
npm i and
pm2 delete all with
pm2 start server.js. Now before testing it out my circleCI I thought of checking if it's working in general or not, so
- When I run this deploy.sh file from within EC2 instance, it works fine and follows all the steps to install
node_modulesand then serving the application with
pm2correctly. So, no issues here.
- From my local machine when I tried to run the same deploy.sh with this command
ssh -i <my-pem-file> <ec2-user>@<ec2-ip> \ ./deploy.sh. it
echoesthe basic stuff but says
pm2: not found . The reason this is happening is because that deploy.sh file is being run in context of my local machine (or not?).
So how can I simply run this
deploy.sh file right after I SSH to my EC2 instance from circleCI, or If there is some better approach to do this all together.