Rebuilding the Sonata Project Demo
It’s not common knowledge but I would like to share with you all that ekino is the main sponsor of the Sonata project. We, ekino are fans of Open Source solutions, and contributing back is important to us.
Then, thanks to your help, the demo has been around for a few years now and we were having some complains about non functional demo so far. As a demo, we try to provide a full experience, you can change credentials, delete pages and … even delete users . So two simultaneous users might just have a wrong experience.
Therefore, we decided to rework the demo using a trending stack: docker and golang, and provide a demo that lasts 10minutes for every tester, so no failing demos anymore.
The first step of this journey was to build a fully functional docker image with the sonata demo: nginx, mysql, php and ready to use fixture. Of course this does not respect docker spirit, one process per container, but context matters first! With this image we can start the demo in a few seconds.
The next step was about creating a dedicated application to start the container on demand. This controller starts and stops containers using the Docker api. The controller has been developed with Go, in order to have a very small footprint and quick deployment on the production server.
The controller is started inside its own docker container, as the controller interacts with docker we need to provide the docker’s socket. At this point we have the controller and the demo, still there is no way to expose the running demos to the outside world. FYI, the controller binds internal port to the host loopback ip (127.0.0.1) to avoid exposing random ports and only have the http port open.
The final step was about adding a reverse proxy (nginx) to expose the internal ports. Each demo is using it’s own subdomain (http://jqaytf.demo.sonata-project.org), a wild card DNS has been setup to point to the host machine. The controller generates a new nginx configuration file, the file is mounted when the controller container is started. And nginx is restarted by a shell script handled by systemd, the shell script detects any changes in the configuration and graceful restart nginx.
The complete workflow
Le’ts put some numbers
- The demo image is 1.1GB.
- The controller image is about 6MB (thanks to golang and its static compilation).
- 1200 demos has been started in 10 days.
- The host load average is very low, thanks to PHP asking host resources only when a user navigates on the demo.
- The host is a Xeon 2 x E5504 with 16GO of Ram (also running the SonataCI server – another story)
Feel free to enjoy the controller and the demo at http://demo.sonata-project.org