summaryrefslogtreecommitdiffstats
path: root/sdc-os-chef/scripts/docker_build.sh
blob: d2f982035619f0b2b5cbd36227d21bccbc2a5bd4 (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
#set -x


function usage
{
    echo "usage: docker_run.sh [ -r|--release <RELEASE-NAME> ]  [ -e|--environment <ENV-NAME> ] [ -p|--port <Docker-hub-port>] [ -h|--help ]"
}


function print_log () {
    funcname=$1
    lineno=$2
    sev=$3
    msg=$4
    dd=`date +"%Y-%m-%d %H:%M:%S"`
    case ${sev} in
       "INFO")
          COLOR="\033[1;32m"             # GREEN
          ;;
       "ERROR")
          COLOR="\033[1;31m"             # RED
          ;;
    esac
    echo -e "$dd: $fname, $funcname:$lineno --- ${COLOR} $msg\e[0m" |tee -a $LOG

}



function conf_proxy () {
   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
}

###################################
#########   Parameters    #########
###################################

WORKSPACE=$1
WORK_DIR=/data/sdc-os-chef
LOGFILE=`basename $0|awk -F. '{print $1".log"}'`
LOG=$WORK_DIR/$LOGFILE
DOCKER_REP=dockercentral.it.att.com:5100
ECOMP_REP=${DOCKER_REP}/com.att.sdc/openecomp
REL=`/usr/bin/xml_grep --text_only parent/version /data/sdc-os-chef/pom.xml`
DOX_VER=` /bin/grep ONBOARDING /data/sdc-os-chef/versions.properties | awk '{print $2}' | awk -F"." '{print $1}'`
DOX_NUM=` /bin/grep ONBOARDING /data/sdc-os-chef/versions.properties | awk '{print $2}' | awk -F"." '{print substr($NF,1,4)}' `
VERSION=` /bin/grep ASDC /data/sdc-os-chef/versions.properties | awk '{print $2}' `
MAVEN_REPO=mavencentral.it.att.com:8084/nexus/content/repositories
ONBOARD_GR=com/att/asdc/onboarding/${DOX_VER}/${DOX_NUM}


[ -f /opt/config/env_name.txt ] && DEP_ENV=$(cat /opt/config/env_name.txt) || DEP_ENV=__ENV-NAME__
[ -f /opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt)    || NEXUS_USERNAME=release
[ -f /opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt)      || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW
[ -f /opt/config/nexus_docker_repo.txt ] && NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt) || NEXUS_DOCKER_REPO=ecomp-nexus:${PORT}

[ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
#docker login -u m09875@sdc.att.com -p Aa1234%^! -e mg877n@att.com dockercentral.it.att.com:5100


###################################
########       MAIN        ########
###################################
print_log Main $LINENO INFO "##### $0 completed #####"

###################################
######## sdc-elasticsearch ########
###################################
cd /data/sdc-os-chef/sdc-elasticsearch
print_log Main $LINENO INFO "start creating sdc-elasticsearch ..."
conf_proxy

docker build -t ${ECOMP_REP}/sdc-elasticsearch:${VERSION} .
docker tag  ${ECOMP_REP}/sdc-elasticsearch:${VERSION} ${ECOMP_REP}/sdc-elasticsearch
docker push ${ECOMP_REP}/sdc-elasticsearch:${VERSION}
res=$?
if [ ${res} -eq 0 ]; then
   print_log Main $LINENO INFO "${ECOMP_REP}/sdc-elasticsearch:${VERSION} pushed successfully"
else
   print_log Main $LINENO ERROR "Error pushing ${ECOMP_REP}/sdc-elasticsearch:${VERSION}"
fi


###################################
########   sdc-cassandra   ########
###################################
cd /data/sdc-os-chef/sdc-cassandra
print_log Main $LINENO INFO "start creating sdc-cassandra ..."

conf_proxy

docker build -t ${ECOMP_REP}/sdc-cassandra:${VERSION} .
docker tag  ${ECOMP_REP}/sdc-cassandra:$VERSION ${ECOMP_REP}/sdc-cassandra
docker push ${ECOMP_REP}/sdc-cassandra:$VERSION
res=$?
if [ ${res} -eq 0 ]; then
   print_log Main $LINENO INFO "${ECOMP_REP}/sdc-cassandra:${VERSION} pushed successfully"
else
   print_log Main $LINENO ERROR "Error pushing ${ECOMP_REP}/sdc-cassandra:${VERSION}"
fi



###################################
########    sdc-kibana     ########
###################################
cd /data/sdc-os-chef/sdc-kibana
print_log Main $LINENO INFO "start creating sdc-kibana ..."

conf_proxy

docker build -t ${ECOMP_REP}/sdc-kibana:$VERSION .
docker tag  ${ECOMP_REP}/sdc-kibana:$VERSION   ${ECOMP_REP}/sdc-kibana
docker push ${ECOMP_REP}/sdc-kibana:$VERSION
res=$?
if [ ${res} -eq 0 ]; then
   print_log Main $LINENO INFO "${ECOMP_REP}/sdc-kibana:${VERSION} pushed successfully"
else
   print_log Main $LINENO ERROR "Error pushing ${ECOMP_REP}/sdc-kibana:${VERSION}"
fi


###################################
########    sdc-sanity     ########
###################################
cd /data/sdc-os-chef/sdc-sanity
print_log Main $LINENO INFO "start creating sdc-sanity ..."

conf_proxy

docker build -t ${ECOMP_REP}/sdc-sanity:$VERSION .
docker tag  ${ECOMP_REP}/sdc-sanity:$VERSION   ${ECOMP_REP}/sdc-sanity
docker push ${ECOMP_REP}/sdc-sanity:$VERSION
res=$?
if [ ${res} -eq 0 ]; then
   print_log Main $LINENO INFO "${ECOMP_REP}/sdc-sanity:${VERSION} pushed successfully"
else
   print_log Main $LINENO ERROR "Error pushing ${ECOMP_REP}/sdc-sanity:${VERSION}"
fi


###################################
########   sdc-backend     ########
###################################
cd /data/sdc-os-chef/sdc-backend
print_log Main $LINENO INFO "start creating sdc-backend ..."

conf_proxy
/bin/sed -i "s/__SDC-RELEASE__/${REL}/g" Dockerfile

wget -q -nd -r --no-parent -A 'onboard-main*.tar' http://${MAVEN_REPO}/att-repository-snapshots/${ONBOARD_GR}/onboard-main
if [ $? -ne 0 ] ; then
   wget -q -nd -r --no-parent -A 'onboard-main*.tar' http://${MAVEN_REPO}/att-repository-releases/${ONBOARD_GR}/onboard-main
fi
/bin/tar -xf onboard-main-${DOX_VER}.*.tar --wildcards --no-anchored "onboarding-be-${DOX_VER}.*.war"
rm onboard-main*.tar

docker build -t ${ECOMP_REP}/sdc-backend:$VERSION .
docker tag  ${ECOMP_REP}/sdc-backend:$VERSION   ${ECOMP_REP}/sdc-backend
docker push ${ECOMP_REP}/sdc-backend:$VERSION
res=$?
if [ ${res} -eq 0 ]; then
   print_log Main $LINENO INFO "${ECOMP_REP}/sdc-backend:${VERSION} pushed successfully"
else
   print_log Main $LINENO ERROR "Error pushing ${ECOMP_REP}/sdc-backend:${VERSION}"
fi


###################################
########   sdc-frontend    ########
###################################
cd /data/sdc-os-chef/sdc-frontend
print_log Main $LINENO INFO "start creating sdc-frontend ..."

conf_proxy

/bin/sed -i "s/__SDC-RELEASE__/${REL}/g" Dockerfile
wget -q -nd -r --no-parent -A 'onboard-main*.tar' http://${MAVEN_REPO}/att-repository-snapshots/${ONBOARD_GR}/onboard-main
if [ $? -ne 0 ] ; then
   wget -q -nd -r --no-parent -A 'onboard-main*.tar' http://${MAVEN_REPO}/att-repository-releases/${ONBOARD_GR}/onboard-main
fi
/bin/tar -xf onboard-main-${DOX_VER}.*.tar --wildcards --no-anchored "onboarding-fe-${DOX_VER}.*.war"
rm onboard-main*.tar

docker build -t ${ECOMP_REP}/sdc-frontend:$VERSION .
docker tag  ${ECOMP_REP}/sdc-frontend:$VERSION   ${ECOMP_REP}/sdc-frontend
docker push ${ECOMP_REP}/sdc-frontend:$VERSION
res=$?
if [ ${res} -eq 0 ]; then
   print_log Main $LINENO INFO "${ECOMP_REP}/sdc-frontend:${VERSION} pushed successfully"
else
   print_log Main $LINENO ERROR "Error pushing ${ECOMP_REP}/sdc-frontend:${VERSION}"
fi

print_log Main $LINENO INFO "##### $0 completed #####"