Build an Image from a different Git repository

Build microservices from other repositories

In most cases, your Codefresh pipeline checks out a single Git repository. Codefresh has great support also 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 microservices from two different 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 Docker image dashboard .

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.

CI/CD pipeline examples
Git clone step
Build an Image with the Dockerfile in root directory
Build step in pipelines in pipelines
Build and push an image
Parallel pipelines