Skip to content
Snippets Groups Projects
Helm.yaml 4.64 KiB
Newer Older
# -*- mode: yaml; coding: utf-8 -*-
# vim: ft=yaml
#
# Hidden template jobs to be used in `.gitlab-ci.yml`
#
# - `.helm:lint`: verify formatting of the helm chart
#
# - `.helm:package`: build the helm package tgz file
# - `.helm:cm-push`: push the helm package tgz file to a remote
---
#
# .helm:lint
# ==========
#
# Verify formatting of the helm chart files.
#
# USAGE
# =====
#
# include:
#   - project: EOLE/Infra/ci-tools
#     ref: master
#     file: /templates/Helm.yaml
#
# stages:
#   - lint
#
# helm lint: {extends: '.helm:lint'}
#
# REQUIREMENTS
# ============
#
# - a `lint` stage must be present in your pipeline or it must be
#   overriden by the extending job to feet your need.
#
# - the `.not-on-stable` rules templates or it must be overriden by
#   the extending job to feet your need
#
# OPTIONAL VARIABLES
# ==================
#
# - `CHART_DIR`: directory of the helm chart, default to `.`
#
# - `HELM_IMAGE`: name of the `helm` docker image to use
#
# - `HELM_ARGS`: optional arguments to pass to `helm lint` command,
#   empty by default
#
# USED CI VARIABLES
# =================
#
.helm:lint:
  stage: lint
  extends:
    - .helm:base
    - .not-on-stable
  script:
    - echo -e "\e[0Ksection_start:$(date +%s):helm-lint\r\e[0KExecute 'helm lint ${HELM_ARGS} ${CHART_DIR}'"
    - helm lint ${HELM_ARGS} "${CHART_DIR}"
    - echo -e "\e[0Ksection_end:$(date +%s):helm-lint\r\e[0K"


# .helm:package
# =============
#
# Build the helm package tgz file
#
# USAGE
# =====
#
# include:
#   - project: EOLE/Infra/ci-tools
#     ref: master
#     file: /templates/Helm.yaml
#
# stages:
#   - build
#
# helm build: {extends: '.helm:package'}
#
# REQUIREMENTS
# ============
#
# - a `build` stage must be present in your pipeline or it must be
#   overriden by the extending job to feet your need.
#
# - the `.not-on-stable` rules templates or it must be overriden by
#   the extending job to feet your need
#
# OPTIONAL VARIABLES
# ==================
#
# - `CHART_DIR`: directory of the helm chart, default to `.`
#
# - `HELM_IMAGE`: name of the `helm` docker image to use
#
# - `HELM_ARGS`: optional arguments to pass to `helm package` command,
#   empty by default
#
# - `HELM_BUILD_DIR`: write package chart in this directory, default
#   to `build`
#
# USED CI VARIABLES
# =================
#
  stage: build
  extends:
    - .helm:base
    - .not-on-stable
  artifacts:
    paths:
      - $HELM_BUILD_DIR
  script:
    - echo -e "\e[0Ksection_start:$(date +%s):helm-package\r\e[0KExecute 'helm package --destination ${HELM_BUILD_DIR} ${HELM_ARGS} ${CHART_DIR}'"
    - helm package --destination "${HELM_BUILD_DIR}" ${HELM_ARGS} "${CHART_DIR}"
    - echo -e "\e[0Ksection_end:$(date +%s):helm-package\r\e[0K"


# .helm:cm-push
# =============
# Push the helm package tgz file to a remote chartMuseum repository
#
# USAGE
# =====
#
# include:
#   - project: EOLE/Infra/ci-tools
#     ref: master
#     file: /templates/Helm.yaml
#
# stages:
#   - release
#
# helm publish: {extends: '.helm:cm-push'}
#
# REQUIREMENTS
# ============
#
# - a `release` stage must be present in your pipeline or it must be
#   overriden by the extending job to feet your need.
#
# - the `.on-release-tag` rules templates or it must be overriden by
#   the extending job to feet your need
#
# - `HELM_REPO` variable: URL of the helm ChartMuseum
#
# - `HELM_REPO_USERNAME` variable: name of the user with write access
#   to the ChartMuseum
#
# - `HELM_REPO_PASSWORD` variable: password of `HELM_REPO_USERNAME`
#
# OPTIONAL VARIABLES
# ==================
#
# - `CHART_DIR`: directory of the helm chart, default to `.`
#
# - `HELM_IMAGE`: name of the `helm` docker image to use
#
# - `HELM_ARGS`: optional arguments to pass to `helm cm-push` command,
#   empty by default
#
# - `HELM_BUILD_DIR`: write package chart in this directory, default
#   to `build`
#
# USED CI VARIABLES
# =================
#
  stage: release
  extends:
    - .helm:base
    - .on-release-tag
  script:
    - echo -e "\e[0Ksection_start:$(date +%s):helm-cm-push-config[collapsed=true]\r\e[0KPrepare environment to push to helm remote repository '${HELM_REPO}'"
    - helm repo add chartrepo "${HELM_REPO}"
    - echo -e "\e[0Ksection_end:$(date +%s):helm-cm-push-config\r\e[0K"
    - echo -e "\e[0Ksection_start:$(date +%s):helm-cm-push\r\e[0KExecute 'helm cm-push ${HELM_BUILD_DIR}/* chartrepo'"
    - helm cm-push "${HELM_BUILD_DIR}"/* chartrepo
    - echo -e "\e[0Ksection_end:$(date +%s):helm-cm-push\r\e[0K"


.helm:base:
  extends: .not-on-stable
  image:
    name: "${HELM_IMAGE}"
  variables:
    HELM_IMAGE: hub.eole.education/eole/helm:latest
    HELM_ARGS: ''
    HELM_BUILD_DIR: 'build'