David Karlsson
David Karlsson

Reputation: 9696

Use Concourse's docker resource to fetch containers to be used in a docker compose

Can one use concourse's docker resource to fetch containers to be used in a docker compose in a task? Currently I am just fetching the containers for my integration tests from my private docker registry, but doing this the connections/resources does not show up in the concourse UI. Any ideas?

Here is my task currently:

---
platform: linux
inputs:
- name: devops-repo
- name:client-repo
params:
  RUNNER_IMG:
  CLIENT_IMG:
  SERVER_IMG:
run:
  path: sh
  args:
  - -exc
  - |
    # "E2E testing:"
      - |
        # Export map the parameters to the dockerfile env.
        export docker-registry-protractor=${RUNNER_IMG}
        export docker-registry-client-dist=${CLIENT_IMG}
        export docker-registry-server-dist=${SERVER_IMG}

        export HOME=/protractor
        # Move to the Protractor test project folder
        mkdir $HOME
        # Get the docker compose file:
        cp devops-repo/my-pipeline/templates/e2e/docker-compose.yml $HOME/docker-compose.yml
        # Get the tests:
        cp client-repo/test/e2e/** $HOME
        cd $HOME

        # https://github.com/concourse/concourse/issues/324

        # Spin up the stack as described in docker-compose:
        docker daemon &
        docker-compose up

The Dockerfile use containers that are being constructed and uploaded to a private docker registry in the previous step of the pipeline.

Upvotes: 2

Views: 1070

Answers (1)

phillbaker
phillbaker

Reputation: 1548

This repo has a good walk through about how to run docker compose in docker in concourse - what you end up doing is using a docker image with docker compose pre-installed, which then loads other images. Using concourse to pre-fetch these images and then cache them locally does help performance.

One trick is that it's actually easier to put the docker compose file in the fetched code repository, not in the concourse config.

The abbreviated concourse yml:

  - name: integration
    plan:
      - aggregate:
        - get: code-from-git-resource
          params: {depth: 1}
          passed: [unit-tests]
          trigger: true
        - get: redis-docker-image
          params: {save: true}
        - get: busybox-docker-image
          params: {save: true}
      - task: Run integration tests
        privileged: true
        config:
          platform: linux
          image_resource:
            type: docker-image
            source:
              repository: amidos/dcind
          inputs:
            - name: code-from-git-resource
            - name: redis-docker-image
            - name: busybox-docker-image
          run:
            path: sh
            args:
              - -exc
              - |
                source /docker-lib.sh
                start_docker

                # Strictly speaking, preloading of images is not required.
                # However you might want to do it for a couple of reasons:
                # - If the image is from a private repository, it is much easier to let concourse pull it,
                #   and then pass it through to the task.
                # - When the image is passed to the task, Concourse can often get the image from its cache.
                docker load -i redis-docker-image/image
                docker tag "$(cat redis-docker-image/image-id)" "$(cat redis-docker-image/repository):$(cat redis-docker-image/tag)"

                docker load -i busybox-docker-image/image
                docker tag "$(cat busybox-docker-image/image-id)" "$(cat busybox-docker-image/repository):$(cat busybox-docker-image/tag)"

                # Run the tests container and its dependencies.
                docker-compose -f code-from-git-resource/example/integration.yml run tests

Upvotes: 3

Related Questions