summaryrefslogtreecommitdiffstats
path: root/deliveries/build_portalapps_dockers.sh
blob: 2a09997c8396ddd6b9e3d783b78419c65572ead7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/bash
# Builds Portal and Portal-SDK webapps; packages all into a docker.
# Prereq: all projects have been cloned from git.
# Expects to be invoked with CWD=portal/deliveries
# Caches files in local directory for docker build.

# Stop on error; show output
set -e -x

# This reuses the docker-compose environment file
echo "Set image tag name variables"
source $(dirname $0)/.env
if [ $1 ]; then
  echo "Sourcing extra parameters from $1"
  source $(dirname $0)/$1
else
  echo "Using only base parameters from .env"
fi

# Check for Jenkins build number
if [ -n "$BUILD_NUMBER" ]; then
    export PORTAL_TAG=$BUILD_NUMBER
    echo "Using Jenkins build number $BUILD_NUMBER; Docker Tag $PORTAL_TAG"
else
    # This indicates a non-Jenkins build
    export BUILD_NUMBER="999"
    echo "Using Default build number $BUILD_NUMBER; Docker Tag $PORTAL_TAG"
    
fi

# Must work when called by ONAP Jenkins AND local builds.
# Pick up Jenkins settings for this script.
# Use -B for batch operation to skip download progress output
if [ -n "$MVN" ]; then
    export MVN="${MVN} -B -gs ${GLOBAL_SETTINGS_FILE} -s ${SETTINGS_FILE} -Dbuild.number=$BUILD_NUMBER"
else
    # Force refresh of snapshots
    MVN="mvn -B -U -Dbuild.number=$BUILD_NUMBER"
fi

# This expects to start in the deliveries folder; make sure
if [ "$PORTAL_DOCKERFILE" != "skip"] && [ ! -f $PORTAL_DOCKERFILE ] ; then
    echo "Failed to find file ${PORTAL_DOCKERFILE}; must start in deliveries folder; exiting"
    exit 1
fi

# Store directory names as variables
# This is the deliveries area.
DELIVDIR="$(pwd)"
# parent directory, for finding source projects
cd ..
BASEDIR="$(pwd)"
cd $DELIVDIR

# Relative path of temp directory
BUILD_REL="build"
# Absolute path of temp directory
BUILD_ABS=$DELIVDIR/$BUILD_REL

# Build Java projects.
# (use env var toskip when debugging Docker build problems)
if [ "$SKIP_JAVA_BUILD" = "please" ]; then

	echo "SKIPPING JAVA BUILD!"

else
	echo "Starting Java build."

	# Clean out and recreate
	rm -fr $BUILD_REL
	mkdir $BUILD_REL

	echo "Build jar and war files"
	cd $BASEDIR
	${MVN} ${MVN_EXTRA_PORTAL} clean install

        if [ "$SDK_DOCKERFILE" != "skip" ] && [ "SDK_APP_DIR" != "skip" ]; then
	  echo "Build Portal-SDK app"
	  cd $BASEDIR/$SDK_APP_DIR
	  ${MVN} ${MVN_EXTRA_SDK} clean package
	fi

	echo "Java build complete."
fi

if [ "$BE_DOCKERFILE" != "skip" ] || [ "PORTAL_DOCKERFILE" != "skip" ]; then
  echo "Copy Portal app BE"
  cp $BASEDIR/$BE_WAR_DIR/$BE_WAR_FILE $BUILD_ABS
fi

if [ "$FE_DOCKERFILE" != "skip" ] || [ "PORTAL_DOCKERFILE" != "skip" ]; then
  echo "Copy Portal app FE"
  cp -r $BASEDIR/$FE_DIR $BUILD_ABS
fi

if [ "$WMS_DOCKERFILE" != "skip" ]; then
  echo "Copy Portal widget-ms"
  cp $BASEDIR/$WIDGET_MS_JAR_DIR/$WIDGET_MS_JAR_FILE $BUILD_ABS
fi

if [ "$SDK_DOCKERFILE" != "skip" ] && [ "SDK_APP_DIR" != "skip" ]; then
  echo "Copy Portal-SDK app build results"
  cp $BASEDIR/$SDK_WAR_DIR/$SDK_WAR_FILE $BUILD_ABS
fi

# Build Docker images

PROXY_ARGS=""
if [ $HTTP_PROXY ]; then
    PROXY_ARGS+="--build-arg HTTP_PROXY=${HTTP_PROXY}"
fi
if [ $HTTPS_PROXY ]; then
    PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
fi

# must work in delivery directory
cd $DELIVDIR

if [ "$DB_DOCKERFILE" = "skip" ]; then 
  echo "SKIPPING DB DOCKER BUILD!"
