c0c5ed04aea7563cf4f90b561730b2a28c07702a
[it/dep.git] / infra / 10-Nexus / bin / install
1 #!/bin/bash
2 ################################################################################
3 #   Copyright (c) 2019 AT&T Intellectual Property.                             #
4 #   Copyright (c) 2019 Nokia.                                                  #
5 #                                                                              #
6 #   Licensed under the Apache License, Version 2.0 (the "License");            #
7 #   you may not use this file except in compliance with the License.           #
8 #   You may obtain a copy of the License at                                    #
9 #                                                                              #
10 #       http://www.apache.org/licenses/LICENSE-2.0                             #
11 #                                                                              #
12 #   Unless required by applicable law or agreed to in writing, software        #
13 #   distributed under the License is distributed on an "AS IS" BASIS,          #
14 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
15 #   See the License for the specific language governing permissions and        #
16 #   limitations under the License.                                             #
17 ################################################################################
18
19 OVERRIDEYAML=$1
20
21
22 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
23 source $DIR/../etc/nexus.conf
24
25 if [ -z "$RICINFRA_RELEASE_NAME" ];then
26    RELEASE_NAME=$helm_release_name
27 else
28    RELEASE_NAME=$RICINFRA_RELEASE_NAME
29 fi
30 if [ -z "$RICINFRA_NAMESPACE" ];then
31    NAMESPACE=$namespace
32 else
33    NAMESPACE=$RICINFRA_NAMESPACE
34 fi
35 if [ -z "$INGRESS_PORT" ];then
36    INGRESS_PORT_NEXUS=$ingress_port
37 else
38    INGRESS_PORT_NEXUS=$INGRESS_PORT
39 fi
40
41
42
43 echo "Deploying nexus repo managers for local docker registry and helm repo."
44 echo "Name Space: $NAMESPACE"
45 echo "Helm Release: $RELEASE_NAME"
46
47 HOSTPOSTFIX=$(cat $DIR/../helm/values.yaml  | grep hostpostfix | awk '{print $2}')
48
49
50 echo "****************************************************************************************************************"
51 echo "                                                     WARNING                                                    "
52 echo "****************************************************************************************************************"
53
54 echo "Nexus is deployed using default admin password. It is not for production deployment."
55 echo "If you want to secure the repositories, you should change the admin password immediately."
56 echo "You can access this nexus here: http://nexus.$HOSTPOSTFIX:$INGRESS_PORT_NEXUS"
57 echo "If nexus.$HOSTPOSTFIX is not resolved by your DNS server, please add an entry in your /etc/hosts file."
58 echo "****************************************************************************************************************"
59
60 COMMON_CHART_VERSION=$(cat $DIR/../../../ric-platform/50-RIC-Platform/helm/common/Chart.yaml | grep version | awk '{print $2}')
61 helm package -d /tmp $DIR/../../../ric-platform/50-RIC-Platform/helm/common
62
63
64 mkdir -p  $DIR/../helm/charts/
65 cp /tmp/common-$COMMON_CHART_VERSION.tgz $DIR/../helm/charts/
66
67 if [ -z $OVERRIDEYAML ]; then
68 helm install --namespace "${NAMESPACE}" --name "${RELEASE_NAME}-nexus" $DIR/../helm
69 else
70 helm install -f $OVERRIDEYAML --namespace "${NAMESPACE}" --name "${RELEASE_NAME}-nexus" $DIR/../helm
71 fi
72
73 NEXUS_POD_NAME=$(kubectl get pod -n $NAMESPACE | grep nexus | grep ContainerCreating | awk '{print $1}')
74
75
76
77 echo "Waiting Nexus to be ready."
78 echo " "
79
80 sleep 10
81
82 IS_NEXUS_READY=$(kubectl logs -n $NAMESPACE $NEXUS_POD_NAME | grep "Started Sonatype Nexus OSS")
83
84 COUNTER=1
85 while [[ -z $IS_NEXUS_READY ]]; do
86         echo -e "\033[2AWaiting Nexus to be ready."
87         echo -e "\033[2K"
88         PROGRESS=$(printf "%0.s-" $(seq 1 $COUNTER))
89         echo -e "\033[1A$PROGRESS"
90
91
92         COUNTER=$((COUNTER+1))
93         if [ $COUNTER -gt 5 ]; then
94                 COUNTER=1
95         fi
96
97         IS_NEXUS_READY=$(kubectl logs -n $NAMESPACE $NEXUS_POD_NAME | grep "Started Sonatype Nexus OSS")
98
99         sleep 5
100 done
101
102 echo $IS_NEXUS_READY
103
104
105 DOCKERPORT=$(cat $DIR/../helm/templates/deployment.yaml  | awk '/.*- name: docker.*/{getline; print $2}')
106
107
108 DOCKERREPOSCRIPT="{\"name\":\"create_docker_repo\",\
109     \"type\":\"groovy\",\
110     \"content\":\"repository.createDockerHosted('docker.snapshot',\
111     $DOCKERPORT, null, 'default', false, true)\"}"
112
113 echo $DOCKERREPOSCRIPT
114
115 # This line uses the default admin password
116 curl -u admin:admin123 -X POST -H "Content-Type: application/json" --data "$DOCKERREPOSCRIPT" http://nexus.$HOSTPOSTFIX:$INGRESS_PORT_NEXUS/service/rest/v1/script
117
118 curl -u admin:admin123 -X POST -H 'Content-Type: text/plain' -H 'Accept: application/json' http://nexus.$HOSTPOSTFIX:$INGRESS_PORT_NEXUS/service/rest/v1/script/create_docker_repo/run
119
120
121
122
123
124