Use created image in 2 jobs

I have my own docker images which run by docker-compose
Also I have 2 jobs for now and each of them build the same application to run tests.
I have the same code:

    machine: true # Use a Linux VM instead of docker environment
    working_directory: ~/bone
    steps:
    - checkout
    - run: docker network create bone-net
    - run: docker-compose up -d
    - run: docker exec bone yarn install --no-cache

Do I can use one build result in many jobs?

version: 2
jobs:
  build:
    machine: true # Use a Linux VM instead of docker environment
    working_directory: ~/bone
    steps:
    - checkout
    - run: docker network create bone-net
    - run: docker-compose up -d
    - run: docker exec bone yarn install --no-cache
    - run:
        name: Test BONE Frontend
        command: docker exec bone yarn lint:client && docker exec bone yarn coverage:client --runInBand
        no_output_timeout: 30m
    - run:
        name: Test BONE Backend
        command: docker exec bone yarn lint:backend && docker exec bone yarn coverage:backend --runInBand
        no_output_timeout: 30m
    - store_artifacts:
        path: docs/bone/1.0.0/
        prefix: coverage
    - store_artifacts:
        path: docs/bone/1.0.0/clover.xml
        prefix: tests

  integration_tests:
    machine: true # Use a Linux VM instead of docker environment
    working_directory: ~/bone
    steps:
    - checkout
    - run: docker network create bone-net
    - run: docker-compose up -d
    - run: docker exec bone yarn install --no-cache
    - run:
        name: Test BONE integration db tests
        command: docker exec bone yarn db
        no_output_timeout: 30m

  workflows:
    version: 2
    unit_and_integration_tests:
      jobs:
        - build
        - integration_tests

When you say a “created image”, do you mean a Docker image? I cannot see a docker build in there.

Or do you mean just a built app in a local folder?

Yes creating an image
Does docker-compose up command make build, isn’t it?

Aha, yes, you’re right.

There are two main ways to deal with this:

  • Push the image to an external Docker registry, and then pull it in the second job
  • Save the image in a workspace, and then load it in the second job

I would probably try the second one to start with, as it is not subject to a slow network speed. But for small images you may find that both approaches achieve some speed-up.

1 Like

In addition to what Jon said, we have a couple feature requests that might be what you are looking for :slight_smile:
https://ideas.circleci.com/ideas/CCI-I-614 and https://ideas.circleci.com/ideas/CCI-I-130