login and Certman AAF Integration changes
[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 environment file
11 echo "Set image tag name variables"
12 source $(dirname $0)/.env
13
14 # Check for Jenkins build number
15 if [ -n "$BUILD_NUMBER" ]; then
16     echo "Using Jenkins build number $BUILD_NUMBER"
17 else
18     # This indicates a non-Jenkins build
19     export BUILD_NUMBER="999"
20 fi
21
22 # Must work when called by ONAP Jenkins AND local builds.
23 # Pick up Jenkins settings for this script.
24 # Use -B for batch operation to skip download progress output
25 if [ -n "$MVN" ]; then
26     export MVN="${MVN} -B -gs ${GLOBAL_SETTINGS_FILE} -s ${SETTINGS_FILE} -Dbuild.number=$BUILD_NUMBER"
27 else
28     # Force refresh of snapshots
29     MVN="mvn -B -U -Dbuild.number=$BUILD_NUMBER"
30 fi
31
32 # This expects to start in the deliveries folder; make sure
33 PORTAL_DOCKERFILE=Dockerfile.portal
34 if [ ! -f $PORTAL_DOCKERFILE ] ; then
35     echo "Failed to find file ${PORTAL_DOCKERFILE}; must start in deliveries folder; exiting"
36     exit 1
37 fi
38 SDK_DOCKERFILE=Dockerfile.sdk
39
40 # Store directory names as variables
41 # This is the deliveries area.
42 DELIVDIR="$(pwd)"
43 # parent directory, for finding source projects
44 cd ..
45 BASEDIR="$(pwd)"
46 cd $DELIVDIR
47
48 # Relative path of temp directory
49 BUILD_REL="build"
50 # Absolute path of temp directory
51 BUILD_ABS=$DELIVDIR/$BUILD_REL
52
53 # Build Java projects.
54 # (use env var toskip when debugging Docker build problems)
55 if [ "$SKIP_JAVA_BUILD" = "please" ]; then
56
57         echo "SKIPPING JAVA BUILD!"
58
59 else
60         echo "Starting Java build."
61
62         # Clean out and recreate
63         rm -fr $BUILD_REL
64         mkdir $BUILD_REL
65
66         echo "Build jar and war files"
67         cd $BASEDIR
68         ${MVN} clean install
69
70         echo "Build Portal-SDK app"
71         cd $BASEDIR/sdk/ecomp-sdk/epsdk-app-os
72         ${MVN} clean package
73
74         echo "Java build complete."
75 fi
76
77 echo "Copy Portal app BE"
78 cp $BASEDIR/ecomp-portal-BE-os/target/portal-be-os.war $BUILD_ABS
79
80 echo "Copy Portal app FE"
81 cp -r $BASEDIR/ecomp-portal-FE-os/dist/public $BUILD_ABS
82
83 echo "Copy Portal widget-ms"
84 cp $BASEDIR/ecomp-portal-widget-ms/widget-ms/target/widget-ms.jar $BUILD_ABS
85
86 echo "Copy Portal-SDK app build results"
87 cp $BASEDIR/sdk/ecomp-sdk/epsdk-app-os/target/epsdk-app-os.war $BUILD_ABS
88
89 # Build Docker images
90
91 PROXY_ARGS=""
92 if [ $HTTP_PROXY ]; then
93     PROXY_ARGS+="--build-arg HTTP_PROXY=${HTTP_PROXY}"
94 fi
95 if [ $HTTPS_PROXY ]; then
96     PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
97 fi
98
99 # must work in delivery directory
100 cd $DELIVDIR
101
102 # Copy DDL/DML to required directories
103 # RELATIVE PATHS to local directories with database scripts
104 # bcos Docker looks within this build area only
105 DB_SCRIPT_DIR=$BUILD_REL/db-scripts
106 mkdir -p ${DELIVDIR}/${DB_SCRIPT_DIR}
107 # Portal
108 cp $BASEDIR/ecomp-portal-DB-common/*.sql ${DB_SCRIPT_DIR}
109 cp $BASEDIR/ecomp-portal-DB-os/*.sql ${DB_SCRIPT_DIR}
110 # SDK app
111 cp $BASEDIR/sdk/ecomp-sdk/epsdk-app-common/db-scripts/*.sql ${DB_SCRIPT_DIR}
112 cp $BASEDIR/sdk/ecomp-sdk/epsdk-app-os/db-scripts/*.sql ${DB_SCRIPT_DIR}
113
114 echo "Build mariadb docker image"
115 DB_DOCKER_CMD="
116   docker build -t ${DB_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
117     --build-arg DB_SCRIPT_DIR=${DB_SCRIPT_DIR}
118     -f Dockerfile.mariadb .
119 "
120 $DB_DOCKER_CMD
121
122 # Copy cassandra scripts to required directories
123 # Portal
124 cp $BASEDIR/ecomp-portal-DB-common/*.cql ${DELIVDIR}
125 # SDK app
126 cp $BASEDIR/sdk/ecomp-sdk/epsdk-app-common/db-scripts/*.cql ${DELIVDIR}
127
128 # Build Docker Images
129
130 echo "Build portal docker image"
131 PORTAL_DOCKER_CMD="
132   docker build -t ${EP_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
133     --build-arg FE_DIR=$BUILD_REL/public
134     --build-arg PORTAL_WAR=$BUILD_REL/portal-be-os.war
135     --build-arg SERVERXML=${DELIVDIR}/server.xml
136     -f $PORTAL_DOCKERFILE .
137 "
138 $PORTAL_DOCKER_CMD
139
140 echo "Build sdk demo app docker image"
141 SDK_DOCKER_CMD="
142   docker build -t ${SDK_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
143     --build-arg SDK_WAR=$BUILD_REL/epsdk-app-os.war
144     -f $SDK_DOCKERFILE .
145 "
146 $SDK_DOCKER_CMD
147
148 echo "Build widget-ms docker image"
149 WMS_DOCKER_CMD="
150   docker build -t ${WMS_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
151     --build-arg WMS_JAR=$BUILD_REL/widget-ms.jar
152     -f Dockerfile.widgetms .
153 "
154 $WMS_DOCKER_CMD
155
156 # For ease of debugging, leave the build dir
157 # echo "Cleaning up"
158 # rm -fr $BUILD_REL