Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker as the effective Rails development environment

[UPDATE]

Unfortunately, dear colleagues, I gave up on docker for now. Main factors:

  • Poor shared volume performance (there are some workarounds using additional tools, but it seems more of a hack). This is not an issue for those fine folks that use Linux, though!
  • I have underrated some upfront work, which is required to make remote runtimes play nicely with editors/IDEs. Things like linting assume a local runtime out of the box and it seems the most widespread solution is a myriad of bash wrapper scripts to delegate execution to a docker container.

Also we hired two DevOps guys, who have quite a bit of docker experience, if they will come up, how to (painlessly!) introduce docker in our company for both hosting and development, I will be happy to revise this topic.


[OLD POST]

As a new version utilising native OSX hypervisor is now available, I've decided to try pushing all my Ruby/Rails/JS development to the docker containers. I've played quite a bit on a fresh El Capitan installation, by trying to dockerize a few private gems we have and our monolith Rails application.

There are a few questions, I was hoping our community may help to solve.

The goal - everything works and host has only iTerm, git, Sublime, SourceTree and Docker installed (nothing is carved in stone, if some additional dependency(-ies) may improve/make the workflow significantly easier, I will be happy to review the options)

Requirements

  • There are quite a few services (EngineYard, ElastiBeanstalk, Github etc) that require my keys to function correctly, I should be able to reuse the ones that are on my host machine.
  • Reusing installed RubyGems across all Ruby app containers would be nice. Basically docker container/docker-compose file is setup in a way that it mounts the same directory that will be a GEM_PATH, bundler in each container will install gems there. Application bundler should take care of loading the right versions.
  • I should be able to debug code easily - putting breakpoints and interacting with debugger as it would be running locally
  • It should support TDD cycle - I change file, it's caught by guard process in the container and related tests are executed
  • When executing Cucumber/Selenium tests I should be able to see what's happening in the browsers. (As I understand the options are - connecting through VNC to virtual frame buffer or running X server locally. I'd prefer options that involve less dependencies on the host side).

Questions

  • Dockerizing existing apps is relatively easy these days, how do you, good people, handle creation/bootstrapping new projects? Common dev container that has usual dependencies?
  • Is it possible to setup the things the way that container "keeps running" more or less like a VM? (This may solve lots of my requirements - running guard, easier debugging, launching arbitrary processes in the same run)
  • I intend to use docker to pack our application for CI purposes. This means that for different environments, there might be a slightly different dependencies, also mounted volumes will differ (probably container for CI won't have those). Should it be solved as different config in docker-compose.yml (volumes) or defined inside a different docker file that inherits from the base one ?

Other thoughts

I am also fine trying out commercial or none-commercial tool, that wraps/bundles the described tooling. So far I've found a thing called http://wercker.com), the thing I don't like about it, it seems like it requires you to setup dev env anyways, which kill the purpose of the whole endeavour.

Feel free to down vote this question if it was posted before and answered clearly. On the other hand I would be happy if this thread will produce guides, links, suggestions to get it done smoothly, I am pretty sure this interests quite a few devs these days.

like image 594
Edgars Jekabsons Avatar asked Jul 05 '16 12:07

Edgars Jekabsons


People also ask

Should Docker use for development environment?

Docker is great at setting up a local development environment because it easily adds the running process without duplicating the virtualized resource. Second, it's more modular. Docker makes it easy to run multiple versions or instances of the same program without configuration headaches and port collisions.

What is the benefit of developing using Docker?

Docker is a containerization platform that is free and open source. It allows developers to package programs into containers, which are standardized executable components that combine application source code with the OS libraries and dependencies needed to run that code in any environment.

What is Docker in Ruby on Rails?

Docker run starts a new container and runs a program inside: -it : attaches your terminal process with the container. -v $PWD:/opt/app : binds your host machine current directory to the container, so files created inside are visible in your machine.

What is a benefit for a developer using Docker compatibility and maintainability?

Compatibility and Maintainability Parity, in terms of Docker, means that your images run the same no matter which server or whose laptop they are running on. For your developers, this means less time spent setting up environments, debugging environment-specific issues, and a more portable and easy-to-set-up codebase.


1 Answers

Consider orats (opinionated rails application templates):

The goal is to provide you an excellent base application that you can use on your next Rails project.

And:

It also happens to use Docker so that your app can be ran on any major platform -- even without needing Ruby installed.


To some of your other requirements:

  • my keys ... I should be able to reuse the ones that are on my host machine

    Specify keys in your docker-compose.yml but omit the value.

  • putting breakpoints and interacting with debugger

    When starting a service, instead of docker-compose up, use docker-compose run --service-ports. This will allow e.g. binding.pry to work.

  • When executing Cucumber/Selenium tests I should be able to see what's happening in the browsers.

    This is tricky. For a workaround consider using save_screenshot, and (the important part) save it to a directory which is mounted to a volume on the Docker host. Open that directory on the host and you'll be able to see an updating screenshot.

like image 155
davetapley Avatar answered Oct 20 '22 02:10

davetapley