Merge "[1707-OS] Updated license text according to the"
[sdc.git] / sdc-os-chef / scripts / docker_build.sh
1 #!/bin/bash
2 #set -x
3
4
5 function usage
6 {
7     echo "usage: docker_run.sh [ -r|--release <RELEASE-NAME> ]  [ -e|--environment <ENV-NAME> ] [ -p|--port <Docker-hub-port>] [ -h|--help ]"
8 }
9
10
11 function print_log () {
12     funcname=$1
13     lineno=$2
14     sev=$3
15     msg=$4
16     dd=`date +"%Y-%m-%d %H:%M:%S"`
17     case ${sev} in
18        "INFO")
19           COLOR="\033[1;32m"             # GREEN
20           ;;
21        "ERROR")
22           COLOR="\033[1;31m"             # RED
23           ;;
24     esac
25     echo -e "$dd: $fname, $funcname:$lineno --- ${COLOR} $msg\e[0m" |tee -a $LOG
26
27 }
28
29
30
31 function conf_proxy () {
32    grep http_proxy Dockerfile || /bin/sed -i '/FROM/a ARG http_proxy=http://one.proxy.att.com:8080\nARG https_proxy=http://one.proxy.att.com:8080' Dockerfile
33 }
34
35 ###################################
36 #########   Parameters    #########
37 ###################################
38
39 WORKSPACE=$1
40 WORK_DIR=/data/sdc-os-chef
41 LOGFILE=`basename $0|awk -F. '{print $1".log"}'`
42 LOG=$WORK_DIR/$LOGFILE
43 DOCKER_REP=dockercentral.it.att.com:5100
44 ECOMP_REP=${DOCKER_REP}/com.att.sdc/openecomp
45 REL=`/usr/bin/xml_grep --text_only parent/version /data/sdc-os-chef/pom.xml`
46 DOX_VER=` /bin/grep ONBOARDING /data/sdc-os-chef/versions.properties | awk '{print $2}' | awk -F"." '{print $1}'`
47 DOX_NUM=` /bin/grep ONBOARDING /data/sdc-os-chef/versions.properties | awk '{print $2}' | awk -F"." '{print substr($NF,1,4)}' `
48 VERSION=` /bin/grep ASDC /data/sdc-os-chef/versions.properties | awk '{print $2}' `
49 MAVEN_REPO=mavencentral.it.att.com:8084/nexus/content/repositories
50 ONBOARD_GR=com/att/asdc/onboarding/${DOX_VER}/${DOX_NUM}
51
52
53 [ -f /opt/config/env_name.txt ] && DEP_ENV=$(cat /opt/config/env_name.txt) || DEP_ENV=__ENV-NAME__
54 [ -f /opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt)    || NEXUS_USERNAME=release
55 [ -f /opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt)      || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW
56 [ -f /opt/config/nexus_docker_repo.txt ] && NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt) || NEXUS_DOCKER_REPO=ecomp-nexus:${PORT}
57
58 [ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
59 #docker login -u m09875@sdc.att.com -p Aa1234%^! -e mg877n@att.com dockercentral.it.att.com:5100
60
61
62 ###################################
63 ########       MAIN        ########
64 ###################################
65 print_log Main $LINENO INFO "##### $0 completed #####"
66
67 ###################################
68 ######## sdc-elasticsearch ########
69 ###################################
70 cd /data/sdc-os-chef/sdc-elasticsearch
71 print_log Main $LINENO INFO "start creating sdc-elasticsearch ..."
72 conf_proxy
73
74 docker build -t ${ECOMP_REP}/sdc-elasticsearch:${VERSION} .
75 docker tag  ${ECOMP_REP}/sdc-elasticsearch:${VERSION} ${ECOMP_REP}/sdc-elasticsearch
76 docker push ${ECOMP_REP}/sdc-elasticsearch:${VERSION}
77 res=$?
78 if [ ${res} -eq 0 ]; then
79    print_log Main $LINENO INFO "${ECOMP_REP}/sdc-elasticsearch:${VERSION} pushed successfully"
80 else
81    print_log Main $LINENO ERROR "Error pushing ${ECOMP_REP}/sdc-elasticsearch:${VERSION}"
82 fi
83
84
85 ###################################
86 ########   sdc-cassandra   ########
87 ###################################
88 cd /data/sdc-os-chef/sdc-cassandra
89 print_log Main $LINENO INFO "start creating sdc-cassandra ..."
90
91 conf_proxy
92
93 docker build -t ${ECOMP_REP}/sdc-cassandra:${VERSION} .
94 docker tag  ${ECOMP_REP}/sdc-cassandra:$VERSION ${ECOMP_REP}/sdc-cassandra
95 docker push ${ECOMP_REP}/sdc-cassandra:$VERSION
96 res=$?
97 if [ ${res} -eq 0 ]; then
98    print_log Main $LINENO INFO "${ECOMP_REP}/sdc-cassandra:${VERSION} pushed successfully"
99 else
100    print_log Main $LINENO ERROR "Error pushing ${ECOMP_REP}/sdc-cassandra:${VERSION}"
101 fi
102
103
104
105 ###################################
106 ########    sdc-kibana     ########
107 ###################################
108 cd /data/sdc-os-chef/sdc-kibana
109 print_log Main $LINENO INFO "start creating sdc-kibana ..."
110
111 conf_proxy
112
113 docker build -t ${ECOMP_REP}/sdc-kibana:$VERSION .
114 docker tag  ${ECOMP_REP}/sdc-kibana:$VERSION   ${ECOMP_REP}/sdc-kibana
115 docker push ${ECOMP_REP}/sdc-kibana:$VERSION
116 res=$?
117 if [ ${res} -eq 0 ]; then
118    print_log Main $LINENO INFO "${ECOMP_REP}/sdc-kibana:${VERSION} pushed successfully"
119 else
120    print_log Main $LINENO ERROR "Error pushing ${ECOMP_REP}/sdc-kibana:${VERSION}"
121 fi
122
123
124 ###################################
125 ########    sdc-sanity     ########
126 ###################################
127 cd /data/sdc-os-chef/sdc-sanity
128 print_log Main $LINENO INFO "start creating sdc-sanity ..."
129
130 conf_proxy
131
132 docker build -t ${ECOMP_REP}/sdc-sanity:$VERSION .
133 docker tag  ${ECOMP_REP}/sdc-sanity:$VERSION   ${ECOMP_REP}/sdc-sanity
134 docker push ${ECOMP_REP}/sdc-sanity:$VERSION
135 res=$?
136 if [ ${res} -eq 0 ]; then
137    print_log Main $LINENO INFO "${ECOMP_REP}/sdc-sanity:${VERSION} pushed successfully"
138 else
139    print_log Main $LINENO ERROR "Error pushing ${ECOMP_REP}/sdc-sanity:${VERSION}"
140 fi
141
142
143 ###################################
144 ########   sdc-backend     ########
145 ###################################
146 cd /data/sdc-os-chef/sdc-backend
147 print_log Main $LINENO INFO "start creating sdc-backend ..."
148
149 conf_proxy
150 /bin/sed -i "s/__SDC-RELEASE__/${REL}/g" Dockerfile
151
152 wget -q -nd -r --no-parent -A 'onboard-main*.tar' http://${MAVEN_REPO}/att-repository-snapshots/${ONBOARD_GR}/onboard-main
153 if [ $? -ne 0 ] ; then
154    wget -q -nd -r --no-parent -A 'onboard-main*.tar' http://${MAVEN_REPO}/att-repository-releases/${ONBOARD_GR}/onboard-main
155 fi
156 /bin/tar -xf onboard-main-${DOX_VER}.*.tar --wildcards --no-anchored "onboarding-be-${DOX_VER}.*.war"
157 rm onboard-main*.tar
158
159 docker build -t ${ECOMP_REP}/sdc-backend:$VERSION .
160 docker tag  ${ECOMP_REP}/sdc-backend:$VERSION   ${ECOMP_REP}/sdc-backend
161 docker push ${ECOMP_REP}/sdc-backend:$VERSION
162 res=$?
163 if [ ${res} -eq 0 ]; then
164    print_log Main $LINENO INFO "${ECOMP_REP}/sdc-backend:${VERSION} pushed successfully"
165 else
166    print_log Main $LINENO ERROR "Error pushing ${ECOMP_REP}/sdc-backend:${VERSION}"
167 fi
168
169
170 ###################################
171 ########   sdc-frontend    ########
172 ###################################
173 cd /data/sdc-os-chef/sdc-frontend
174 print_log Main $LINENO INFO "start creating sdc-frontend ..."
175
176 conf_proxy
177
178 /bin/sed -i "s/__SDC-RELEASE__/${REL}/g" Dockerfile
179 wget -q -nd -r --no-parent -A 'onboard-main*.tar' http://${MAVEN_REPO}/att-repository-snapshots/${ONBOARD_GR}/onboard-main
180 if [ $? -ne 0 ] ; then
181    wget -q -nd -r --no-parent -A 'onboard-main*.tar' http://${MAVEN_REPO}/att-repository-releases/${ONBOARD_GR}/onboard-main
182 fi
183 /bin/tar -xf onboard-main-${DOX_VER}.*.tar --wildcards --no-anchored "onboarding-fe-${DOX_VER}.*.war"
184 rm onboard-main*.tar
185
186 docker build -t ${ECOMP_REP}/sdc-frontend:$VERSION .
187 docker tag  ${ECOMP_REP}/sdc-frontend:$VERSION   ${ECOMP_REP}/sdc-frontend
188 docker push ${ECOMP_REP}/sdc-frontend:$VERSION
189 res=$?
190 if [ ${res} -eq 0 ]; then
191    print_log Main $LINENO INFO "${ECOMP_REP}/sdc-frontend:${VERSION} pushed successfully"
192 else
193    print_log Main $LINENO ERROR "Error pushing ${ECOMP_REP}/sdc-frontend:${VERSION}"
194 fi
195
196 print_log Main $LINENO INFO "##### $0 completed #####"