blob: d2349b8e0ee29f89412ecefd039250fc267f0ccf [file] [log] [blame]
Christopher Lott (cl778h)a9627f82017-07-26 11:49:07 -04001#!/bin/bash
Christopher Lott (cl778h)c83b7cb2017-10-11 14:45:00 -04002# Builds Portal and Portal-SDK webapps; packages all into a docker.
3# Prereq: all projects have been cloned from git.
Christopher Lott (cl778h)a9627f82017-07-26 11:49:07 -04004# Expects to be invoked with CWD=portal/deliveries
5# Caches files in local directory for docker build.
6
7# Stop on error; show output
8set -e -x
9
st782s21a87612018-01-30 17:29:36 -050010# This reuses the docker-compose environment file
Christopher Lott (cl778h)978dbcf2017-08-23 18:27:19 -040011echo "Set image tag name variables"
12source $(dirname $0)/.env
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -040013if [ $1 ]; then
14 echo "Sourcing extra parameters from $1"
15 source $(dirname $0)/$1
16else
17 echo "Using only base parameters from .env"
18fi
Christopher Lott (cl778h)a9627f82017-07-26 11:49:07 -040019
st782s21a87612018-01-30 17:29:36 -050020# Check for Jenkins build number
21if [ -n "$BUILD_NUMBER" ]; then
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -040022 echo "Using Jenkins build number $BUILD_NUMBER; Docker Tag $PORTAL_TAG"
st782s21a87612018-01-30 17:29:36 -050023else
24 # This indicates a non-Jenkins build
25 export BUILD_NUMBER="999"
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -040026 echo "Using Default build number $BUILD_NUMBER; Docker Tag $PORTAL_TAG"
27
st782s21a87612018-01-30 17:29:36 -050028fi
29
30# Must work when called by ONAP Jenkins AND local builds.
Christopher Lott (cl778h)a9627f82017-07-26 11:49:07 -040031# Pick up Jenkins settings for this script.
32# Use -B for batch operation to skip download progress output
33if [ -n "$MVN" ]; then
st782s21a87612018-01-30 17:29:36 -050034 export MVN="${MVN} -B -gs ${GLOBAL_SETTINGS_FILE} -s ${SETTINGS_FILE} -Dbuild.number=$BUILD_NUMBER"
Christopher Lott (cl778h)a9627f82017-07-26 11:49:07 -040035else
Christopher Lott (cl778h)978dbcf2017-08-23 18:27:19 -040036 # Force refresh of snapshots
st782s21a87612018-01-30 17:29:36 -050037 MVN="mvn -B -U -Dbuild.number=$BUILD_NUMBER"
Christopher Lott (cl778h)a9627f82017-07-26 11:49:07 -040038fi
39
40# This expects to start in the deliveries folder; make sure
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -040041if [ "$PORTAL_DOCKERFILE" != "skip"] && [ ! -f $PORTAL_DOCKERFILE ] ; then
Christopher Lott (cl778h)978dbcf2017-08-23 18:27:19 -040042 echo "Failed to find file ${PORTAL_DOCKERFILE}; must start in deliveries folder; exiting"
Christopher Lott (cl778h)a9627f82017-07-26 11:49:07 -040043 exit 1
44fi
45
Christopher Lott (cl778h)978dbcf2017-08-23 18:27:19 -040046# Store directory names as variables
st782s21a87612018-01-30 17:29:36 -050047# This is the deliveries area.
48DELIVDIR="$(pwd)"
Christopher Lott (cl778h)978dbcf2017-08-23 18:27:19 -040049# parent directory, for finding source projects
Christopher Lott (cl778h)a9627f82017-07-26 11:49:07 -040050cd ..
st782s21a87612018-01-30 17:29:36 -050051BASEDIR="$(pwd)"
52cd $DELIVDIR
Christopher Lott (cl778h)a9627f82017-07-26 11:49:07 -040053
Christopher Lott (cl778h)978dbcf2017-08-23 18:27:19 -040054# Relative path of temp directory
55BUILD_REL="build"
56# Absolute path of temp directory
st782s21a87612018-01-30 17:29:36 -050057BUILD_ABS=$DELIVDIR/$BUILD_REL
Christopher Lott (cl778h)978dbcf2017-08-23 18:27:19 -040058
st782s21a87612018-01-30 17:29:36 -050059# Build Java projects.
60# (use env var toskip when debugging Docker build problems)
61if [ "$SKIP_JAVA_BUILD" = "please" ]; then
Christopher Lott (cl778h)978dbcf2017-08-23 18:27:19 -040062
st782s21a87612018-01-30 17:29:36 -050063 echo "SKIPPING JAVA BUILD!"
Christopher Lott (cl778h)978dbcf2017-08-23 18:27:19 -040064
st782s21a87612018-01-30 17:29:36 -050065else
66 echo "Starting Java build."
Christopher Lott (cl778h)978dbcf2017-08-23 18:27:19 -040067
st782s21a87612018-01-30 17:29:36 -050068 # Clean out and recreate
69 rm -fr $BUILD_REL
70 mkdir $BUILD_REL
Christopher Lott (cl778h)978dbcf2017-08-23 18:27:19 -040071
st782s21a87612018-01-30 17:29:36 -050072 echo "Build jar and war files"
73 cd $BASEDIR
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -040074 ${MVN} ${MVN_EXTRA_PORTAL} clean install
st782s21a87612018-01-30 17:29:36 -050075
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -040076 if [ "$SDK_DOCKERFILE" != "skip" ] && [ "SDK_APP_DIR" != "skip" ]; then
77 echo "Build Portal-SDK app"
78 cd $BASEDIR/$SDK_APP_DIR
jz385pfe027d02020-05-04 19:29:37 +053079 ${MVN} ${MVN_EXTRA_SDK} clean package -Dskiptests=true
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -040080 fi
st782s21a87612018-01-30 17:29:36 -050081
82 echo "Java build complete."
83fi
Christopher Lott (cl778h)a9627f82017-07-26 11:49:07 -040084
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -040085if [ "$BE_DOCKERFILE" != "skip" ] || [ "PORTAL_DOCKERFILE" != "skip" ]; then
86 echo "Copy Portal app BE"
87 cp $BASEDIR/$BE_WAR_DIR/$BE_WAR_FILE $BUILD_ABS
88fi
Christopher Lott (cl778h)a9627f82017-07-26 11:49:07 -040089
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -040090if [ "$FE_DOCKERFILE" != "skip" ] || [ "PORTAL_DOCKERFILE" != "skip" ]; then
91 echo "Copy Portal app FE"
92 cp -r $BASEDIR/$FE_DIR $BUILD_ABS
93fi
Christopher Lott (cl778h)a9627f82017-07-26 11:49:07 -040094
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -040095if [ "$WMS_DOCKERFILE" != "skip" ]; then
96 echo "Copy Portal widget-ms"
97 cp $BASEDIR/$WIDGET_MS_JAR_DIR/$WIDGET_MS_JAR_FILE $BUILD_ABS
98fi
Christopher Lott (cl778h)978dbcf2017-08-23 18:27:19 -040099
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -0400100if [ "$SDK_DOCKERFILE" != "skip" ] && [ "SDK_APP_DIR" != "skip" ]; then
101 echo "Copy Portal-SDK app build results"
102 cp $BASEDIR/$SDK_WAR_DIR/$SDK_WAR_FILE $BUILD_ABS
103fi
st782s21a87612018-01-30 17:29:36 -0500104
105# Build Docker images
Christopher Lott (cl778h)a9627f82017-07-26 11:49:07 -0400106
Christopher Lott (cl778h)a9627f82017-07-26 11:49:07 -0400107PROXY_ARGS=""
108if [ $HTTP_PROXY ]; then
109 PROXY_ARGS+="--build-arg HTTP_PROXY=${HTTP_PROXY}"
110fi
111if [ $HTTPS_PROXY ]; then
112 PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
113fi
114
st782s21a87612018-01-30 17:29:36 -0500115# must work in delivery directory
116cd $DELIVDIR
117
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -0400118if [ "$DB_DOCKERFILE" = "skip" ]; then
119 echo "SKIPPING DB DOCKER BUILD!"
120else
st782s21a87612018-01-30 17:29:36 -0500121# Copy DDL/DML to required directories
122# RELATIVE PATHS to local directories with database scripts
123# bcos Docker looks within this build area only
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -0400124 DB_SCRIPT_DIR=$BUILD_REL/db-scripts
125 mkdir -p ${DELIVDIR}/${DB_SCRIPT_DIR}
st782s21a87612018-01-30 17:29:36 -0500126# Portal
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -0400127 cp $BASEDIR/ecomp-portal-DB-common/*.sql ${DB_SCRIPT_DIR}
128 cp $BASEDIR/ecomp-portal-DB-os/*.sql ${DB_SCRIPT_DIR}
st782s21a87612018-01-30 17:29:36 -0500129# SDK app
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -0400130 cp $BASEDIR/sdk/ecomp-sdk/epsdk-app-common/db-scripts/*.sql ${DB_SCRIPT_DIR}
131 cp $BASEDIR/sdk/ecomp-sdk/epsdk-app-os/db-scripts/*.sql ${DB_SCRIPT_DIR}
st782s21a87612018-01-30 17:29:36 -0500132
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -0400133 echo "Build mariadb docker image"
134 DB_DOCKER_CMD="
135 docker build -t ${DB_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
136 --build-arg DB_SCRIPT_DIR=${DB_SCRIPT_DIR}
137 -f $DB_DOCKERFILE .
138 "
139 $DB_DOCKER_CMD
140fi
st782s21a87612018-01-30 17:29:36 -0500141
Kishore Reddy, Gujja (kg811t)4ee89672018-03-20 17:15:25 -0400142# Copy cassandra scripts to required directories
143# Portal
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -0400144#cp $BASEDIR/ecomp-portal-DB-common/*.cql ${DELIVDIR}
Kishore Reddy, Gujja (kg811t)4ee89672018-03-20 17:15:25 -0400145# SDK app
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -0400146#cp $BASEDIR/sdk/ecomp-sdk/epsdk-app-common/db-scripts/*.cql ${DELIVDIR}
Kishore Reddy, Gujja (kg811t)4ee89672018-03-20 17:15:25 -0400147
Kishore Reddy, Gujja (kg811t)a59bc3e2018-09-25 13:59:56 -0400148# Build Docker Images
Kishore Reddy, Gujja (kg811t)4ee89672018-03-20 17:15:25 -0400149
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -0400150#Combined FE/BE image
151if [ "$PORTAL_DOCKERFILE" = "skip" ]; then
152 echo "SKIPPING PORTAL DOCKER IMAGE BUILD!"
153else
154 echo "Build portal docker image"
155 PORTAL_DOCKER_CMD="
156 docker build -t ${EP_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
157 --build-arg FE_DIR=$BUILD_REL/public
158 --build-arg PORTAL_WAR=$BUILD_REL/$BE_WAR_FILE
159 --build-arg SERVERXML=${SERVER_XML_DIR}/server.xml
160 --build-arg PORTALCONTEXT=$PORTALCONTEXT
161 -f $PORTAL_DOCKERFILE .
162 "
163 $PORTAL_DOCKER_CMD
164fi
Christopher Lott (cl778h)a9627f82017-07-26 11:49:07 -0400165
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -0400166if [ "$SDK_DOCKERFILE" = "skip" ]; then
167 echo "SKIPPING SDK DOCKER IMAGE BUILD!"
168else
169 echo "Build sdk demo app docker image"
170 SDK_DOCKER_CMD="
171 docker build -t ${SDK_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
172 --build-arg SDK_WAR=$BUILD_REL/$SDK_WAR_FILE
173 --build-arg SDKCONTEXT=$SDKCONTEXT
174 -f $SDK_DOCKERFILE .
175 "
176 $SDK_DOCKER_CMD
177fi
st782s21a87612018-01-30 17:29:36 -0500178
Kotta, Shireesha (sk434m)b75f35b2019-06-13 14:41:15 -0400179if [ "$BE_DOCKERFILE" = "skip" ]; then
180 echo "SKIPPING BE DOCKER IMAGE BUILD!"
181else
182 echo "Build portal be image"
183 BE_DOCKER_CMD="
184 docker build -t ${BE_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
185 --build-arg PORTAL_WAR=$BUILD_REL/$BE_WAR_FILE
186 --build-arg SERVERXML=${SERVER_XML_DIR}/server.xml
187 --build-arg PORTALCONTEXT=$PORTALCONTEXT
188 --build-arg BE_BASE_IMAGE=$BE_BASE_IMAGE
189 -f $BE_DOCKERFILE .
190 "
191 $BE_DOCKER_CMD
192fi
193
194if [ "$FE_DOCKERFILE" = "skip" ]; then
195 echo "SKIPPING FE DOCKER IMAGE BUILD!"
196else
197 echo "Build portal fe image"
198 FE_DOCKER_CMD="
199 docker build -t ${FE_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
200 --build-arg FE_DIR=$BUILD_REL/public
201 --build-arg FECONTEXT=$FECONTEXT
202 --build-arg FE_BASE_IMAGE=$FE_BASE_IMAGE
203 -f $FE_DOCKERFILE .
204 "
205 $FE_DOCKER_CMD
206fi
207
208if [ "$WMS_DOCKERFILE" = "skip" ]; then
209 echo "SKIPPING WIDGET-MS DOCKER IMAGE BUILD!"
210else
211 echo "Build widget-ms docker image"
212 WMS_DOCKER_CMD="
213 docker build -t ${WMS_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
214 --build-arg WMS_JAR=$BUILD_REL/$WIDGET_MS_JAR_FILE
215 -f Dockerfile.widgetms .
216 "
217 $WMS_DOCKER_CMD
218fi
Christopher Lott (cl778h)978dbcf2017-08-23 18:27:19 -0400219
220# For ease of debugging, leave the build dir
221# echo "Cleaning up"
222# rm -fr $BUILD_REL