Search code examples
springmavencirclecicircleci-2.0

How to run docker in Ciricle CI orbs?


CircleCI introduces orb in 2.1, I am trying to add Circle Ci config my sample project.

But in my testing codes, I have used test containers to simplify the dependent config of my integration tests.

When committing my codes, the Circle CI running is failed.

org.testcontainers.containers.ContainerLaunchException: Container startup failed
Caused by: org.testcontainers.containers.ContainerFetchException: Can't get Docker image: RemoteDockerImage(imageName=mongo:4.0.10, imagePullPolicy=DefaultPullPolicy())
Caused by: java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration

My Circle CI config.

version: 2.1

orbs:
  maven: circleci/[email protected]
  codecov: codecov/[email protected]

jobs:
  codecov:
    machine:
      image: ubuntu-1604:201903-01
    steps:
       - codecov/upload

workflows:
  build:
    jobs:
      - maven/test:
          command: "-q verify -Pcoverage"
      - codecov:
          requires:
            - maven/test

Solution

  • Got it run myself.

    The maven orb provides reusable jobs and commands, but by default, it used a JDK executor, does not provide a Docker runtime.

    My solution is giving up the reusable job, and reuse some commands from the maven orb in your own jobs.

    version: 2.1
    
    orbs:
      maven: circleci/[email protected]
      codecov: codecov/[email protected]
    executors:
      docker-mongo:
        docker:
          - image: circleci/openjdk:14-jdk-buster
          - image: circleci/mongo:latest
    jobs:
      build:
        executor: docker-mongo
        steps:
          - checkout
          - maven/with_cache:
              steps:
                - run: mvn -q test verify -Pcoverage
          - maven/process_test_results
          - codecov/upload:
              when: on_success
    workflows:
      build:
        jobs:
          - build