Prebuilt docker images for CirceCI

CircleCI Images

CircleCI provides quite a few convenience images in order to speed up the build process. These are generally fairly robust images that will cover most cases. If you wanted to use the convenience image for elixir 1.12.2, you would specify it as follows:

  jobs:
    build:
      docker:
        - image: cimg/elixir:1.12.2
      steps:
        - checkout
        - run: mix --version
        - run: mix deps.get
        - run: mix test

Seems like you’re all set - elixir 1.12.2 is installed for free! That is until you realize that you are locked to the following:

  1. Ubuntu 18.04
  2. Elixir 1.12.2 OTP 22
  3. Erlang 24

The million dollar question is “What do you do if you require anything different?”

Enter prebuilt docker images

CircleCI will use any docker image file, which will allow you to specify exactly what you need. Now, before you fire up docker and start creating your own (I was just gearing up to do so), it turns out that the kind folks at Hex have prebuilt elixir images that span a wide variety of configurations. And it’s completely searchable using the following pattern:

${ELIXIR_VER}-erlang-${OTP_VER}-${OS_NAME}-${OS_VER}

So if you want elixir 1.12.2 OTP 24, with erlang 24.0.3 on ubuntu 20.04 (Focal Fossa) you would filter for:

1.12.2-erlang-24.0.3-ubuntu-focal (you don’t have to include the os version in the filter).

Sure enough, there’s an image!

1.12.2-erlang-24.0.3-ubuntu-focal-20210325

Using your prebuilt image

Ok, so you’ve saved yourself some time and found the image - now what?

It’s a fairly easy switch to use the hex image instead of the convenience image:

jobs:
  build:
    docker:
      - image: hexpm/elixir:1.12.2-erlang-24.0.3-ubuntu-focal-20210325
    steps:
      - checkout
      - run: mix --version
      - run: mix deps.get
      - run: mix test

Final notes

These images are bare. As in nothing beyond erlang and elixir. No sudo (you’re the root user). No curl, build-essentials, python, node or any other tools you may need. But they are quite simple to install in your config file:

      - run: mix test
      - run: apt-get install -y curl build-essentials # etc.

Also note that:

Tagged images are never changed, that means hexpm/erlang@22.0-alpine-3.11.2 will always target the tag OTP-22.0 and won’t update when OTP-22.0.1 is released.

Joe Sward

Code Monkey