changeset 4:8c2659d0cadf

Integrate web client build into thermostat-ng.sh Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-July/024179.html
author Miloslav Zezulka mzezulka@redhat.com
date Tue, 18 Jul 2017 16:03:37 +0200
parents d1b78dcca129
children c69fd8f97d50
files thermostat-ng.sh
diffstat 1 files changed, 54 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/thermostat-ng.sh	Thu Jul 13 20:10:46 2017 +0200
+++ b/thermostat-ng.sh	Tue Jul 18 16:03:37 2017 +0200
@@ -63,7 +63,7 @@
   local max_attempts=40
   while [ $max_attempts -gt 0 ]; do
     if grep -q "$expected_msg" "$log_file"; then
-       break
+      break
     fi
     sleep 1
     max_attempts=$(( $max_attempts - 1 ))
@@ -131,6 +131,7 @@
 }
 
 start_agent() {
+  config_agent
   echo "Starting agent ..."
   $AGENT_ROOT/distribution/target/image/bin/thermostat -J-Dthermostat.agent.verbose=true -Tbg "$AGENT_PID_FILE" > "$AGENT_LOG_FILE" 2>&1 
   check_success_msg $? "Failed to start agent"
@@ -162,23 +163,64 @@
 
 build() {
   local dir="$1"
-  local error=0
-  local component=$(basename $dir)
   if [ "${DO_BUILD}_" == "true_" ]; then
+    local build_fn=$2
+    local error=0
+    local component=$(basename $dir)
     pushd "$dir"
-      mvn clean verify
+      $build_fn;
       error=$?
     popd
     check_success_msg $error "Failed to build $component"
+  else 
+    echo "Build of $dir is skipped."
   fi
 }
 
+mvn_build() {
+  mvn clean verify
+}
+
+npm_build() {
+  # setup environment variables
+  export NODE_ENV=development
+  export GATEWAY_URL=http://127.0.0.1:30000
+  npm install
+  npm run build
+}
+
 build_web_gateway() {
-  build "$WEB_GATEWAY_ROOT"
+  build "$WEB_GATEWAY_ROOT" mvn_build
+}
+
+config_agent() {
+  local agent_conf_dir="$HOME/.thermostat/etc"
+  local agent_conf="${agent_conf_dir}/agent.auth"
+  if [ ! -d "$agent_conf" ]; then
+    mkdir -p "$agent_conf_dir"
+  fi
+  echo "username=foo-agent-user" >> $agent_conf
+  echo "password=agent-pwd" >> $agent_conf
 }
 
+
 build_agent() {
-  build "$AGENT_ROOT"
+  build "$AGENT_ROOT" mvn_build
+}
+
+build_web_client() {
+  build "$WEB_CLIENT_ROOT" npm_build
+}
+
+# deploy web-client resources statically, more info at http://icedtea.classpath.org/pipermail/thermostat/2017-May/023164.html
+copy_web_client_to_web_gateway() {
+  local dist_dir="${WEB_CLIENT_ROOT}/dist";
+  if [ -d "$dist_dir" ]; then
+    cp -r $dist_dir $WEB_GATEWAY_ROOT/distribution/target/image/web-client;
+    echo "Web client copied to web-gateway."
+  else
+    fail "Web client could not be copied to web-gateway because the directory web-client/dist/ does not exist. Make sure the web-client has been built correctly."
+  fi
 }
 
 # Shuts down everything in reverse order.
@@ -197,6 +239,8 @@
 # Idle loop so as to be able to receive signals
 idle() {
   echo "Thermostat started. Stop with CTRL+C"
+  echo "The web client can be accessed at: http://127.0.0.1:30000/web-client/"
+  echo "Use credentials 'test-user':'test-pass' to log in."
   while true; do
     sleep 60
   done
@@ -224,6 +268,10 @@
 # Build the agent and web-gateway
 build_agent
 build_web_gateway
+# Build the web client and copy the built distribution image into
+# web-gateway's web-client folder for static serving of the web client.
+build_web_client
+copy_web_client_to_web_gateway
 
 trap stop_all INT