Skip to content

Commit

Permalink
[PCP-9347] externalize/enhance TP setup automation (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
syan-tibco authored Jan 30, 2025
1 parent a02f235 commit 6a921fb
Show file tree
Hide file tree
Showing 18 changed files with 752 additions and 252 deletions.
2 changes: 1 addition & 1 deletion charts/provisioner-config-local/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apiVersion: v2
name: provisioner-config-local
description: Platform Provisioner local config
type: application
version: "1.1.16"
version: "1.1.19"
appVersion: "2.0.0"
home: https://github.com/TIBCOSoftware/tp-helm-charts
maintainers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ meta:

# CP version see: https://docs.tibco.com/pub/platform-cp/1.3.0/doc/html/Default.htm#Installation/helm-chart-version-matrix.htm
GUI_CP_PLATFORM_BOOTSTRAP_VERSION: 1.3.53
GUI_CP_PLATFORM_BASE_VERSION: 1.3.437
GUI_CP_PLATFORM_BASE_VERSION: 1.3.439 # HF4

# CP env
GUI_CP_INSTANCE_ID: "cp1"
Expand Down
55 changes: 49 additions & 6 deletions charts/provisioner-config-local/recipes/tp-automation-o11y.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ meta:
GUI_TP_AUTO_CP_VERSION: "" # keep it empty, unless you see an error with GUI_TP_AUTO_CP_VERSION in the logs
GUI_TP_AUTO_USE_LOCAL_SCRIPT: false
GUI_TP_AUTO_USE_GITHUB_SCRIPT: true
GUI_TP_AUTO_SCREENSHOT_PATH: "/tmp/auto/screenshots"
GUI_TP_AUTO_REPORT_PATH: "/tmp/auto/report"
GUI_TP_AUTO_GITHUB_REPO_NAME: "github.com/TIBCOSoftware/platform-provisioner"
GUI_TP_AUTO_GITHUB_REPO_PATH: "docs/recipes/automation/tp-setup/bootstrap"
GUI_TP_AUTO_GITHUB_REPO_BRANCH: "provisioner-config-local-1.1.16"
GUI_TP_AUTO_GITHUB_REPO_BRANCH: "provisioner-config-local-{{ .Chart.Version }}"

# DP capabilities deployment
GUI_TP_AUTO_ACTIVE_USER: true
Expand Down Expand Up @@ -56,6 +56,7 @@ meta:
GUI_TP_AUTO_K8S_DP_NAMESPACE: "k8s-auto-dp1ns"
GUI_TP_AUTO_K8S_DP_SERVICE_ACCOUNT: "k8s-auto-dp1sa"
GUI_TP_AUTO_INGRESS_CONTROLLER: "nginx"
GUI_TP_AUTO_INGRESS_CONTROLLER_CLASS_NAME: "nginx"
GUI_TP_AUTO_STORAGE_CLASS: "hostpath"

# DP o11y setup
Expand Down Expand Up @@ -87,10 +88,11 @@ meta:
TP_AUTO_USE_LOCAL_SCRIPT: ${GUI_TP_AUTO_USE_LOCAL_SCRIPT:-false}
TP_AUTO_USE_GITHUB_SCRIPT: ${GUI_TP_AUTO_USE_GITHUB_SCRIPT:-true}
TP_AUTO_SCRIPT_FOLDER: ${GUI_TP_AUTO_SCRIPT_FOLDER:-"/tmp/auto"}
TP_AUTO_SCREENSHOT_PATH: ${GUI_TP_AUTO_SCREENSHOT_PATH:-"/tmp/auto/screenshots"}
TP_AUTO_REPORT_PATH: ${GUI_TP_AUTO_REPORT_PATH:-"/tmp/auto/report"}
TP_AUTO_REPORT_YAML_FILE: report.yaml
TP_AUTO_GITHUB_REPO_NAME: ${GUI_TP_AUTO_GITHUB_REPO_NAME:-"github.com/TIBCOSoftware/platform-provisioner"}
TP_AUTO_GITHUB_REPO_PATH: ${GUI_TP_AUTO_GITHUB_REPO_PATH:-"docs/recipes/automation/tp-setup/bootstrap"}
TP_AUTO_GITHUB_REPO_BRANCH: ${GUI_TP_AUTO_GITHUB_REPO_BRANCH:-"provisioner-config-local-1.1.16"}
TP_AUTO_GITHUB_REPO_BRANCH: ${GUI_TP_AUTO_GITHUB_REPO_BRANCH:-"provisioner-config-local-{{ .Chart.Version }}"}

# DP capabilities deployment
TP_AUTO_ACTIVE_USER: ${GUI_TP_AUTO_ACTIVE_USER:-true}
Expand Down Expand Up @@ -127,6 +129,7 @@ meta:
TP_AUTO_K8S_DP_NAMESPACE: ${GUI_TP_AUTO_K8S_DP_NAMESPACE:-"k8s-auto-dp1ns"}
TP_AUTO_K8S_DP_SERVICE_ACCOUNT: ${GUI_TP_AUTO_K8S_DP_SERVICE_ACCOUNT:-"k8s-auto-dp1sa"}
TP_AUTO_INGRESS_CONTROLLER: ${GUI_TP_AUTO_INGRESS_CONTROLLER:-"nginx"}
TP_AUTO_INGRESS_CONTROLLER_CLASS_NAME: ${GUI_TP_AUTO_INGRESS_CONTROLLER_CLASS_NAME:-"nginx"}
TP_AUTO_STORAGE_CLASS: ${GUI_TP_AUTO_STORAGE_CLASS:-"hostpath"}

# DP o11y setup
Expand All @@ -145,6 +148,7 @@ meta:
# flow control
PYTHON_FILE_LOGIN_POINT: page_auth.py
PYTHON_FILE_ENTRY_POINT: run.py
PYTHON_FILE_ENV_POINT: page_env.py
TP_OVERWRITE_DNS: ${GUI_TP_OVERWRITE_DNS:-false}
TP_PORT_FORWARD: ${GUI_TP_PORT_FORWARD:-true}
tasks:
Expand Down Expand Up @@ -190,8 +194,6 @@ tasks:
content: |
cd ${TP_AUTO_SCRIPT_FOLDER}
pip install -r requirements.txt
rm -rf downloads
rm -rf screenshots
- condition: ${TP_AUTO_ACTIVE_USER} # only create admin and subscription
clusters:
- name: ${TP_CLUSTER_NAME}
Expand All @@ -200,6 +202,20 @@ tasks:
fileName: script.sh
content: |
cd ${TP_AUTO_SCRIPT_FOLDER}
_report_file="${TP_AUTO_REPORT_PATH}/${TP_AUTO_REPORT_YAML_FILE}"
if [[ -f "$_report_file" ]]; then
if [[ "$(yq '.ENV.REPORT_AUTO_ACTIVE_USER' "$_report_file")" == "true" ]]; then
echo "----------------------------------------------------------------"
echo "ENV.REPORT_AUTO_ACTIVE_USER is true. User has been active. Exiting..."
echo "----------------------------------------------------------------"
exit 0
else
echo "_report_file: ${_report_file}"
cat "$_report_file"
fi
fi
python ${PYTHON_FILE_LOGIN_POINT}
_result=$?
echo "python return code: ${_result}"
Expand All @@ -213,6 +229,21 @@ tasks:
content: |
export TP_AUTO_IS_CREATE_DP=${TP_AUTO_ENABLE_DP}
cd ${TP_AUTO_SCRIPT_FOLDER}
_report_file="${TP_AUTO_REPORT_PATH}/${TP_AUTO_REPORT_YAML_FILE}"
if [[ -f "$_report_file" ]]; then
# Get all dataPlane.name and concatenate them into a,b,c format
dp_names=$(yq '.dataPlane[].name' "$_report_file" | tr '\n' ',' | sed 's/,$//')
if [[ -n "$dp_names" ]]; then
echo "----------------------------------------------------------------"
echo "dataPlane[$dp_names] already exists. Exiting..."
echo "----------------------------------------------------------------"
exit 0
else
echo "_report_file: ${_report_file}"
cat "$_report_file"
fi
fi
python ${PYTHON_FILE_ENTRY_POINT}
_result=$?
echo "python return code: ${_result}"
Expand Down Expand Up @@ -282,3 +313,15 @@ tasks:
_result=$?
echo "python return code: ${_result}"
exit ${_result}
- condition: true
clusters:
- name: ${TP_CLUSTER_NAME}
script:
ignoreErrors: false
fileName: script.sh
content: |
cd ${TP_AUTO_SCRIPT_FOLDER}
python ${PYTHON_FILE_ENV_POINT}
_result=$?
echo "python return code: ${_result}"
exit ${_result}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ meta:
GUI_TP_DB_PASSWORD: postgres
GUI_TP_DB_NAME: postgres
GUI_TP_DB_TLS_ENABLED: false
GUI_TP_INSTALL_PROVISIONER_UI: true
GUI_TP_INSTALL_PROVISIONER_UI: false
GUI_TP_INSTALL_CERT_MANAGER: true
GUI_TP_INSTALL_METRICS_SERVER: true
GUI_PIPELINE_LOG_DEBUG: false
Expand Down
3 changes: 2 additions & 1 deletion dev/platform-provisioner-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ cd "${DEV_PATH}" || exit

# default network is host
[[ -z "${PIPELINE_CONTAINER_NETWORK}" ]] && export PIPELINE_CONTAINER_NETWORK="host"
[[ -z "${PIPELINE_CONTAINER_TTY}" ]] && export PIPELINE_CONTAINER_TTY="-it"

[[ -z "${PIPELINE_INPUT_RECIPE}" ]] && export PIPELINE_INPUT_RECIPE="recipe.yaml"
[[ -z "${PIPELINE_TRIGGER_RUN_SH}" ]] && export PIPELINE_TRIGGER_RUN_SH="true"
Expand Down Expand Up @@ -135,7 +136,7 @@ export PIPELINE_INPUT_RECIPE_CONTENT=""
echo "Using platform provisioner docker image: ${PIPELINE_DOCKER_IMAGE}"

# is used to export functions; so subshell can use it
docker run -it --rm \
docker run "${PIPELINE_CONTAINER_TTY}" --rm \
--name provisioner-pipeline-task \
--net "${PIPELINE_CONTAINER_NETWORK}" \
-e ACCOUNT \
Expand Down
3 changes: 2 additions & 1 deletion dev/platform-provisioner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export PIPELINE_CMD_NAME_YQ="${PIPELINE_CMD_NAME_YQ:-yq4}"

# default network is host
[[ -z "${PIPELINE_CONTAINER_NETWORK}" ]] && export PIPELINE_CONTAINER_NETWORK="host"
[[ -z "${PIPELINE_CONTAINER_TTY}" ]] && export PIPELINE_CONTAINER_TTY="-it"

[[ -z "${PIPELINE_INPUT_RECIPE}" ]] && export PIPELINE_INPUT_RECIPE="recipe.yaml"
[[ -z "${PIPELINE_TRIGGER_RUN_SH}" ]] && export PIPELINE_TRIGGER_RUN_SH="true"
Expand Down Expand Up @@ -127,7 +128,7 @@ export PIPELINE_INPUT_RECIPE_CONTENT=""
echo "Using platform provisioner docker image: ${PIPELINE_DOCKER_IMAGE}"

# is used to export functions; so subshell can use it
docker run -it --rm \
docker run "${PIPELINE_CONTAINER_TTY}" --rm \
--name provisioner-pipeline-task \
--net "${PIPELINE_CONTAINER_NETWORK}" \
-e ACCOUNT \
Expand Down
51 changes: 30 additions & 21 deletions docs/recipes/automation/on-perm/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
# On-Premises automation
# On-Premises setup automation

The goal of this automation is to create full running TP on-perm environment from scratch with one script.

In the on-perm use case; we assume there will be a on-perm cluster running. The default target is Docker for Desktop.
In the on-perm use case; we assume there will be an on-perm cluster running. The default target is Docker for Desktop.

## Setup flow

### 1. Generate recipe from provisioner-config-local helm chart
```bash
./generate-recipe.sh 1 1
```

### 2. Adjust recipe for your k8s environment
```bash
# choose the environment you will deploy to
./adjust-recipe.sh
```

### 3. (Optional) Update recipe tokens
```bash
./update-recipe-tokens.sh
```

### 4. Install the full TP on-perm environment
Before trigger the run.sh script; you can manually set TP versions that you want to install on 02-tp-cp-on-perm.yaml file.
```bash
./run.sh 1
```

## What happens in the run.sh script?
Basically the `run.sh` script will:
* Deploy on-perm tools like ingress, Postgres
* Deploy TIBCO Platform Control Plane
Expand All @@ -13,24 +38,8 @@ Basically the `run.sh` script will:
* Deploy a DP
* Deploy a capability

We can copy the following recipes from provisioner GUI.
```
01-tp-on-perm.yaml
02-tp-cp-on-perm.yaml
03-tp-adjust-dns.yaml
04-tp-adjust-resource.yaml
05-tp-auto-deploy-dp.yaml
```

Or use the `generate-recipe.sh` script to generate the skeleton and manually modify. (Adding tokens and certificates)


## Local development process for python automation

* Use local repo to generate recipe
* Deploy CP subscription (Admin, sub user, DP, app, etc.)

```shell
export GITHUB_TOKEN=""
./generate-recipe.sh 2 && ./run.sh 4
```
* Use local repo to generate recipe `./generate-recipe.sh 2 1`
* Deploy CP subscription normally `./run.sh 1`
* In this case the setup automation will mount `../tp-setup/bootstrap/` folder to the automation container. So you can edit the python automation code in your local machine and run the automation script in the container.
60 changes: 56 additions & 4 deletions docs/recipes/automation/on-perm/adjust-recipe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,30 @@
# All Rights Reserved. Confidential & Proprietary.
#

#######################################
# adjust-recipe.sh: this script will adjust the recipe for deploying TP on-prem for different k8s environments
# Globals:
# None
# Arguments:
# 1 - 4: the choice of the environment
# Returns:
# None
# Notes:
# Ideally we should use ./generate-recipe.sh to generate the recipe first before adjusting it.
# Samples:
# ./adjust-recipe.sh 1
#######################################

# This script will generate the recipe for deploying TP on-prem
function adjust_recipes() {
local choice="${1:-""}"
while true; do
if [[ -z $choice ]]; then
echo "Please select an option:"
echo "1. Adjust for k3s"
echo "2. Adjust for openshift"
echo "3. Exit"
echo "2. Adjust for OpenShift"
echo "3. Adjust for Docker Desktop"
echo "4. Exit"
read -rp "Enter your choice (1-3): " choice
fi

Expand All @@ -39,6 +54,7 @@ function adjust_recipes() {
_recipe_file_name="04-tp-adjust-resource.yaml"
if [[ -f "${_recipe_file_name}" ]]; then
yq eval -i '(.meta.guiEnv.GUI_TASK_REMOVE_RESOURCES = false)' "$_recipe_file_name"
yq eval -i '(.meta.guiEnv.GUI_TASK_SHOW_RESOURCES = false)' "$_recipe_file_name"
fi

_recipe_file_name="05-tp-auto-deploy-dp.yaml"
Expand Down Expand Up @@ -76,6 +92,7 @@ function adjust_recipes() {
_recipe_file_name="04-tp-adjust-resource.yaml"
if [[ -f "${_recipe_file_name}" ]]; then
yq eval -i '(.meta.guiEnv.GUI_TASK_REMOVE_RESOURCES = false)' "$_recipe_file_name"
yq eval -i '(.meta.guiEnv.GUI_TASK_SHOW_RESOURCES = false)' "$_recipe_file_name"
fi

_recipe_file_name="05-tp-auto-deploy-dp.yaml"
Expand All @@ -92,6 +109,43 @@ function adjust_recipes() {
break
;;
3)
echo "Adjusting for Docker Desktop..."
_recipe_file_name="01-tp-on-perm.yaml"
export TP_STORAGE_CLASS="hostpath"
if [[ -f "${_recipe_file_name}" ]]; then
yq eval -i '(.meta.guiEnv.GUI_TP_INGRESS_SERVICE_TYPE = "LoadBalancer")' "$_recipe_file_name"
yq eval -i '(.meta.guiEnv.GUI_TP_STORAGE_CLASS = env(TP_STORAGE_CLASS))' "$_recipe_file_name"
yq eval -i '(.meta.guiEnv.GUI_TP_STORAGE_CLASS_FOR_NFS_SERVER_PROVISIONER = env(TP_STORAGE_CLASS))' "$_recipe_file_name"
yq eval -i '(.meta.guiEnv.GUI_TP_INSTALL_NFS_SERVER_PROVISIONER = false)' "$_recipe_file_name"
yq eval -i '(.meta.guiEnv.GUI_TP_INSTALL_METRICS_SERVER = true)' "$_recipe_file_name"
yq eval -i '(.meta.guiEnv.GUI_TP_INSTALL_PROVISIONER_UI = false)' "$_recipe_file_name"
fi

_recipe_file_name="02-tp-cp-on-perm.yaml"
if [[ -f "${_recipe_file_name}" ]]; then
yq eval -i '(.meta.guiEnv.GUI_CP_STORAGE_CLASS = "hostpath")' "$_recipe_file_name"
fi

_recipe_file_name="04-tp-adjust-resource.yaml"
if [[ -f "${_recipe_file_name}" ]]; then
yq eval -i '(.meta.guiEnv.GUI_TASK_REMOVE_RESOURCES = true)' "$_recipe_file_name"
yq eval -i '(.meta.guiEnv.GUI_TASK_SHOW_RESOURCES = false)' "$_recipe_file_name"
fi

_recipe_file_name="05-tp-auto-deploy-dp.yaml"
if [[ -f "${_recipe_file_name}" ]]; then
yq eval -i '(.meta.guiEnv.GUI_TP_AUTO_USE_LOCAL_SCRIPT = false)' ${_recipe_file_name}
yq eval -i '(.meta.guiEnv.GUI_TP_AUTO_USE_GITHUB_SCRIPT = true)' ${_recipe_file_name}
yq eval -i '(.meta.guiEnv.GUI_TP_AUTO_STORAGE_CLASS = env(TP_STORAGE_CLASS))' ${_recipe_file_name}
fi

_recipe_file_name="06-tp-o11y-stack.yaml"
if [[ -f "${_recipe_file_name}" ]]; then
yq eval -i '(.meta.guiEnv.GUI_TP_STORAGE_CLASS = env(TP_STORAGE_CLASS))' "$_recipe_file_name"
fi
break
;;
4)
echo "Exiting..."
break
;;
Expand All @@ -102,11 +156,9 @@ function adjust_recipes() {
done
}


# main function
function main() {
adjust_recipes "$@"
}

main "$@"

Loading

0 comments on commit 6a921fb

Please sign in to comment.