Christopher Lott (cl778h) | a9627f8 | 2017-07-26 11:49:07 -0400 | [diff] [blame] | 1 | #!/bin/bash |
Christopher Lott (cl778h) | c83b7cb | 2017-10-11 14:45:00 -0400 | [diff] [blame] | 2 | # Builds Portal and Portal-SDK webapps; packages all into a docker. |
| 3 | # Prereq: all projects have been cloned from git. |
Christopher Lott (cl778h) | a9627f8 | 2017-07-26 11:49:07 -0400 | [diff] [blame] | 4 | # Expects to be invoked with CWD=portal/deliveries |
| 5 | # Caches files in local directory for docker build. |
| 6 | |
| 7 | # Stop on error; show output |
| 8 | set -e -x |
| 9 | |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 10 | # This reuses the docker-compose environment file |
Christopher Lott (cl778h) | 978dbcf | 2017-08-23 18:27:19 -0400 | [diff] [blame] | 11 | echo "Set image tag name variables" |
| 12 | source $(dirname $0)/.env |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 13 | if [ $1 ]; then |
| 14 | echo "Sourcing extra parameters from $1" |
| 15 | source $(dirname $0)/$1 |
| 16 | else |
| 17 | echo "Using only base parameters from .env" |
| 18 | fi |
Christopher Lott (cl778h) | a9627f8 | 2017-07-26 11:49:07 -0400 | [diff] [blame] | 19 | |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 20 | # Check for Jenkins build number |
| 21 | if [ -n "$BUILD_NUMBER" ]; then |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 22 | echo "Using Jenkins build number $BUILD_NUMBER; Docker Tag $PORTAL_TAG" |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 23 | else |
| 24 | # This indicates a non-Jenkins build |
| 25 | export BUILD_NUMBER="999" |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 26 | echo "Using Default build number $BUILD_NUMBER; Docker Tag $PORTAL_TAG" |
| 27 | |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 28 | fi |
| 29 | |
| 30 | # Must work when called by ONAP Jenkins AND local builds. |
Christopher Lott (cl778h) | a9627f8 | 2017-07-26 11:49:07 -0400 | [diff] [blame] | 31 | # Pick up Jenkins settings for this script. |
| 32 | # Use -B for batch operation to skip download progress output |
| 33 | if [ -n "$MVN" ]; then |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 34 | export MVN="${MVN} -B -gs ${GLOBAL_SETTINGS_FILE} -s ${SETTINGS_FILE} -Dbuild.number=$BUILD_NUMBER" |
Christopher Lott (cl778h) | a9627f8 | 2017-07-26 11:49:07 -0400 | [diff] [blame] | 35 | else |
Christopher Lott (cl778h) | 978dbcf | 2017-08-23 18:27:19 -0400 | [diff] [blame] | 36 | # Force refresh of snapshots |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 37 | MVN="mvn -B -U -Dbuild.number=$BUILD_NUMBER" |
Christopher Lott (cl778h) | a9627f8 | 2017-07-26 11:49:07 -0400 | [diff] [blame] | 38 | fi |
| 39 | |
| 40 | # This expects to start in the deliveries folder; make sure |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 41 | if [ "$PORTAL_DOCKERFILE" != "skip"] && [ ! -f $PORTAL_DOCKERFILE ] ; then |
Christopher Lott (cl778h) | 978dbcf | 2017-08-23 18:27:19 -0400 | [diff] [blame] | 42 | echo "Failed to find file ${PORTAL_DOCKERFILE}; must start in deliveries folder; exiting" |
Christopher Lott (cl778h) | a9627f8 | 2017-07-26 11:49:07 -0400 | [diff] [blame] | 43 | exit 1 |
| 44 | fi |
| 45 | |
Christopher Lott (cl778h) | 978dbcf | 2017-08-23 18:27:19 -0400 | [diff] [blame] | 46 | # Store directory names as variables |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 47 | # This is the deliveries area. |
| 48 | DELIVDIR="$(pwd)" |
Christopher Lott (cl778h) | 978dbcf | 2017-08-23 18:27:19 -0400 | [diff] [blame] | 49 | # parent directory, for finding source projects |
Christopher Lott (cl778h) | a9627f8 | 2017-07-26 11:49:07 -0400 | [diff] [blame] | 50 | cd .. |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 51 | BASEDIR="$(pwd)" |
| 52 | cd $DELIVDIR |
Christopher Lott (cl778h) | a9627f8 | 2017-07-26 11:49:07 -0400 | [diff] [blame] | 53 | |
Christopher Lott (cl778h) | 978dbcf | 2017-08-23 18:27:19 -0400 | [diff] [blame] | 54 | # Relative path of temp directory |
| 55 | BUILD_REL="build" |
| 56 | # Absolute path of temp directory |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 57 | BUILD_ABS=$DELIVDIR/$BUILD_REL |
Christopher Lott (cl778h) | 978dbcf | 2017-08-23 18:27:19 -0400 | [diff] [blame] | 58 | |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 59 | # Build Java projects. |
| 60 | # (use env var toskip when debugging Docker build problems) |
| 61 | if [ "$SKIP_JAVA_BUILD" = "please" ]; then |
Christopher Lott (cl778h) | 978dbcf | 2017-08-23 18:27:19 -0400 | [diff] [blame] | 62 | |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 63 | echo "SKIPPING JAVA BUILD!" |
Christopher Lott (cl778h) | 978dbcf | 2017-08-23 18:27:19 -0400 | [diff] [blame] | 64 | |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 65 | else |
| 66 | echo "Starting Java build." |
Christopher Lott (cl778h) | 978dbcf | 2017-08-23 18:27:19 -0400 | [diff] [blame] | 67 | |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 68 | # Clean out and recreate |
| 69 | rm -fr $BUILD_REL |
| 70 | mkdir $BUILD_REL |
Christopher Lott (cl778h) | 978dbcf | 2017-08-23 18:27:19 -0400 | [diff] [blame] | 71 | |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 72 | echo "Build jar and war files" |
| 73 | cd $BASEDIR |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 74 | ${MVN} ${MVN_EXTRA_PORTAL} clean install |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 75 | |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 76 | if [ "$SDK_DOCKERFILE" != "skip" ] && [ "SDK_APP_DIR" != "skip" ]; then |
| 77 | echo "Build Portal-SDK app" |
| 78 | cd $BASEDIR/$SDK_APP_DIR |
jz385p | fe027d0 | 2020-05-04 19:29:37 +0530 | [diff] [blame] | 79 | ${MVN} ${MVN_EXTRA_SDK} clean package -Dskiptests=true |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 80 | fi |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 81 | |
| 82 | echo "Java build complete." |
| 83 | fi |
Christopher Lott (cl778h) | a9627f8 | 2017-07-26 11:49:07 -0400 | [diff] [blame] | 84 | |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 85 | if [ "$BE_DOCKERFILE" != "skip" ] || [ "PORTAL_DOCKERFILE" != "skip" ]; then |
| 86 | echo "Copy Portal app BE" |
| 87 | cp $BASEDIR/$BE_WAR_DIR/$BE_WAR_FILE $BUILD_ABS |
| 88 | fi |
Christopher Lott (cl778h) | a9627f8 | 2017-07-26 11:49:07 -0400 | [diff] [blame] | 89 | |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 90 | if [ "$FE_DOCKERFILE" != "skip" ] || [ "PORTAL_DOCKERFILE" != "skip" ]; then |
| 91 | echo "Copy Portal app FE" |
| 92 | cp -r $BASEDIR/$FE_DIR $BUILD_ABS |
| 93 | fi |
Christopher Lott (cl778h) | a9627f8 | 2017-07-26 11:49:07 -0400 | [diff] [blame] | 94 | |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 95 | if [ "$WMS_DOCKERFILE" != "skip" ]; then |
| 96 | echo "Copy Portal widget-ms" |
| 97 | cp $BASEDIR/$WIDGET_MS_JAR_DIR/$WIDGET_MS_JAR_FILE $BUILD_ABS |
| 98 | fi |
Christopher Lott (cl778h) | 978dbcf | 2017-08-23 18:27:19 -0400 | [diff] [blame] | 99 | |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 100 | if [ "$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 |
| 103 | fi |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 104 | |
| 105 | # Build Docker images |
Christopher Lott (cl778h) | a9627f8 | 2017-07-26 11:49:07 -0400 | [diff] [blame] | 106 | |
Christopher Lott (cl778h) | a9627f8 | 2017-07-26 11:49:07 -0400 | [diff] [blame] | 107 | PROXY_ARGS="" |
| 108 | if [ $HTTP_PROXY ]; then |
| 109 | PROXY_ARGS+="--build-arg HTTP_PROXY=${HTTP_PROXY}" |
| 110 | fi |
| 111 | if [ $HTTPS_PROXY ]; then |
| 112 | PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}" |
| 113 | fi |
| 114 | |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 115 | # must work in delivery directory |
| 116 | cd $DELIVDIR |
| 117 | |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 118 | if [ "$DB_DOCKERFILE" = "skip" ]; then |
| 119 | echo "SKIPPING DB DOCKER BUILD!" |
| 120 | else |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 121 | # 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) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 124 | DB_SCRIPT_DIR=$BUILD_REL/db-scripts |
| 125 | mkdir -p ${DELIVDIR}/${DB_SCRIPT_DIR} |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 126 | # Portal |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 127 | cp $BASEDIR/ecomp-portal-DB-common/*.sql ${DB_SCRIPT_DIR} |
| 128 | cp $BASEDIR/ecomp-portal-DB-os/*.sql ${DB_SCRIPT_DIR} |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 129 | # SDK app |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 130 | 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} |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 132 | |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 133 | 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 |
| 140 | fi |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 141 | |
Kishore Reddy, Gujja (kg811t) | 4ee8967 | 2018-03-20 17:15:25 -0400 | [diff] [blame] | 142 | # Copy cassandra scripts to required directories |
| 143 | # Portal |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 144 | #cp $BASEDIR/ecomp-portal-DB-common/*.cql ${DELIVDIR} |
Kishore Reddy, Gujja (kg811t) | 4ee8967 | 2018-03-20 17:15:25 -0400 | [diff] [blame] | 145 | # SDK app |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 146 | #cp $BASEDIR/sdk/ecomp-sdk/epsdk-app-common/db-scripts/*.cql ${DELIVDIR} |
Kishore Reddy, Gujja (kg811t) | 4ee8967 | 2018-03-20 17:15:25 -0400 | [diff] [blame] | 147 | |
Kishore Reddy, Gujja (kg811t) | a59bc3e | 2018-09-25 13:59:56 -0400 | [diff] [blame] | 148 | # Build Docker Images |
Kishore Reddy, Gujja (kg811t) | 4ee8967 | 2018-03-20 17:15:25 -0400 | [diff] [blame] | 149 | |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 150 | #Combined FE/BE image |
| 151 | if [ "$PORTAL_DOCKERFILE" = "skip" ]; then |
| 152 | echo "SKIPPING PORTAL DOCKER IMAGE BUILD!" |
| 153 | else |
| 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 |
| 164 | fi |
Christopher Lott (cl778h) | a9627f8 | 2017-07-26 11:49:07 -0400 | [diff] [blame] | 165 | |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 166 | if [ "$SDK_DOCKERFILE" = "skip" ]; then |
| 167 | echo "SKIPPING SDK DOCKER IMAGE BUILD!" |
| 168 | else |
| 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 |
| 177 | fi |
st782s | 21a8761 | 2018-01-30 17:29:36 -0500 | [diff] [blame] | 178 | |
Kotta, Shireesha (sk434m) | b75f35b | 2019-06-13 14:41:15 -0400 | [diff] [blame] | 179 | if [ "$BE_DOCKERFILE" = "skip" ]; then |
| 180 | echo "SKIPPING BE DOCKER IMAGE BUILD!" |
| 181 | else |
| 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 |
| 192 | fi |
| 193 | |
| 194 | if [ "$FE_DOCKERFILE" = "skip" ]; then |
| 195 | echo "SKIPPING FE DOCKER IMAGE BUILD!" |
| 196 | else |
| 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 |
| 206 | fi |
| 207 | |
| 208 | if [ "$WMS_DOCKERFILE" = "skip" ]; then |
| 209 | echo "SKIPPING WIDGET-MS DOCKER IMAGE BUILD!" |
| 210 | else |
| 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 |
| 218 | fi |
Christopher Lott (cl778h) | 978dbcf | 2017-08-23 18:27:19 -0400 | [diff] [blame] | 219 | |
| 220 | # For ease of debugging, leave the build dir |
| 221 | # echo "Cleaning up" |
| 222 | # rm -fr $BUILD_REL |