Feature 8170: deploy OSM services with a helm chart
[osm/devops.git] / installers / install_ngsa.sh
1 #!/bin/bash
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15
16 set +eux
17
18 # Helm chart 1.6.0 correspondes to Airflow 2.3.0
19 AIRFLOW_HELM_VERSION=1.9.0
20 PROMPUSHGW_HELM_VERSION=1.18.2
21 ALERTMANAGER_HELM_VERSION=0.22.0
22
23 # Install Airflow helm chart
24 function install_airflow() {
25 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
26 # copy airflow-values.yaml to the destination folder
27 sudo mkdir -p ${OSM_HELM_WORK_DIR}
28 sudo cp ${OSM_DEVOPS}/installers/helm/values/airflow-values.yaml ${OSM_HELM_WORK_DIR}
29 # update airflow-values.yaml to use the right tag
30 echo "Updating Helm values file helm/values/airflow-values.yaml to use defaultAirflowTag: ${OSM_DOCKER_TAG}"
31 sudo sed -i "s#defaultAirflowTag:.*#defaultAirflowTag: ${OSM_DOCKER_TAG}#g" ${OSM_HELM_WORK_DIR}/airflow-values.yaml
32 echo "Updating Helm values file helm/values/airflow-values.yaml to use defaultAirflowRepository: ${DOCKER_REGISTRY_URL}${DOCKER_USER}/airflow"
33 sudo sed -i "s#defaultAirflowRepository:.*#defaultAirflowRepository: ${DOCKER_REGISTRY_URL}${DOCKER_USER}/airflow#g" ${OSM_HELM_WORK_DIR}/airflow-values.yaml
34
35 if ! helm -n osm status airflow 2> /dev/null ; then
36 # if it does not exist, create secrets and install
37 kubectl -n osm create secret generic airflow-webserver-secret --from-literal="webserver-secret-key=$(python3 -c 'import secrets; print(secrets.token_hex(16))')"
38 helm repo add apache-airflow https://airflow.apache.org
39 helm repo update
40 helm -n osm install airflow apache-airflow/airflow -f ${OSM_HELM_WORK_DIR}/airflow-values.yaml --version ${AIRFLOW_HELM_VERSION}
41 else
42 # if it exists, upgrade
43 helm repo update
44 helm -n osm upgrade airflow apache-airflow/airflow -f ${OSM_HELM_WORK_DIR}/airflow-values.yaml --version ${AIRFLOW_HELM_VERSION}
45 fi
46 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
47 }
48
49 # Install Prometheus Pushgateway helm chart
50 function install_prometheus_pushgateway() {
51 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
52 if ! helm -n osm status pushgateway 2> /dev/null ; then
53 # if it does not exist, install
54 helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
55 helm repo update
56 helm -n osm install pushgateway prometheus-community/prometheus-pushgateway --version ${PROMPUSHGW_HELM_VERSION}
57 else
58 # if it exists, upgrade
59 helm repo update
60 helm -n osm upgrade pushgateway prometheus-community/prometheus-pushgateway --version ${PROMPUSHGW_HELM_VERSION}
61 fi
62 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
63 }
64
65 # Install Prometheus AlertManager helm chart
66 function install_prometheus_alertmanager() {
67 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
68 # copy alertmanager-values.yaml to the destination folder
69 sudo mkdir -p ${OSM_HELM_WORK_DIR}
70 sudo cp ${OSM_DEVOPS}/installers/helm/values/alertmanager-values.yaml ${OSM_HELM_WORK_DIR}
71 if ! helm -n osm status alertmanager 2> /dev/null ; then
72 # if it does not exist, install
73 helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
74 helm repo update
75 helm -n osm install alertmanager prometheus-community/alertmanager -f ${OSM_HELM_WORK_DIR}/alertmanager-values.yaml --version ${ALERTMANAGER_HELM_VERSION}
76 else
77 # if it exists, upgrade
78 helm repo update
79 helm -n osm upgrade alertmanager prometheus-community/alertmanager -f ${OSM_HELM_WORK_DIR}/alertmanager-values.yaml --version ${ALERTMANAGER_HELM_VERSION}
80 fi
81 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
82 }
83
84 # main
85
86 DOCKER_REGISTRY_URL=
87 DOCKER_USER="opensourcemano"
88 OSM_DEVOPS="/usr/share/osm-devops"
89 OSM_DOCKER_TAG="13"
90 OSM_HELM_WORK_DIR="/etc/osm/helm"
91
92 while getopts ":D:d:t:r:U:-: " o; do
93 case "${o}" in
94 D)
95 OSM_DEVOPS="${OPTARG}"
96 ;;
97 d)
98 OSM_HELM_WORK_DIR="${OPTARG}"
99 ;;
100 t)
101 OSM_DOCKER_TAG="${OPTARG}"
102 ;;
103 r)
104 DOCKER_REGISTRY_URL="${OPTARG}"
105 ;;
106 U)
107 DOCKER_USER="${OPTARG}"
108 ;;
109 -)
110 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="y" && continue
111 echo -e "Invalid option: '--$OPTARG'\n" >&2
112 exit 1
113 ;;
114 :)
115 echo "Option -$OPTARG requires an argument" >&2
116 exit 1
117 ;;
118 \?)
119 echo -e "Invalid option: '-$OPTARG'\n" >&2
120 exit 1
121 ;;
122 *)
123 exit 1
124 ;;
125 esac
126 done
127
128 source $OSM_DEVOPS/common/logging
129 source $OSM_DEVOPS/common/track
130
131 echo "DEBUG_INSTALL=$DEBUG_INSTALL"
132 echo "OSM_DEVOPS=$OSM_DEVOPS"
133 echo "OSM_DOCKER_TAG=$OSM_DOCKER_TAG"
134 echo "OSM_HELM_WORK_DIR=$OSM_HELM_WORK_DIR"
135
136 install_airflow
137 track deploy_osm airflow_ok
138 install_prometheus_pushgateway
139 track deploy_osm pushgateway_ok
140 install_prometheus_alertmanager
141 track deploy_osm alertmanager_ok
142