Update tag to be used by airflow image when installing NGSA
[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.6.0
20 PROMPUSHGW_HELM_VERSION=1.18.2
21
22 # Install Airflow helm chart
23 function install_airflow() {
24 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
25 # copy airflow-values.yaml to the destination folder
26 sudo mkdir -p ${OSM_HELM_WORK_DIR}
27 sudo cp ${OSM_DEVOPS}/installers/helm/values/airflow-values.yaml ${OSM_HELM_WORK_DIR}
28 # update airflow-values.yaml to use the right tag
29 echo "Updating Helm values file helm/values/airflow-values.yaml to use defaultAirflowTag: ${OSM_DOCKER_TAG}"
30 sudo sed -i "s#defaultAirflowTag:.*#defaultAirflowTag: ${OSM_DOCKER_TAG}#g" ${OSM_HELM_WORK_DIR}/airflow-values.yaml
31 if ! helm -n osm status airflow 2> /dev/null ; then
32 # if it does not exist, create secrets and install
33 kubectl -n osm create secret generic airflow-webserver-secret --from-literal="webserver-secret-key=$(python3 -c 'import secrets; print(secrets.token_hex(16))')"
34 helm repo add apache-airflow https://airflow.apache.org
35 helm repo update
36 helm -n osm install airflow apache-airflow/airflow -f ${OSM_HELM_WORK_DIR}/airflow-values.yaml --version ${AIRFLOW_HELM_VERSION}
37 else
38 # if it exists, upgrade
39 helm repo update
40 helm -n osm upgrade airflow apache-airflow/airflow -f ${OSM_HELM_WORK_DIR}/airflow-values.yaml --version ${AIRFLOW_HELM_VERSION}
41 fi
42 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
43 }
44
45 # Install Prometheus Pushgateway helm chart
46 function install_prometheus_pushgateway() {
47 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
48 if ! helm -n osm status pushgateway 2> /dev/null ; then
49 # if it does not exist, install
50 helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
51 helm repo update
52 helm -n osm install pushgateway prometheus-community/prometheus-pushgateway --version ${PROMPUSHGW_HELM_VERSION}
53 else
54 # if it exists, upgrade
55 helm repo update
56 helm -n osm upgrade pushgateway prometheus-community/prometheus-pushgateway --version ${PROMPUSHGW_HELM_VERSION}
57 fi
58 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
59 }
60
61 # main
62
63 OSM_DEVOPS="/usr/share/osm-devops"
64 OSM_HELM_WORK_DIR="/etc/osm/helm"
65 OSM_DOCKER_TAG="13"
66
67 while getopts ":D:d:t:-: " o; do
68 case "${o}" in
69 D)
70 OSM_DEVOPS="${OPTARG}"
71 ;;
72 d)
73 OSM_HELM_WORK_DIR="${OPTARG}"
74 ;;
75 t)
76 OSM_DOCKER_TAG="${OPTARG}"
77 ;;
78 -)
79 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="y" && continue
80 echo -e "Invalid option: '--$OPTARG'\n" >&2
81 exit 1
82 ;;
83 :)
84 echo "Option -$OPTARG requires an argument" >&2
85 exit 1
86 ;;
87 \?)
88 echo -e "Invalid option: '-$OPTARG'\n" >&2
89 exit 1
90 ;;
91 *)
92 exit 1
93 ;;
94 esac
95 done
96
97 source $OSM_DEVOPS/common/logging
98 source $OSM_DEVOPS/common/track
99
100 echo "DEBUG_INSTALL=$DEBUG_INSTALL"
101 echo "OSM_DEVOPS=$OSM_DEVOPS"
102 echo "OSM_DOCKER_TAG=$OSM_DOCKER_TAG"
103 echo "OSM_HELM_WORK_DIR=$OSM_HELM_WORK_DIR"
104
105 install_airflow
106 track deploy_osm airflow_ok
107 install_prometheus_pushgateway
108 track deploy_osm pushgateway_ok
109