Build an Image from a Different Git Repository

Build microservices from other repositories

In most cases, your Codefresh pipeline will checkout a single Git repository. Codefresh also has great support for Monorepos if you have placed all your applications in a single repository.

A Codefresh pipeline is not really tied to a specific git repository, which means that by checking out multiple git repositories you can build docker images from other unrelated repositories in a single pipeline if you wish to do so.

Building Docker images from other Git repositories

Here is a Codefresh pipeline that checks out two micro-services from two separate Git repositories.

Checkout and build docker images

Checkout and build docker images

And here is the pipeline definition.

codefresh.yml

version: '1.0'
stages:
  - 'clone phase'
  - 'build phase'
steps:
  checkoutApp1:
    title: 'Cloning first repository...'
    type: git-clone
    repo: kostis-codefresh/example_nodejs_postgres
    revision: experiment1
    git: github
    stage: 'clone phase'
  checkoutApp2:
    title: 'Cloning second repository...'
    type: git-clone
    repo: kostis-codefresh/trivial-go-web
    revision: master
    git: github
    stage: 'clone phase'
  myFirstDockerImage:
    title: 'Building Microservice A'
    type: build
    dockerfile: Dockerfile
    image_name: my-nodejs-image
    tag: from-develop-branch
    working_directory: './example_nodejs_postgres'
    stage: 'build phase'   
  mySecondDockerImage:
    title: 'Building Microservice B'
    type: build
    dockerfile: Dockerfile
    working_directory: './trivial-go-web'
    image_name: my-app-image
    tag: from-master-branch
    stage: 'build phase'
      

The pipeline first checks out two different Git repositories (which themselves contain Dockerfiles). Then it creates a Docker image for each one using the respective Dockerfile.

You can see both images in the Codefresh Docker registry .

Docker images from other Git repos

Docker images from other Git repos

Notice that there are no explicit push steps in the pipeline, as all successful Codefresh pipelines automatically push to the private Docker registry.