diff --git a/helmfile/sda.eks.alb.helmfile.yml b/helmfile/sda.eks.alb.helmfile.yml index 27a6a8c..f03f861 100644 --- a/helmfile/sda.eks.alb.helmfile.yml +++ b/helmfile/sda.eks.alb.helmfile.yml @@ -46,7 +46,7 @@ releases: values: - values/cloudbees/cb-ci.common.yml.gotmpl - values/cloudbees/cb-ci.eks.alb.ha.yml.gotmpl - - name: cbcd + - name: cbcd-server namespace: cbcd version: 2.27.0 chart: cloudbees/cloudbees-flow diff --git a/make/cbcd/Makefile b/make/cbcd/Makefile index fa12c12..1b50974 100644 --- a/make/cbcd/Makefile +++ b/make/cbcd/Makefile @@ -16,9 +16,9 @@ CBCD_AGENT_VERSION := $(CBCD_SERVER_VERSION) CB_LB_CONFIG := $(shell echo $(call getEnvProperty,CB_LB_CONFIG)) HOSTNAME := $(shell echo $(call getEnvProperty,HOSTNAME)) -.PHONY: updateDb -updateDb: ## Create and Update Database inside Kubernetes Cluster -updateDb: check_kubeconfig check_envfile +.PHONY: cdUpdateDb +cdUpdateDb: ## Create and Update Database Service inside Kubernetes Cluster. It requires to create Database for Flow +cdUpdateDb: check_kubeconfig check_envfile source .env && \ helm repo add bitnami https://charts.bitnami.com/bitnami && helm repo update && \ helm --debug upgrade --install mysql bitnami/mysql --version $(MYSQL_DB_VERSION) \ @@ -26,27 +26,27 @@ updateDb: check_kubeconfig check_envfile --namespace db --create-namespace && \ kubectl rollout status sts mysql --namespace db && wait -.PHONY: connectDBRemotely -connectDBRemotely: ## Open a connection to Database remotely for CloudBees CD -connectDBRemotely: check_envfile +.PHONY: cdConnectDBRemotely +cdConnectDBRemotely: ## Open a connection to Database remotely for CloudBees CD +cdConnectDBRemotely: check_envfile source .env && \ mysql -h $$EXTERNAL_ENDPOINT_DB -u admin --password --verbose -.PHONY: createDBRemotely -createDBRemotely: ## Update Database remotely for CloudBees CD -createDBRemotely: check_envfile +.PHONY: cdCreateDBRemotely +cdCreateDBRemotely: ## Update Database remotely for CloudBees CD +cdCreateDBRemotely: check_envfile source .env && \ mysql -h $$EXTERNAL_ENDPOINT_DB -u admin --password --verbose < $(MKFILE)/create.db.sql -.PHONY: dropDBRemotely -dropDBRemotely: ## Delete Database remotely for CloudBees CD. Note: Database cannot be used between different deployment. -dropDBRemotely: check_envfile +.PHONY: cdDropDBRemotely +cdDropDBRemotely: ## Delete Database remotely for CloudBees CD. Note: Database cannot be used between different deployment. +cdDropDBRemotely: check_envfile source .env && \ mysql -h $$EXTERNAL_ENDPOINT_DB -u admin --password --verbose < $(MKFILE)/drop.db.sql -.PHONY: updateServer -updateServer: ## Update CD Server -updateServer: check_kubeconfig check_envfile guard-CB_LB_CONFIG +.PHONY: cdUpdateServer +cdUpdateServer: ## Update CD Server +cdUpdateServer: check_kubeconfig check_envfile guard-CB_LB_CONFIG source .env && \ sed "s/\$${hostname}/$$HOSTNAME/g; \ s|\$${cert_arn}|$$CERTIFICATE_ID|g ;" < $(DIR_HELM_VALUES)/cloudbees/$(CB_LB_CONFIG).yaml > $(MKFILE)/values.$(CB_LB_CONFIG).yaml && \ @@ -63,13 +63,17 @@ updateServer: check_kubeconfig check_envfile guard-CB_LB_CONFIG --namespace cbcd --create-namespace \ --timeout 10000s -.PHONY: updateAll -updateAll: ## Update Database + CD Server -updateAll: updateDb updateServer +.PHONY: cdUpdateAll +cdUpdateAll: ## Update Database Service + CD Server. It requires to create Database for Flow. +cdUpdateAll: cdUpdateDb cdUpdateServer -.PHONY: updateAgent -updateAgent: ## Update CD Agent -updateAgent: check_kubeconfig check_envfile guard-CB_LB_CONFIG +.PHONY: cdUpdateAllDBRemote +cdUpdateAllDBRemote: ## Create Database for Flow + CD Server. +cdUpdateAllDBRemote: cdCreateDBRemotely cdUpdateServer + +.PHONY: cdUpdateAgent +cdUpdateAgent: ## Update CD Agent +cdUpdateAgent: check_kubeconfig check_envfile guard-CB_LB_CONFIG source .env && \ kubectl create cbcd-agent kubectl create secret generic flow-agent-secret \ @@ -81,15 +85,15 @@ updateAgent: check_kubeconfig check_envfile guard-CB_LB_CONFIG --namespace cbcd_AGENT \ --timeout 10000s -.PHONY: getValues -getValues: ## Get Helm Chart value for an specific version. -getValues: +.PHONY: cdGetValues +cdGetValues: ## Get Helm Chart value for an specific version. +cdGetValues: helm repo add cloudbees https://public-charts.artifacts.cloudbees.com/repository/public/ && helm repo update helm inspect values --version $(CBCD_SERVER_VERSION) cloudbees/cloudbees-flow > $(MKFILE)/values.all.$(CBCD_SERVER_VERSION).cb-cd-server.yaml -.PHONY: deleteDb -deleteDb: ## Delete Database. -deleteDb: check_kubeconfig check_envfile +.PHONY: cdDeleteDb +cdDeleteDb: ## Delete Database. +cdDeleteDb: check_kubeconfig check_envfile $(call print_title,Uninstall CloudBees Core via Helm) source .env && \ kubectl delete --all pods --grace-period=0 --force --namespace db && \ @@ -98,9 +102,9 @@ deleteDb: check_kubeconfig check_envfile kubectl delete --all pvc --grace-period=0 --force --namespace db && \ kubectl delete ns db || echo "There is NOT existing namespace db" -.PHONY: deleteServer -deleteServer: ## Delete CloudBees CD Server. -deleteServer: check_kubeconfig check_envfile +.PHONY: cdDeleteServer +cdDeleteServer: ## Delete CloudBees CD Server. +cdDeleteServer: check_kubeconfig check_envfile $(call print_title,Uninstall CloudBees Core via Helm) source .env && \ kubectl delete --all pods --grace-period=0 --force --namespace cbcd && \ @@ -109,6 +113,10 @@ deleteServer: check_kubeconfig check_envfile kubectl delete --all pvc --grace-period=0 --force --namespace cbcd && \ kubectl delete ns cbcd || echo "There is NOT existing namespace cbcd" -.PHONY: deleteAll -deleteAll: ## Delete CloudBees CD + Database -deleteAll: deleteServer deleteDb +.PHONY: cdDeleteAll +cdDeleteAll: ## Delete CloudBees CD Release + Database Service. +cdDeleteAll: cdDeleteServer cdDeleteDb + +.PHONY: cdDeleteAllDBRemote +cdDeleteAllDBRemote: ## Delete CloudBees CD Release + Drop Database for CloudBees CD. +cdDeleteAllDBRemote: cdDeleteServer cdDropDBRemotely diff --git a/make/cbci/Makefile b/make/cbci/Makefile index 08b2520..8c47313 100644 --- a/make/cbci/Makefile +++ b/make/cbci/Makefile @@ -72,9 +72,9 @@ define updateCBCI kubectl rollout status sts cjoc --namespace cbci && wait endef -.PHONY: helm-update-simple -helm-update-simple: ## Install/Update CloudBees Core Modern via Helm. Adding OC Simple Casc Bundle. -helm-update-simple: check_kubeconfig check_envfile guard-CB_LB_CONFIG +.PHONY: ciHelm-update-simple +ciHelm-update-simple: ## Install/Update CloudBees Core Modern via Helm. Adding OC Simple Casc Bundle. +ciHelm-update-simple: check_kubeconfig check_envfile guard-CB_LB_CONFIG $(call print_title, Load Simple OC Casc Bundle) source .env && \ kubectl create ns "cbci" || echo "cbci exist" && \ @@ -84,9 +84,9 @@ helm-update-simple: check_kubeconfig check_envfile guard-CB_LB_CONFIG $(call print_title,Updating Remote CloudBees Helm Chart) $(call updateCBCI) -.PHONY: helm-update-advanced -helm-update-advanced: ## Install/Update CloudBees Core Modern via Helm. Adding OC Advanced Casc Bundle and Local Helm Chart. -helm-update-advanced: check_kubeconfig check_envfile guard-CB_LB_CONFIG +.PHONY: ciHelm-update-advanced +ciHelm-update-advanced: ## Install/Update CloudBees Core Modern via Helm. Adding OC Advanced Casc Bundle and Local Helm Chart. +ciHelm-update-advanced: check_kubeconfig check_envfile guard-CB_LB_CONFIG @echo -n "Are up to date .env file and $(DIR_CHARTS)/cb-ci-local/casc/oc/modern.oc.advance/variables.yaml? [yes/No] " && read ans && [ $${ans:-No} = yes ] $(call print_title,Updating Local CloudBees Helm Chart) source .env && \ @@ -109,17 +109,17 @@ helm-update-advanced: check_kubeconfig check_envfile guard-CB_LB_CONFIG $(call print_title,Updating Remote CloudBees Helm Chart) $(call updateCBCI) -.PHONY: helmfile-update -helmfile-update: ## Install/Update CloudBees Core Modern via Helmfile. -helmfile-update: check_kubeconfig +.PHONY: ciHelmfile-update +ciHelmfile-update: ## Install/Update CloudBees Core Modern via Helmfile. +ciHelmfile-update: check_kubeconfig @rm -f $(HELM_LOG_PATH) PLATFORM=ci helmfile --debug --file $(DIR_HELMFILES)/sda.eks.alb.helmfile.yml --interactive apply | tee -a $(HELM_LOG_PATH) @#$(call restartOCIfExist) @#kubectl rollout status sts cjoc --namespace cbci && wait -.PHONY: check-availability -check-availability: ## Check availability of the OC. -check-availability: guard-OC_URL +.PHONY: ciCheck-availability +ciCheck-availability: ## Check availability of the OC. +ciCheck-availability: guard-OC_URL source .env && \ until kubectl get pod -n cbci cjoc-0; do sleep 2 && echo "Waiting for Pod to get ready"; done @echo "OC Pod is Ready" @@ -130,24 +130,24 @@ check-availability: guard-OC_URL until curl -u $$ADMIN_JENKINS_USER:$$ADMIN_JENKINS_PASS -s $(OC_URL) > /dev/null; do sleep 10 && echo "Waiting for Operation Center at $(OC_URL)"; done @echo "Operation Center Ready at $(OC_URL)" -.PHONY: validate-casc-bundle -validate-casc-bundle: ## Validate 1 bundle. -validate-casc-bundle: guard-OC_URL +.PHONY: ciValidate-casc-bundle +ciValidate-casc-bundle: ## Validate 1 bundle. +ciValidate-casc-bundle: guard-OC_URL source .env && \ cd $(DIR_CHARTS)/$$PATH_BUNDLE_VAL && zip -r /tmp/bundle-to-validate.zip $$BUNDLE_VAL $(call JenkinsCLI,casc-pre-validate-bundle) < /tmp/bundle-to-validate.zip | yq -o=json -.PHONY: update-casc-cm -update-casc-cm: ## Update Configuration as Code Controllers in Operation Center, Validate and Apply (if it requires) -update-casc-cm: guard-OC_URL +.PHONY: ciUpdate-casc-cm +ciUpdate-casc-cm: ## Update Configuration as Code Controllers in Operation Center, Validate and Apply (if it requires) +ciUpdate-casc-cm: guard-OC_URL $(call JenkinsCLI,casc-check-out-bundles) | yq -o=json $(call JenkinsCLI,casc-raw-bundle-validation-log) | yq -o=json @echo -n "Do you want to Restart Controller to apply? [yes/No] " && read ans && [ $${ans:-No} = yes ] $(call JenkinsCLI,build admin/restart-all-controllers -s) -.PHONY: plugin-calc-bundle -plugin-calculator: ## Provide plugin.yaml and plugin-catalog.yaml for a bundle. IMPORTANT: Require to be run from Bash5 (eg. docker-libs > bash5.alpine) -plugin-calculator: +.PHONY: ciPlugin-calculator +ciPlugin-calculator: ## Provide plugin.yaml and plugin-catalog.yaml for a bundle. IMPORTANT: Require to be run from Bash5 (eg. docker-libs > bash5.alpine) +ciPlugin-calculator: source .env && \ current_full_bundle_path=$$(echo $$CBCI_CASC_BUNDLE_PATH/$$CBCI_CASC_BUNDLE_NAME) && \ actual_plugins_folder=$$(echo $(DIR_CHARTS)/cb-ci-local/casc/tmp-plugin-calculations) && \ @@ -165,22 +165,22 @@ plugin-calculator: -C "$$actual_plugins_folder/catalog/$(CBCI_VERSION_APP).offline.yaml" \ -s -.PHONY: purge_pods -purge_pods: -purge_pods: #Purge Pods in cbci and cbci-agents namespaces +.PHONY: ciPurge_pods +ciPurge_pods: +ciPurge_pods: #Purge Pods in cbci and cbci-agents namespaces kubectl delete --all pods --grace-period=0 --force --namespace "cbci" kubectl delete --all pods --grace-period=0 --force --namespace "cbci-agents" -.PHONY: helm-delete -helm-delete: ## Helm Delete all things into CloudBees Core Modern Namespaces and Storage. Ref: https://docs.cloudbees.com/docs/cloudbees-ci/latest/kubernetes-install-guide/kubernetes-uninstall -helm-delete: check_kubeconfig check_envfile purge_pods +.PHONY: ciHelm-delete +ciHelm-delete: ## Helm Delete all things into CloudBees Core Modern Namespaces and Storage. Ref: https://docs.cloudbees.com/docs/cloudbees-ci/latest/kubernetes-install-guide/kubernetes-uninstall +ciHelm-delete: check_kubeconfig check_envfile ciPurge_pods $(call print_title,Uninstall CloudBees Core via Helm) helm --debug uninstall cbci --namespace "cbci" || echo "Relese cbci does not exist" $(call postHelmDelete) -.PHONY: helmfile-delete -helmfile-delete: ## Helmfile Delete -helmfile-delete: check_kubeconfig purge_pods +.PHONY: ciHelmfile-delete +ciHelmfile-delete: ## Helmfile Delete +ciHelmfile-delete: check_kubeconfig ciPurge_pods @rm -f $(HELM_LOG_PATH) helmfile --debug --file $(DIR_HELMFILES)/sda.eks.alb.helmfile.yml destroy | tee -a $(HELM_LOG_PATH) $(call postHelmDelete) diff --git a/make/cbsda/Makefile b/make/cbsda/Makefile index e8231aa..9aa25c5 100644 --- a/make/cbsda/Makefile +++ b/make/cbsda/Makefile @@ -1,35 +1,23 @@ MKFILE := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) +CI_MAKEFOLDER := $(MKFILE)/../cbci +CD_MAKEFOLDER := $(MKFILE)/../cbcd PARENT_MKFILE := $(HOME)/.Makefile DIR_HELMFILES := $(MKFILE)/../../helmfile HELM_LOG_PATH := $(MKFILE)/helm.log include $(PARENT_MKFILE) -define postHelmDelete - helm repo remove cloudbees || echo "Repository cloudbees does not exist" - kubectl delete --all pvc --grace-period=0 --force --namespace "cbci" - kubectl delete --all pvc --grace-period=0 --force --namespace "cbcd" - kubectl delete ns "cbci-agents" || echo "There is NOT existing namespace cbci-agents" - kubectl delete ns "cbci" || echo "There is not existing namespace cbci" - kubectl delete ns "cbcd" || echo "There is not existing namespace cbcd" -endef - .PHONY: helmfile-update helmfile-update: ## Install/Update CloudBees Core Modern via Helmfile. -helmfile-update: check_kubeconfig +helmfile-update: @rm -f $(HELM_LOG_PATH) + cd $(CD_MAKEFOLDER) && make cdCreateDBRemotely helmfile --debug --file $(DIR_HELMFILES)/sda.eks.alb.helmfile.yml --interactive apply | tee -a $(HELM_LOG_PATH) -.PHONY: purge_pods -purge_pods: -purge_pods: #Purge Pods in cbci and cbci-agents namespaces - kubectl delete --all pods --grace-period=0 --force --namespace "cbcd" - kubectl delete --all pods --grace-period=0 --force --namespace "cbci" - kubectl delete --all pods --grace-period=0 --force --namespace "cbci-agents" - .PHONY: helmfile-delete helmfile-delete: ## Helmfile Delete -helmfile-delete: check_kubeconfig purge_pods +helmfile-delete: check_kubeconfig @rm -f $(HELM_LOG_PATH) + cd $(CI_MAKEFOLDER) && make ciHelm-delete + cd $(CD_MAKEFOLDER) && make cdDeleteAllDBRemote helmfile --debug --file $(DIR_HELMFILES)/sda.eks.alb.helmfile.yml destroy | tee -a $(HELM_LOG_PATH) - $(call postHelmDelete)