Deploy using mina and Docker

#dev, #docker

tl;dr

WARNING: The config/deploy.rb listed here is based on a project I work on but it is also a PoC. Use it at your own risk.

Check this file: isbn-vue-pg/config/deploy.rb.

$ mina setup
$ mina deploy

And everything is set for you.


It is been a long time that all my development env is based on Docker. I am used to it and I like it a lot. Everything is so simple once you use Docker.

I started to deploy using mina and Docker in September of 2017, I always wanted to share my config/deploy.rb but because of some flaws (next topic), I didn’t.

But recently I was “challenged”, the talk was something like:

Why not using ansible/chef?

(me) I do everything using mina and Docker, including updating the Ruby version

But you still need to ssh and install Docker in the machine, don’t you? And then you need ansible/chef.

I thought about that a lot, but wait, mina setup setups what you need in the machine for you when it comes to directories and files, so, why not installing Docker? 🤔

Big list of flaws and not tested stuff

  • I have not tested rollback, reason: I’d rather create a revert commit, PR to master and deploy again;
  • I have not tested remote running rails console, just ssh and run docker exec and done;
  • I have deployed another project and the code is more DRYier than this because the other one also starts sidekiq;
  • I’m not compiling assets in the Rails project because, for my example, there is no asset to compile, the Rails app is just an API, but I am compiling Vue.js in other step;
  • It lacks zero-downtime deploy, once more for my example, I don’t need it;

Features

The only thing you need in the machine is Docker, but with this config/deploy.rb when you run mina setup it installs Docker for you.

Everything else is downloaded using Docker. And it is light because my Ruby image has everything my project needs.

The Ruby image is my “general purpose Ruby image” that is ready to run any Ruby project and to run the automated tests as well.

The Nodejs image is the standard Nodejs image. Lucky me 😉.

Instead of copying all the files of the app inside the Docker image, as everyone else that I saw does, I just bind the “current” path with the image, all the “mina way” to git clone and create the symlinks is the same.

Other features:

  • I’m using Docker volumes to install the bundle dependencies.
  • If you need to update the Ruby version just change the call from dmitryrck/ruby to the one you want.
  • For this project, I tested using Amazon EC2 (Ubuntu);
  • My project is a public repo in GitHub, you need to change the config/deploy.rb to git clone a private repo, nothing too much complex;

I don’t doubt there are other (better) ways to achieve the same, but my project was already using mina, so it made sense to just hack it to deploy using Docker. If you are doing something similar please share in the comments I’d love to hear about 😉.

P. S.: Another reason to use mina and Docker in this way is that I don’t have to publish an image in Docker hub or any private repo, worst-case scenario I just build in the server itself.