Skip to main content

Multiple branch deployment

Overview

Multiple branch deployment is a solution that helps optimize k8s resource utilization for the development process. Based on that, we can keep the environment working stably during application development. The idea is the source code of all feature branches will be deployed to separate namespaces to prevent to impact to stable code of default branch. In order to implement the multiple branch deployment, 4 main stuffs are required

  • Source code repositories
  • GitLab template
  • dwp-spec repository
  • live repository (helm)

Source code repositories

The source code repositories are divided to 3 groups

  • Libraries

    • dwp-core
    • dwp-akerbp-lib
    • dwp-landing-page
  • AkerBP services

    • microservice-akerbp-action-log
    • microservice-akerbp-auto-casing-seat
    • microservice-akerbp-edrilling
    • microservice-akerbp-email-notification
    • microservice-akerbp-formation-tops
    • microservice-akerbp-iqx
    • microservice-akerbp-planned-survey
    • microservice-akerbp-target-summary
    • microservice-akerbp-timeplanner
    • microservice-akerbp-utilities
    • microservice-akerbp-websocket
    • microservice-akerbp-well-project-plan
    • microservice-akerbp-wellbarrier
  • Customized core services

    • microservice-custom-loads
    • microservice-kick-tolerance
    • microservice-trajectory
    • dwp-webapp
    • dwp-help
    • config
    • dwp-db-utility

AkerBP services will be deployed to akerbp<release version> namespace for default branch and akerbp<release version>-dev namespace for feature branch. Customized core services will be deployed to dwp-system-akerbp<release version> namespace for default branch and dwp-system-akerbp<release version>-dev namespace for feature branch.

GitLab template

All gitlab template files are stored at: https://gitlab.com/ds365ai/snowleopard/microservice-utilities/-/tree/Dev_Integration_Branch/git_templates?ref_type=heads We can refer these files to know exactly how pipeline worked.

dwp-spec repository

URL: https://gitlab.com/ds365ai/snowleopard/dwp-spec The gitlab yaml file on this repository will handle deployment stage. We can overwrite value of environment variables that defined in live repository by updating dwp_dev_large.json (more explanation in implementation section)

Live repository

URL: https://gitlab.com/Halliburton-Landmark/dsif/live/aws/akerbp-oec-live/-/tree/akerbp-dev-oec-2.4.2?ref_type=heads This repository contains all helm files that used for deployment.

Finding environment variables to swap out

kubectl get pod <podname> -n <namespace> -o json | jq '.spec.containers[].env'
# Example
kubectl get pod microservice-kick-tolerance-6746449bbf-rl9mp -n dwp -o json | jq '.spec.containers[].env'

Implementation

  1. Build & deploy services

alt text

Following below steps to implement build and deploy pipeline:

  • Create feature branch as convention name
  • Update dwp_dev_large.json and live repo if needed.

In order to deploy code from feature branch to cluster, the convention name is required. The convention branch name is <feature-branch-name>-deliver. The branches do not comply with the convention name that still is built and the image is pushed to Jfrog, however it is not deployed to k8s cluster. Ideally, we should create the same branch name for 3 repositories: source code, dwp-spec, live (it should be checked out from default branch) so we can handle environment variables of feature branches separately. For dwp-spec and live repositories, if we do not create the same branch as the source code repository, the pipeline will use the default branch for these repositories.

In case we need to overwrite a common environment variable in live repository, we can add that variable and its value to dwp_dev_large.json

For example:

alt text

We have middleware_endpoint represents middleware endpoint in live repository, we can overwrite it before deploying to the cluster by updating it in dwp_dev_large.json like this:

need to find correct image here

alt text

When do we need to update dwp_dev_large.json ?

Assume we need to deploy webapp and dwp-middleware services of the feature branch to the k8s cluster. Expectation is webapp will call dwp-middleware of the feature branch correctly. Because endpoint name of services deployed on the cluster base on feature branch name. As above capture, all services which are deployed from this branch of dwp-spec will call the middleware endpoint http://dwp242akerbp-dwp-middleware.dwp-system-akerbp242-dev/ as well. In order to determine correctly the endpoint of service, we have to access k8s cluster to check that. 2. Build & deploy libraries

alt text

In order to implement the multiple branch pipeline for the library. Just need to make sure the created feature branch on both of library source repository and dwp-app is the same. So the library version will be updated to package.json file of dwp-app and trigger dwp-app pipeline automatically.

Example of how to deploy

Note: All the feature branches mentioned below should have the same name.

Backend:

  1. Create feature branch in microservice, e.g. microservice-log-transfer
  2. Create feature branch in live-repo: https://gitlab.com/ds365ai/DSWC/dwp-beta-live-repo
  3. Create feature branch in spec-repo: https://gitlab.com/ds365ai/DSWC/dwp-spec
    • Update dwp_dev_large.json with the internal url of the microservice
    • E.g. for microservice-log-transfer, if your branch is called b4c-import-data-issue-deliver, the log_transfer_endpoint variable should be changed to "http://b4c-import-dat-microservice-log-transfer.dwp-dev" (http://{{the first 14 characters of the feature branch}}-{{name of microservice}}.{{deployment namespace}})
  4. Create feature branch in dwp-app

Frontend:

  1. Create feature branch in the repo, e.g. dwp-log-transfer
  2. Create feature branch in dwp-core
  3. Create feature branch in dwp-app, change the version of the correct package in package.json
    • E.g. for dwp-log-transfer, change the package to "@dswc/dwp-log-transfer": ">=17.0.0-b4c-import-data-issue-deliver.1 <17.0.0-b4c-import-data-issue-deliver.9999"

After pipelines have been run successfully, the branches should have been deployed to the following urls: https://{{the first 14 characters of the feature branch}}-dwp-webapp.{{environment}}

OEC2 - https://b4c-import-dat-webapp-dwp-webapp.oec-prod-dsif2.openearth.io/

Tiger - https://b4c-import-dat-webapp-dwp-webapp.tiger.dazlmkengdev02.ienergycloud.solutions

Connecting...