Over a million developers have joined DZone.

Build, Test, and Deploy Apps Independently From a Monorepo

DZone's Guide to

Build, Test, and Deploy Apps Independently From a Monorepo

Set up your pipeline so that when changes occur to a project in the monorepo, the CI for that corresponding project is triggered and a Docker image is built and deployed.

· DevOps Zone ·
Free Resource

Can you release faster without sacrificing quality? See how with our free ebook Strategies for a Successful Test Automation Project and a free trial of Ranorex Studio today!

In our previous blog posts, we've shared our thoughts and experiences on our approach with monorepo. We received a few questions after that blog on how CI and deploys go with the monorepo.

In this article, we will learn how to run CI and build and deploy applications independently from a monorepo. On each PR and commit, we will run tests on the service that has changed build a Docker image from it and push it to a registry. This image can then be deployed to a cluster on any supported Container Service. We will use Shippable for this scenario.


Our monorepo has two projects. Both of them are simple Node JS apps. www is a front-end app and will run selenium tests. API is the backend app, which we will test using superagent and chai. The initial setup can be a bit tricky and depends on how projects in your repository are structured. Detecting what has changed in the repository is important. We will call a shell script from shippable.yml that will detect what has changed and trigger tests. When all our test pass successfully we will build a docker image and then push it to the registry.


language: node_js

  - selenium

    - ./detectChangedFolders.sh

This YAML l will run the below shell script, which will detect changes in folders (i.e., services in our repository and run tests). Also note that we are specifying all the services required in shippable.yml


#!/bin/bash -e
export IGNORE_FILES=$(ls -p | grep -v /)

detect_changed_folders() {
 echo "detecting changes for this build"
 folders=`git diff --name-only $SHIPPABLE_COMMIT_RANGE | sort -u | awk 'BEGIN {FS="/"} {print $1}' | uniq`
 export changed_components=$folders

run_tests() {
 for component in $changed_components
 echo "----------------------------------------------"
 echo "$component has changed"
 if ! [[ " ${IGNORE_FILES[@]} " =~ "$component" ]]; then
 echo "-------------------Running tests for $component---------------------"
 cd "$component"
 ./run.sh "$component"
 cd ..
 echo "Ignoring this change"

if [ "$IS_PULL_REQUEST" != true ]; then
 echo "skipping because it's a PR"

1. Enable

Enable the project on Shippable. Now, when navigating to the pipelines tab, you can view your project on SPOG.


On every build triggered, the changed folders are detected and an image is built and pushed to the registry. In our example, the run.sh file that we have in every folder is responsible for triggering tests, building an image, and pushing it to the registry.

2. Deploy

Now that our images are built, we will use pipelines to deploy these images. We will begin our resources and jobs in shippable.resources.yml and shippable.jobs.yml , respectively.

Here is how we will define resources and jobs for our pipeline:

 - name: api-img
 type: image
 integration: dockerhub
 sourceName: "chetantarale/sampleapp"
 versionName: master.3

 - name: www-img
 type: image
 integration: dockerhub
 sourceName: "chetantarale/sampleapp"
 versionName: master.3

 - name: ddc-cluster
 type: cluster
 integration: ddc-cluster

 - name: www-options #required
 type: dockerOptions #required
 portMappings: #optional
 - "51000:51000"

 - name: api-options #required
 type: dockerOptions #required
 portMappings: #optional
 - "50000:50000"

 - name: dockerhub
 type: integration
 integration: "dockerhub"

www-img and api-img are the two images that will be built when the CI job runs. These images are the OUTs from the CI job.

Dockerhub is a resource of type integration that points to the registry where we will push our image. ddc-cluster is an integration of type cluster where we will deploy our app. www-options and api-options are the options that can be appended to a docker image to be pushed.

We will define the following jobs in our job's YAML:

  • A runCI job that builds our images.
  • Two manifest jobs to generate a manifest.
  • Two deploy jobs that deploy our app.
 - name: monorepo_sample_runCI
 type: runCI
 - OUT: api-img
 - OUT: www-img
 - script: echo 'on success !!!!!'
 - script: echo 'Failed job .... :('

 - name: www-man
 type: manifest
 - IN: www-options
 - IN: www-img
 force: true

 - name: www-deploy
 type: deploy
 - IN: www-man
 - IN: ddc-cluster

 - name: api-man
 type: manifest
 - IN: api-options
 - IN: api-img
 force: true

 - name: api-deploy
 type: deploy
 - IN: api-man
 - IN: ddc-cluster

Now, push these files and add this repo as syncRepo from Shippable UI. Shippable will read the jobs and resource's YAMLs and create your pipeline.



We have successfully set up our pipeline. For any changes to a project within in the monorepo, the CI for that corresponding project is triggered and a Docker image is built and deployed.

Get your test automation project off to the right start. Download your free test planning template and a 30-day no-obligation trial of Ranorex Studio today!

monorepo ,ci ,docker ,devops ,tutorial ,app development

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}