0

I have a Elastic Load Balancer in AWS. I have my node.js code deployed in 3 instances and I'm using pm2 to update my code, but I need to do manually on this way:

  • Connect by ssh in each machine
  • Git pull on each machine
  • pm2 reload all on each machine

How can I do to update all the code in ALL machines when I do a new commit to the master or other branch (like production branch)?

Thanks.

2
  • 1
    Have you looked at the pm2 docs? There's a section for deployment Commented Sep 12, 2016 at 13:45
  • 1
    @Seth Your comment is the best answer ;) Commented Oct 15, 2016 at 21:36

4 Answers 4

1

You can just write a script in for example bash to solve this:

# This will run your local script update.sh on the remote 
ssh serverIp1 "bash -s" < ./update.sh 

Then in you local update.sh you can add code to git pull and reload:

# This code will run on the remote
git pull
# Update
# Other commands to run on remote host

You can also have a script that does all of this for all your machines:

ssh serverIp1 "bash -s" < ./update.sh
ssh serverIp2 "bash -s" < ./update.sh
ssh serverIp3 "bash -s" < ./update.sh

or event better:

for ip in serverIp1 serverIp2 serverIp3; do
    (ssh $ip "bash -s" < ./update.sh)
done
Sign up to request clarification or add additional context in comments.

Comments

1

An alternative is ElasticBeanstalk, especially if you are using a "pure" Node solution (not a lot of extra services on the instances). With beanstalk, you supply a git ref or ZIP file of your project, and it handles the deployment (starting up new instances, health checks, getting them on the load balance, removing old instances, etc.) In some ways it is an automated deployment version of what you have now, because you still will have EC2 instances, a Load Balancer, etc.

Comments

1

Use a tool like Jenkins (self-hosted) or Travis CI to run your builds and deployments. Many alternatives are available FYI, Jenkins and Travis are just some of the most popular.

Comments

0

Ok, thanks for your answers but I think the best option for me is AWS CodeDeploy.

I don't know why I did not find this before make the question...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.