4d4aa8335987fdc6a8f629c777ac2bae9e84898b
[portal.git] / deliveries / build_portalapps_dockers.sh
1 #!/bin/bash
2 # Builds Portal and Portal-SDK webapps; packages all into a docker.
3 # Prereq: all projects have been cloned from git.
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
10 # This reuses the docker-compose file
11 echo "Set image tag name variables"
12 source $(dirname $0)/.env
13
14 # Work standalone AND in the ONAP Jenkins.
15 # Pick up Jenkins settings for this script.
16 # Use -B for batch operation to skip download progress output
17 if [ -n "$MVN" ]; then
18     export MVN="${MVN} -B -gs ${GLOBAL_SETTINGS_FILE} -s ${SETTINGS_FILE}"
19 else
20     # Force refresh of snapshots
21     MVN="mvn -B -U"
22 fi
23
24 # This expects to start in the deliveries folder; make sure
25 PORTAL_DOCKERFILE=Dockerfile.portalapps
26 if [ ! -f $PORTAL_DOCKERFILE ] ; then
27     echo "Failed to find file ${PORTAL_DOCKERFILE}; must start in deliveries folder; exiting"
28     exit 1
29 fi
30
31 # Store directory names as variables
32 # This is the Docker Project area.
33 DELIV="$(pwd)"
34 # parent directory, for finding source projects
35 cd ..
36 BASE="$(pwd)"
37 cd $DELIV
38
39 # Relative path of temp directory
40 BUILD_REL="build"
41 # Absolute path of temp directory
42 BUILD_ABS=$DELIV/$BUILD_REL
43 rm -fr $BUILD_REL
44 mkdir $BUILD_REL
45
46 # Copy DDL/DML to required directories
47
48 # RELATIVE PATHS to local directories with database scripts
49 # bcos Docker looks within this build area only
50 SCR_BASE=$BUILD_REL/scripts
51 PORTAL_SCRIPT_DIR=$SCR_BASE/ecomp-portal-DB-os
52 SDK_SCRIPT_DIR=$SCR_BASE/epsdk-app-os
53 mkdir -p ${PORTAL_SCRIPT_DIR} ${SDK_SCRIPT_DIR}
54
55 # copy over DB scripts for the dockerfiles
56 # Portal
57 cp $BASE/ecomp-portal-DB-common/*.sql ${PORTAL_SCRIPT_DIR}
58 cp $BASE/ecomp-portal-DB-os/*.sql ${PORTAL_SCRIPT_DIR}
59 # SDK app
60 cp $BASE/sdk/ecomp-sdk/epsdk-app-common/db-scripts/*.sql ${SDK_SCRIPT_DIR}
61 cp $BASE/sdk/ecomp-sdk/epsdk-app-os/db-scripts/*.sql ${SDK_SCRIPT_DIR}
62
63 # build database docker
64 DB_DOCKER_CMD="
65   docker build -t ${DB_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
66     --build-arg PORTAL_SCRIPT_DIR=${PORTAL_SCRIPT_DIR}
67     --build-arg SDK_SCRIPT_DIR=${SDK_SCRIPT_DIR}
68     -f Dockerfile.mariadb .
69 "
70 echo "Build mariadb docker image"
71 $DB_DOCKER_CMD
72
73 echo "Build all jar and war files in Portal"
74 cd $BASE
75 ${MVN} clean install
76
77 echo "Copy Portal app BE"
78 cd $BASE/ecomp-portal-BE-os
79 cp target/ecompportal-be-os.war $BUILD_ABS
80
81 echo "Copy Portal app FE"
82 cd $BASE/ecomp-portal-FE-os/
83 cp -r dist/public $BUILD_ABS
84
85 echo "Copy Portal widget-ms"
86 cd $BASE/ecomp-portal-widget-ms
87 cp widget-ms/target/widget-ms.jar $BUILD_ABS
88
89 echo "Build and copy Portal-SDK app"
90 cd $BASE/sdk/ecomp-sdk/epsdk-app-os
91 ${MVN} clean package
92 cp target/epsdk-app-os.war $BUILD_ABS
93
94 PROXY_ARGS=""
95 if [ $HTTP_PROXY ]; then
96     PROXY_ARGS+="--build-arg HTTP_PROXY=${HTTP_PROXY}"
97 fi
98 if [ $HTTPS_PROXY ]; then
99     PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
100 fi
101
102 echo "Build portal docker image"
103 cd $DELIV
104 PORTAL_DOCKER_CMD="
105   docker build -t ${EP_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
106     --build-arg FE_DIR=$BUILD_REL/public
107     --build-arg PORTAL_WAR=$BUILD_REL/ecompportal-be-os.war
108     --build-arg SDK_WAR=$BUILD_REL/epsdk-app-os.war
109     -f $PORTAL_DOCKERFILE .
110 "
111 $PORTAL_DOCKER_CMD
112
113 echo "Bbuild widget-ms docker image"
114 WMS_DOCKER_CMD="
115   docker build -t ${WMS_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
116     --build-arg WMS_JAR=$BUILD_REL/widget-ms.jar
117     -f Dockerfile.widgetms .
118 "
119 $WMS_DOCKER_CMD
120
121 # For ease of debugging, leave the build dir
122 # echo "Cleaning up"
123 # rm -fr $BUILD_REL