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