How to use a Building Block multiple times

This tutorial will show you how you can use a Building Block multiple times
in the same environment with the example of the Redis-HA Building Block.

Include multiple Building Block instances

Each Building Block instance should have its own dedicated directory in the control repository so that you their values can be changed independently.

The directory structure of the example's control repository is the following:

└── syseleven-redis-ha/
    ├── .gitlab-ci.yml
└── syseleven-redis-ha-2/
    ├── .gitlab-ci.yml
    └── values-redis-ha.yaml

The main .gitlab-ci.yml should look like this:


  - /syseleven-redis-ha/.gitlab-ci.yml
  - /syseleven-redis-ha-2/.gitlab-ci.yml

Extend Job Environment Templates

The next step is to include a JobEnvironment template to each Building Block instance.

Since the instances are to be deployed in the same environment and Gitlab does not allow to include the same template in multiple Gitlab CI definitions, you have to include it once in one of your Building Block instances .gitlab-ci.yml. The other instances will have to extend the job of the first one and do any necessary modifications.

The modifications that need to be made are the following:

  • the job names
  • the environment variables BASEDIR, NAMESPACE_ and RELEASENAME

First deployment redis-ha:


  - project: syseleven/building-blocks/helmfiles/redis-ha
    file: JobDevelopment.yaml
    ref: 1.33.0

And the second deployment redis-ha-2:


  extends: .syseleven-redis-ha-development
    NAMESPACE_REDIS_HA: syseleven-redis-ha-2
    BASEDIR: $CI_PROJECT_DIR/syseleven-redis-ha-2
    RELEASE_NAME_REDIS_HA: redis-ha-2

    - syseleven-redis-ha-diff-development
    - .syseleven-redis-ha-2-development

    - syseleven-redis-ha-deploy-development
    - .syseleven-redis-ha-2-development

After committing, you should get two Redis-HA deployments in different namespaces. If you want to deploy the same Building Block multiple times in the same namespace, you have to change default variables.