Specifying docker image from .ruby-version file

I’m currently investigating what can be done with CircleCI 2.1. I would like to use a .ruby-version file to tell circleci which docker image to use in a executor. Here’s an excerpt of the my ideal circle.yml file:

      - image: circleci/ruby:{{ cat .ruby-version }}

Where the contents of .ruby-version are interpolated into the image name, and would effectively result in something like:

image: circleci/ruby:2.4.1

As far as I can tell, there’s no way to do with this right now. Does anyone know of a way I can achieve this type of thing (use the contents of a file to make up a portion of the name of the specified docker image)?

I would be surprised if you could use dynamic executors in that way. I haven’t tried the 2.1 features yet, but assuming this is a primary container, it presently needs to spin up just to read the YAML file, by which time it is too late to change the container.

What you could do though is to use Docker-in-Docker: pull a Ruby image of your choosing using Docker commands containing an env var for the version, add tests into it via a custom Dockerfile, build it, then run it. I do this using Docker Compose, and it is pretty solid in CircleCI 2.0.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.