Hacking Hours
We have a lot of technologies today. Well, they are so many that when we think to start a pet project we are immediately overwhelmed with an infinite number of technical solutions we can apply to achieve our initial end. You want a simple page to display your cv. Do I need it responsive? Can I do it as a bunch of html pages or do I use some backend? Do I use MVC? Do i use MVC in the client with frameworks like angular? Do I need some kind of automation? And how do I distribute my pet project? Just a git repository? Do I add some spicy stuff and prepare it also for some packaging manager? Which language? Java, maven and nexus? Well maybe something more interpreted? Like python, setuptools and pip? But how can I deploy and test without any fuss and without polluting my sacred laptop while developing? Good old virtual box, good friend vagrant stuff, or new cutting edge linux containers with docker recipes? All this questions to just start a pet project. Well this is a pet project so, honestly, all the purpose is to think in whatever we want.
My pet project started as a rudimentary web tool to automate some things in my home, and the first idea was to play videos on my RaspberryPI with omxplayer, and hence the name of the project. Initially I started by developing the code directly on my RaspberryPI. I must confess that it is not very good. I need to do all the programming through ssh connection and using vim as a code editor and I had plans to explore a little more about Atom (and I know that Atom kind of sucks as a reliable editor) so if need to change the setup. At the same time I didn't want to fill my laptop, which by the way is the one I use at work, with a bunch of python libraries just to develop a little pet project. So what to do? Some years ago I believe that the childish virtualbox interface with a virtual machine with a second version of my linux mint would be a solution. Today that seems ridiculous and my first thought was to create a vagrant box with the /vagrant directory mapped into my project root folder and, in this way develop In my machine and run in the vagrant virtual machine. This seems attractive at first but then I remember that I would need to prepare the vm to run the project. I would need to install python libraries. For me this is not a big problem, it would be a one time job. The problem here is that if I want to distribute the running environment I would need to share my vm image or write down in an md file the instructions needed, and if someone else give a try to the project that else would need to replicate all the setup I already did. Well not very attractive. Then I remember that I could use containers instead of vms and the features of docker and docker-compose to create a specific running environment for this pet project.
First the Dockerfile with all the setup needed to run the flask application in a centos linux container. I need, also, to create the script that would start the application
python /var/app/omxclient/omxclient/main.py
tail -f /var/log/*log
and, then, the funny part. On the docker-compose yml file I setup the container and the mapping for my host folder where I had the project.
omxclient:
build: ./omxclient
ports:
- "5000"
volumes:
- /home/vitorfernandes/IdeaProjects\
/balhau/omxpiclient:/var/app/omxclient
-/media/samba/hdc1/MediaLibrary\
/downloads:/media/samba/hdc1\
/MediaLibrary/downloads
This way I just need to run docker-compose up to have my project running in an isolated environment. Another nice feature is since flask will reload files that had change and since the mapping will propagate these changes into the container when I save a change it will also reflect in the running application which is very neat indeed.