Push docker image to multiple repos


#1

Hello,

I have been using consourse for about a month now, everything seems to work out great.

I have a job that builds the docker image and I need to push it to multiple ECR repos. What would be the best approach to do that? So far I created separate resources for each repo but it seems that I cannot push without specifying build: parameter. Is there a way to just push the image without building it?

Thanks


#2

Hi Dan,

One solution to this problem is to push to on main ECR repo first, and then to spread that image to the rest of the ECR repos that it needs to go to. To accomplish this in one pipeline, you would:

  1. define all the image resources in one pipeline.
  2. arbitrarily pick the the “main” repo to build and push to
  3. define the job in such a way that the “secondary” repos come after the main one in the build plan
  4. when you define those secondary put steps, add the cache_from parameter to the definition. This will make docker load the image first before attempting to build it. This should skip the compile stage and simply push the image into the repo

An example of this is kind of job plan is below.

jobs:
- name: build-multiple-images
  plan:
    - aggregate:
      - get: image-git
      - get: image-version
    - put: main-image
      params:
        build: image-git/Dockerfile
        tag: image-version/version
      get_params:
        save: true # NOTE: this will save the image resource
    - put: secondary-image
      params:
        build: image-git/Dockerfile
        cache_from:
          - main-image # NOTE: this will used saved image on disk
        tag: image-version/version
    

#3

Thanks for this reply. I tried your approach and it seems to work with simple docker builds but not the multi-stage builds. When I had a single stage dockerfile it did build the image in the first “put” step and then reused all layers in second put. However, with multi-stage build it only reused few layers but most of them it built again.

Here’s what I tried and it seems to work:

- put: main-docker-image
  params:
    build: build_output/_docker_build
    tag: build_output/_docker_build/tag.txt
  get_params: {rootfs: true}
- put: second-docker-image
  params:
    import_file: main-docker-image/rootfs.tar
    tag: build_output/_docker_build/tag.txt
  get_params: {skip_download: true}

#4
  • put: main-docker-image
    params:
    build: build_output/_docker_build
    tag: build_output/_docker_build/tag.txt
    get_params:
    rootfs: true

  • put: second-docker-image
    params:
    import_file: main-docker-image/rootfs.tar
    tag: build_output/_docker_build/tag.txt
    get_params: {skip_download: true}