From eda922f65d579926d6887444677109751c59809c Mon Sep 17 00:00:00 2001 From: Yuxiang Zhu Date: Aug 24 2018 08:28:14 +0000 Subject: CI/CD: Add Makefile for updating CI/CD OpenShift Pipeline jobs This Makefile is used to update the OpenShift manifests for all pipeline jobs with a single run. Parameters of the templates are configured for the upstream WaiverDB CI/CD workflow and service locations. *NOTE: Secrets and images in your OpenShift project are *NOT* touched by this script. You have to manually manage them.* Log into your OpenShift project that is dedicated for CI/CD workloads. You must have the admin access to the OpenShift project. ```bash oc login oc project ``` To install or update all CI/CD pipelines, just run ```bash make install ``` To delete all manifests created by this script, run ```bash make uninstall ``` More information can be found in `openshift/README.md`. --- diff --git a/openshift/README.md b/openshift/README.md index 2b275c0..cab6615 100644 --- a/openshift/README.md +++ b/openshift/README.md @@ -20,6 +20,22 @@ Before using the Pipeline, please ensure your Jenkins master has the following p Notes: [1]: Those plugins are preinstalled if you are using the Jenkins master shipped with OpenShift. +### Batch Updating All Pipeline Jobs +Running `make install` inside `openshift/pipelines` will perform batch updates on all jobs +with parameters defined in `openshift/pipelines/jobs`. +Logging into your OpenShift project is required before using the Makefile. +Secrets and Images in your OpenShift project are *NOT* touched. + +All pipeline job definitions are in `./pipelines/jobs` while templates are in `./pipelines/templates`. +For each pipeline job, there are 2 files in `openshift/pipelines/jobs`: +`.env` and `.tmpl`. `.env` gives all the parameters +passing to the OpenShift template specified in `.tmpl`. +You can also specify an alternate directories for looking up job definitions and templates +by using `JOBS_DIR` and `TEMPLATES_DIR` Makefile variables. +For example, if you want to set up a stage version of pipeline jobs +with experimental modifications to job definitions, +you can run: `make install JOBS_DIR=stage-jobs`. For more information, run `make help`. + ### Dev Pipeline Dev Pipeline is a part of the WaiverDB Pipeline, covers the following steps: diff --git a/openshift/pipelines/Makefile b/openshift/pipelines/Makefile new file mode 100644 index 0000000..993653c --- /dev/null +++ b/openshift/pipelines/Makefile @@ -0,0 +1,38 @@ +OC:=oc +OCFLAGS:= +JOBS_DIR:=jobs +TEMPLATES_DIR:=templates +JOB_PARAM_FILES:=$(wildcard $(JOBS_DIR)/*.env) +JOBS:=$(patsubst $(JOBS_DIR)/%.env,%,$(JOB_PARAM_FILES)) + +OC_CMD=$(OC) $(OCFLAGS) + +help: + @echo TARGETS + @echo -e "\tinstall\t\tInstall or update pipelines to OpenShift" + @echo -e "\tuninstall\tDelete installed pipelines from OpenShift" + @echo + @echo VARIABLES + @echo -e "\tJOBS\t\tSpace seperated list of pipeline jobs to install" + @echo -e "\tJOBS_DIR\tLooking for pipeline job definitions in an alternate directory." + @echo -e "\tTEMPLATES_DIR\tLooking for pipeline job templates in an alternate directory." + @echo -e "\tOC\t\tUse this oc command" + @echo -e "\tOCFLAGS\t\tOptions to append to the oc command arguments" +install: + @for job in $(JOBS); do \ + echo "[PIPELINE] Updating pipeline job \"$${job}\"..." ; \ + template_file=$$(cat ./$(JOBS_DIR)/$${job}.tmpl); \ + $(OC_CMD) process --local -f ./$(TEMPLATES_DIR)/$${template_file} \ + --param-file ./$(JOBS_DIR)/$${job}.env | $(OC_CMD) apply -f -; \ + echo "[PIPELINE] Pipeline job \"$${job}\" updated" ; \ + done +uninstall: + @for job in $(JOBS); do \ + template_file=$$(cat ./$(JOBS_DIR)/$${job}.tmpl); \ + template_name=$${template_file%.y?ml}; \ + template_name=$${template_name%-template}; \ + echo "[PIPELINE] Deleting pipeline job \"$${job}\"..." ; \ + $(OC_CMD) delete all -l template="$$template_name" -l app="$$job" ;\ + echo "[PIPELINE] Pipeline job \"$${job}\" deleted" ; \ + done +.PHONY: help install uninstall