else 
# Copy DDL/DML to required directories
# RELATIVE PATHS to local directories with database scripts
# bcos Docker looks within this build area only
  DB_SCRIPT_DIR=$BUILD_REL/db-scripts
  mkdir -p ${DELIVDIR}/${DB_SCRIPT_DIR}
# Portal
  cp $BASEDIR/ecomp-portal-DB-common/*.sql ${DB_SCRIPT_DIR}
  cp $BASEDIR/ecomp-portal-DB-os/*.sql ${DB_SCRIPT_DIR}
# SDK app
  cp $BASEDIR/sdk/ecomp-sdk/epsdk-app-common/db-scripts/*.sql ${DB_SCRIPT_DIR}
  cp $BASEDIR/sdk/ecomp-sdk/epsdk-app-os/db-scripts/*.sql ${DB_SCRIPT_DIR}

  echo "Build mariadb docker image"
  DB_DOCKER_CMD="
    docker build -t ${DB_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
      --build-arg DB_SCRIPT_DIR=${DB_SCRIPT_DIR}
      -f $DB_DOCKERFILE .
  "
  $DB_DOCKER_CMD
fi

# Copy cassandra scripts to required directories
# Portal
#cp $BASEDIR/ecomp-portal-DB-common/*.cql ${DELIVDIR}
# SDK app
#cp $BASEDIR/sdk/ecomp-sdk/epsdk-app-common/db-scripts/*.cql ${DELIVDIR}

# Build Docker Images

#Combined FE/BE image
if [ "$PORTAL_DOCKERFILE" = "skip" ]; then
  echo "SKIPPING PORTAL DOCKER IMAGE BUILD!"
else
  echo "Build portal docker image"
  PORTAL_DOCKER_CMD="
    docker build -t ${EP_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
      --build-arg FE_DIR=$BUILD_REL/public
      --build-arg PORTAL_WAR=$BUILD_REL/$BE_WAR_FILE
      --build-arg SERVERXML=${SERVER_XML_DIR}/server.xml
      --build-arg PORTALCONTEXT=$PORTALCONTEXT
      -f $PORTAL_DOCKERFILE .
  "
  $PORTAL_DOCKER_CMD
fi

if [ "$SDK_DOCKERFILE" = "skip" ]; then
  echo "SKIPPING SDK DOCKER IMAGE BUILD!"
else
  echo "Build sdk demo app docker image"
  SDK_DOCKER_CMD="
    docker build -t ${SDK_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
      --build-arg SDK_WAR=$BUILD_REL/$SDK_WAR_FILE
      --build-arg SDKCONTEXT=$SDKCONTEXT
      -f $SDK_DOCKERFILE .
  "
  $SDK_DOCKER_CMD
fi

if [ "$BE_DOCKERFILE" = "skip" ]; then
  echo "SKIPPING BE DOCKER IMAGE BUILD!"
else 
  echo "Build portal be image"
  BE_DOCKER_CMD="
    docker build -t ${BE_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
      --build-arg PORTAL_WAR=$BUILD_REL/$BE_WAR_FILE
      --build-arg SERVERXML=${SERVER_XML_DIR}/server.xml
      --build-arg PORTALCONTEXT=$PORTALCONTEXT
      --build-arg BE_BASE_IMAGE=$BE_BASE_IMAGE
      -f $BE_DOCKERFILE .
  "
  $BE_DOCKER_CMD
fi

if [ "$FE_DOCKERFILE" = "skip" ]; then
  echo "SKIPPING FE DOCKER IMAGE BUILD!"
else 
  echo "Build portal fe image"
  FE_DOCKER_CMD="
    docker build -t ${FE_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
      --build-arg FE_DIR=$BUILD_REL/public
      --build-arg FECONTEXT=$FECONTEXT
      --build-arg FE_BASE_IMAGE=$FE_BASE_IMAGE
      -f $FE_DOCKERFILE .
  "
  $FE_DOCKER_CMD
fi

if [ "$WMS_DOCKERFILE" = "skip" ]; then
  echo "SKIPPING WIDGET-MS DOCKER IMAGE BUILD!"
else
  echo "Build widget-ms docker image"
  WMS_DOCKER_CMD="
    docker build -t ${WMS_IMG_NAME}:${PORTAL_TAG} ${PROXY_ARGS}
      --build-arg WMS_JAR=$BUILD_REL/$WIDGET_MS_JAR_FILE
      -f Dockerfile.widgetms .
  "
  $WMS_DOCKER_CMD
fi

# For ease of debugging, leave the build dir
# echo "Cleaning up"
# rm -fr $BUILD_REL