Concurrent Docker builds while running tests

I’m moving our build environment away from Gitlab CI to CircleCI and one thing I’m running into is running our tests at the same time as we’re building our Docker container.

Our Docker container takes a good 10min or so to build and running the tests can be done independently of it (I currently have CircleCI running them as a standard rails app outside of our own docker container). Is there a way to build our container while we’re also running rspec with the default Rails CircleCI stack?

1 Like

I would love to see this as well. We’re migrating from another CI service as well and this would effectively double continuous deployment time. In fact, I’d go so far as to say it would convince us to add more containers :slight_smile:


I had an idea (one I plan on trying); one could theoretically create a “test” that runs the docker build/push. When used in conjunction with some of the advanced libraries/harneses (recommended by CircleCI) to give more perspective about long-running specs (for example, rspec_junit_formatter) the long running docker build would be secluded to it’s own container while the rest of your specs were run in the other container. The first pass might take a while before CircleCI learns that one spec in particular takes the longest :thumbsup:

EDIT #2:

require 'spec_helper'

class Docker

    system('docker build --rm=false -t $CIRCLE_PROJECT_REPONAME:$CIRCLE_SHA1 . | cat')


describe Docker do
  it 'builds' do
    if ENV['CIRCLECI']
      expect( be true
DOCKER_LOGIN=$(aws ecr get-login --region us-west-2)
ECR=$(echo $DOCKER_LOGIN | sed 's|.*https://||')