Build multiple images

Trying to create 1 job that will use the same executor, but build and push multiple images based on different dockerfiles located in different directories within my repo.

I’m using the GCR orb, and i’ve tried using matrices with the following config:

jobs:
  build-and-push:
    executor: gcp-gcr/default
    parameters:
      path:
        type:string
    steps:
      - checkout
      - gcp-gcr/gcr-auth
      - gcp-gcr/build-image:
          image: jre-test
          no_output_timeout: 20m
          registry-url: gcr.io/my-gcr/
          path: path
      - gcp-gcr/push-image:
          digest-path: /tmp/digest.txt
          image:j re-test
          registry-url: gcr.io/my-gcr/
      - run:
          command: |
            echo "Digest is: $(</tmp/digest.txt)"
      
orbs:
  gcp-gcr: circleci/gcp-gcr@0.13.0
version: 2.1
workflows:
  commit:
    jobs:
      - build-and-push-<< matrix.path >>
        matrix:
          parameters:
            path: [jre]

My repo is structured with a jre directory, and inside that is a Dockerfile.

I’m just trying to get a single image to work first, and then i’ll add more directories/images afterwords. I was going to add multiple Dockerfiles inside the jre directory. For different operating systems.

The goal here is to schedule the job to run regularly, and have it build a new version of the Dockerfiles and upload it to our registry.

I’d like to use native circle yml, and not write a build script that parses the directories and does all the commands that the orb is doing. Tho i’m beginning to think the gcp-gcr orb is holding me back a bit.

Currently the above job fails with "

matrix:

 in 'string', line 30, column 15:

mapping values are not allowed here

Unable to parse YAML

Unless I’m misunderstanding something about your use case I don’t think matrices is the feature you should be using for this. A regular parameterized job would let you write one job definition and then run it with multiple configurations in parallel.

Your current config also isn’t a valid CCI config file.

It’s also worth noting that the gcp-gcr orb already has a parameterized job that does what you seem to be attempting to do.

version: 2.1

orbs:
  gcp-gcr: circleci/gcp-gcr@0.13.0

workflows:
  commit:
    jobs:
      - gcp-gcr/build-and-push-image:
          context: jre
          image: my-image-jre
          registry-url: us.gcr.io
      - gcp-gcr/build-and-push-image:
          context: another-directory
          image: my-image-another-directory
          registry-url: us.gcr.io
      - gcp-gcr/build-and-push-image:
          context: and-another-directory
          image: my-image-and-another-directory
          registry-url: us.gcr.io

should be most of the way there.

Let me know if I’m misunderstanding something, and good luck! :slight_smile: