I'm thinking about how to best setup my SaaS application for automatic scaling and have reached a step I'm unsure of how to tackle. To properly describe the problem, I better start by explaining how I see this whole process going down:
First of, I'll host the main site on a separate VPS that handles signups and has all the info on the actual app servers, their load and user count and so on. I'm thinking that a cron job or something will check so that I always have space for N more users, and if I go below that number, start the process of setting up a new VPS instance automatically.
I've decided to use DigitalOcean and their API to set up droplets, which I'll then connect to ServerPilot by sending in the ServerPilot setup script as CloudInit user meta data when creating the droplet on DigitalOcean.
I can then use a combination of the ServerPilot and DigitalOCean API's to check on the servers, create "apps", db's, connect domains and so on.
Now to the tricky part. I need to somehow get Git repositories set up on the newly created server without manually SSH:ing to it.
My options here seems limited. I can't really set up some kind of normal web-api from the start to manage git and app-deployments, since ServerPilot hasn't done it's thing when CloudInit runs.
A possibility would be to include a custom script in the CloudInit that serves as a rudimentary web-API to set up and deploy the PHP apps. This is when I started looking at Sinatra for Ruby or Flask/Bottle for python. If I understand it correctly, they can provide an API endpoint without nginx/apache being installed yet. Or perhaps am I totally off here?
Before going any further, I'd like input on my ideas so far.
Does this plan sound reasonable?
Is there better alternatives to ServerPilot for this kind of use, where I rather stay away from config files myself?
Would it be better to just make my own custom image file for new droplets and not use ServerPilot at all, having it include a "manager"-app API in normal PHP for setting up the user apps?
I kind of like the idea of letting ServerPilot handle the setup though, as I'm not primarily a server guy. Any input is appreciated.