In this article, I want to share how I manage to run 8 side-projects (mostly written in Rails) from a single server for 12 eur / mo.
First of all, why side-projects? Isn’t all this applicable to webdev in general?
Of cause, it is. At least partially I guess. But things are a bit different when you have a team of 50 devs vs. 5 devs vs. just you.
I’m going to focus on that last extreme case, i.e. how to manage multiple side-projects in a most efficient way when there’s just you with not too much spare time (still have your day job) and limited money to spend (otherwise your wife won’t be happy). So you want to spend this time and money as efficiently as possible.
Your side-project will gonna have to be stored somewhere (privately). Even if you are the single developer, you may still want a Git hosting to sync code with the server.
Getting a Server
Before you start, you need a server. There are multiple choices available on the market for getting a VM. For example, Amazon EC2, and Google Cloud Compute. But in my experience, it’s better to not go with behemoth cloud platforms, as they quickly become a money drain. A better option would be to use Digital Ocean, or Linode. The pricing there is much more predictable, and they don’t try to vendor-lock you.
But my favorite provider and this is what I use now is Scaleway. It is very good for value per money. See, you can get a bare-metal server in Amsterdam with 4 cores, 8 Gb of memory for 12 EUR / mo .
Now that you have a server how do you actually run your projects on it? Configuring the server for each particular project is quite tricky, and supporting / updating stuff is even more time-consuming.
The solution is Docker.
All of my side-projects located on a single Ubuntu server and each of them is running in a docker container. Every container exposes a custom port and I have a globally installed NGinx that dispatches the requests to Docker containers accordingly.
The advantage of this approach is that you can serve multiple projects from one server. For example, I have 8 projects (most of those are in Rails) + the databases. And all of them are running on a single server for 12 eur / mo without interfering with each other. The lightweight Docker containers make it happen.
Now that I look at htop output, it looks as if I only use 4 Gb or RAM out of 8. Which means there’s still a room for more projects.
So let’s say I need to deploy my new project. Here’s what I do.
1. create a dockerfile
RUN apt-get install -yqq build-essential libpq-dev apt-transport-https chrpath libssl-dev libxft-dev
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get install -y nodejs
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install yarn --yes
CMD ["rails", "s", "-b", "0.0.0.0"]
By the way, if you’re into Rails here’s a very good book on Docker.
2. docker-compose file
If you’re new to Docker and all this seems a bit complex, no worries. I will do a separate article on docker configuration with a detailed instruction very soon.
Now you can ssh into your server and run your project with
docker-compose up -d. You can even scale it with
docker-compose up -d --scale web=3
3. Configuring nginx
Now that the project is running on the server, we need to make it publicly available by configuring Nginx.
We need to create a new file
Then, simply reload the Nginx config.
I hope by that time you have at least an overview of how my setup works. In the next articles, I’m planning to elaborate on many of the topics we talked about here including Docker and Nginx setup.
I’d be happy to answer any questions (you can write to me in Twitter DM)