0

I'm looking for recommandations about the best way to deploy updated versions of a Node.JS application when using multiple instances spawned by auto-scaling.

My code is hosted on GitHub, usual deployment was made using GitHub Actions, pushing the updates and triggering install/db updates after CI on specific hosts.

Now that my instances are "variables", I was thinking of some kind of polling at a regular interval, but this solution isn't appropriate because it breaks the usual CI process.

Did you have any good practices to setup all this properly ?

Johan
  • 277
  • 4
  • 17

2 Answers2

1

You can add the script in user-data section to update or perform any init process.

Your instance should be able to pull code from Github and the init script will perform the necessary operation. Note: The user-data script will only execute once new instance spawned from the auto-scaling group.

For example

#!/bin/bash
cd /app;
git pull;
npm install;
pm2 start myapp.js

enter image description here

Adiii
  • 54,482
  • 7
  • 145
  • 148
1

You could consider using CodePipepline (CP) or at least CodeDeploy (CD). They seem as good fit for your use-case of automated deployments from github.

CP integrates with GitHub so you could set it up to automatically detect changes in your repo. Depending on the specific of your application you could have CodeBuild (CB), or not, and the CD to deploy to your instances.

CD integrates with Auto Scaling Group, thuss once setup, there shouldn't be a problem using it in the group.

The initial setup probably can be troublesome when doing it first time. But once done, you will have benefits of automatic deployments of your application, rollbacks, notifications and more.

Marcin
  • 215,873
  • 14
  • 235
  • 294