<p>I'm trying to configure a <code>gitlab-ci.yml</code> file to automatically build two Docker images. I've seen it being done with docker-compose, but in my case I don't want to use docker-compose.</p>
<p>The <code>docker-compose.yml</code> configuration that I've seen is something like this:</p>
<pre class="lang-yaml prettyprint-override"><code>version: '3'

services:
  vcxagency-base:
    build:
      context: https://github.com/AbsaOSS/vcxagencynode.git#master
      dockerfile: ./vcxagency-base/vcxagency-base.Dockerfile
    image: vcxagency-base:1.15.0
  
  vcxagency-node:
    build:
      context: https://github.com/AbsaOSS/vcxagencynode.git#master
      dockerfile: ./vcxagency-node/Dockerfile
    image: vcxagency-node:0.3.1
    ports:
      - 8080:8080
    depends_on:
      - postgres
    environment:
      - LOG_LEVEL=debug
      - LOG_ENABLE_INDYSDK=false
      - LOG_JSON_TO_CONSOLE=false
      - SERVER_PORT=8080
      - SERVER_MAX_REQUEST_SIZE_KB=300
      - SERVER_ENABLE_TLS=false
</code></pre>
<p>I haven't really worked with Docker at all. I tried to explore the documentation, but couldn't find something specific.</p>
<p>The goal would be to have these running on a Kubernetes cluster, but for now I just want to build the images in GitLab.</p>

CurlyError
<p>You could make use of Kaniko as a docker build tool and GitLabs feature called matrix builds.</p>
<p><strong>How to use kaniko for building docker images</strong></p>
<p>Snippet below is taken from the official GitLab <a href="https://docs.gitlab.com/ee/ci/docker/using_kaniko.html#building-a-docker-image-with-kaniko" rel="noreferrer">docs</a></p>
<pre class="lang-yaml prettyprint-override"><code>build:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [&quot;&quot;]
  script:
    - mkdir -p /kaniko/.docker
    - echo &quot;{\&quot;auths\&quot;:{\&quot;${CI_REGISTRY}\&quot;:{\&quot;auth\&quot;:\&quot;$(printf &quot;%s:%s&quot; &quot;${CI_REGISTRY_USER}&quot; &quot;${CI_REGISTRY_PASSWORD}&quot; | base64 | tr -d '\n')\&quot;}}}&quot; &gt; /kaniko/.docker/config.json
    - &gt;-
      /kaniko/executor
      --context &quot;${CI_PROJECT_DIR}&quot;
      --dockerfile &quot;${CI_PROJECT_DIR}/Dockerfile&quot;
      --destination &quot;${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}&quot;
  rules:
    - if: $CI_COMMIT_TAG
</code></pre>
<p><strong>What are matrix builds?</strong></p>
<p>GitLab introduced a feature for parallel job executions which is called matrix jobs, basically the job is executed multiple times with different sets of variables (variable matrix).</p>
<p>Taking the above snippet as a base you would result in something like below (suppose your dockerfiles are stored under <code>&lt;PROJECT_DIR&gt;/dockerfiles/</code> and are named <code>A.dockerfile</code> and <code>B.dockerfile</code>, respectively):</p>
<pre class="lang-yaml prettyprint-override"><code>.kaniko-build:
  stage: build
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [&quot;&quot;]
  script:
    - mkdir -p /kaniko/.docker
    - echo &quot;{\&quot;auths\&quot;:{\&quot;${CI_REGISTRY}\&quot;:{\&quot;auth\&quot;:\&quot;$(printf &quot;%s:%s&quot; &quot;${CI_REGISTRY_USER}&quot; &quot;${CI_REGISTRY_PASSWORD}&quot; | base64 | tr -d '\n')\&quot;}}}&quot; &gt; /kaniko/.docker/config.json
    - &gt;-
      /kaniko/executor
      --context &quot;${CI_PROJECT_DIR}&quot;
      --dockerfile &quot;${CI_PROJECT_DIR}/${DOCKERFILE}&quot;
      --destination &quot;${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}&quot;
  rules:
    - if: $CI_COMMIT_TAG

docker-build:
  extends: .build
  parallel:
    matrix:
      - DOCKERFILE: ${CI_PROJECT_DIR}/dockerfiles/A.dockerfile
      - DOCKERFILE: ${CI_PROJECT_DIR}/dockerfiles/B.dockerfile
</code></pre>
