Search code examples
dockerdocker-composedevelopment-environmentrancher

Rancher development environment


I started to use rancher recently for a project. Within few days I set up a standard microservice architecture with 4 basic services (hosted on Digital Ocean), trying to make it as production ready as possible

Services:

  • Api Gateway
  • GraphQL Api
  • OAuth2 Server
  • Frontend

it also includes Loadbalancers, Health checks etc...

I'm amazed at how good it is, as such I heavily used all the features provided by rancher in my configs, for example, the DNS conventions <service>.<stack>, sidekicks, rancher-compose etc...

The above services lives in their own repository and they have their own Dockerfile , docker-compose.yml and rancher-compose.yml for production, so that they can be deployed independently.

Now that I proved myself that rancher will be my new "friend", I need a strategy to run the same application on my local environment and being able to develop my services, just like I would do with Vagrant.

I'm wondering what's the best approach to port an application that runs on rancher to a development environment.

I had some ideas on how to tackle this, however, none of them seemed to allow me to achieve it without re-configuring the whole services for development.

1 - Rancher on local machine

This is the first approach I took, install a rancher-server and a rancher-client locally and deploy the whole stack just like in production. It seemed the most logical idea to me. However, this wouldn't allow me to change the code of the services and being reflected into the containers live. Maybe using shared volumes might work but it looks trivial to me if you have any idea please let me know. For me, This solution is gone :(

2 - Docker compose

My second attempt was to use plainly docker compose and shared volumes, omitting load balancers and all the features of rancher :( However, this might work, I would need to change all the configurations of all my services where they point to a rancher specific DNS domain <service>.<stack> to use just <service> over the bridge network. But this means maintaining 2 different configurations for different environments, which is weird and not fun to do.

3 - Vagrant

As the second solution is already messy (double docker-compose and double configuration for the services) why not just re-create the whole environment in vagrant (without rancher features, maybe with ansible) where one nginx does reverse proxy and resolve requests between services. However, this require also quite a lot work and double effort again :(

Is there any other approach which will make rancher suitable for a development environment in a non-painfull way? How companies which rely on rancher or any other platform tools solved this issue?


Solution

  • Rancher on the local machine is a common pattern. If you run Rancher on a VM, or locally on a Linux box, when you launch your stacks the subtle change is that you add volumes to the host..

    services: myapp: volumes: - /Users/myhome/code:/src ...

    You could now use templating features in the compose files and the Rancher CLI. Something like:

    services: myapp: {{ if dev-local == "true"}} volumes: - /Users/blah:/src {{end}} ...

    Then you could have an answers file that just has dev-local="false"