deploy.sh 3.08 KB
Newer Older
snehal jagtap's avatar
snehal jagtap committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash

declare -A envVars=( ["BUILD_BUILDNUMBER"]=$BUILD_BUILDNUMBER ["GOOGLE_PROJECT_NAME"]=$GOOGLE_PROJECT_NAME ["CONTAINER_REGISTRY_NAME"]=$CONTAINER_REGISTRY_NAME
                     ["COMPUTE_ZONE"]=$COMPUTE_ZONE ["CLUSTER_NAME"]=$CLUSTER_NAME ["CLUSTER_TYPE"]=$CLUSTER_TYPE ["SOURCE_CONTAINER_REGISTRY_NAME"]=$SOURCE_CONTAINER_REGISTRY_NAME )

declare -a missingEnvVars
declare -a imageList
for key in ${!envVars[@]}
do
    if [[ -z ${envVars[${key}]} ]]
    then
        missingEnvVars+=(${key})
    fi
done

if [ ${#missingEnvVars[@]} -gt 0 ]
then
    joined=$(printf ", %s" "${missingEnvVars[@]}")
    echo "Missing ${joined:1}"
    exit 1
fi

if [ ${CLUSTER_TYPE} == 'Zonal' ]; then
  gcloud container clusters get-credentials ${CLUSTER_NAME} --zone ${COMPUTE_ZONE}
elif [ ${CLUSTER_TYPE} == "Regional" ]; then
  export CLOUDSDK_CONTAINER_USE_V1_API_CLIENT=false && export CLOUDSDK_CONTAINER_USE_V1_API=false && gcloud beta container clusters get-credentials ${CLUSTER_NAME} --region ${COMPUTE_ZONE} --project ${GOOGLE_PROJECT_NAME}
fi
kubectl cluster-info --token=`gcloud auth application-default print-access-token` --cluster=gke_${GOOGLE_PROJECT_NAME}_${COMPUTE_ZONE}_${CLUSTER_NAME}

imageList=$(gcloud container images list-tags gcr.io/${CONTAINER_REGISTRY_NAME}/ingestion-pipeline --filter=${BUILD_BUILDNUMBER} --format=text)
if [ -z "${imageList[0]}" ]; then
     gcloud container images -q add-tag gcr.io/${SOURCE_CONTAINER_REGISTRY_NAME}/ingestion-pipeline:${BUILD_BUILDNUMBER} gcr.io/${CONTAINER_REGISTRY_NAME}/ingestion-pipeline:${BUILD_BUILDNUMBER}
     gcloud container images -q add-tag gcr.io/${SOURCE_CONTAINER_REGISTRY_NAME}/timeseries-backup:${BUILD_BUILDNUMBER} gcr.io/${CONTAINER_REGISTRY_NAME}/timeseries-backup:${BUILD_BUILDNUMBER}
     if [ `echo $?` == 1 ]; then
        echo "Error occured while copying image"
        exit 1
     fi
else
       echo "Image already exist(s)"
fi

sed -i -e "s/IMAGE_NAME/gcr.io\/${CONTAINER_REGISTRY_NAME}\/ingestion-pipeline:${BUILD_BUILDNUMBER}/g" ingestion-pipeline-deployment.yml
sed -i -e "s/IMAGE_NAME/gcr.io\/${CONTAINER_REGISTRY_NAME}\/timeseries-backup:${BUILD_BUILDNUMBER}/g" backup-cronjob.yaml

sed -i -e "s/ENV_TAG/${CLUSTER_NAME}/g" backup-cronjob.yaml
sed -i -e "s/GLOBAL_GOOGLE_PROJECT_NAME/${GLOBAL_GOOGLE_PROJECT_NAME}/g" backup-cronjob.yaml


if [ "`kubectl get secrets -l name=ingestion-pipeline 2>/dev/null | wc -l`" -gt "0" ]; then
  declare -a config_list=(`kubectl get secrets -l name=ingestion-pipeline --sort-by=.metadata.creationTimestamp -o jsonpath={.items[*].metadata.name}`)
  current_config_name=`echo ${config_list[-1]}`
  sed -i -e  "s/CONFIGNAME/$current_config_name/g" ingestion-pipeline-deployment.yml
else
  echo "Configs for this deployment are required and does not exist. Kindly create one"
fi

kubectl apply -f backup-cronjob.yaml --cluster=gke_${GOOGLE_PROJECT_NAME}_${COMPUTE_ZONE}_${CLUSTER_NAME}
kubectl apply -f ingestion-pipeline-deployment.yml --cluster=gke_${GOOGLE_PROJECT_NAME}_${COMPUTE_ZONE}_${CLUSTER_NAME}
kubectl apply -f timeseries-ingestion-service.yaml
kubectl delete hpa osdu-cloud-data-ingestion --ignore-not-found=true