You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by wi...@apache.org on 2020/08/25 08:28:30 UTC

[incubator-streampipes-installer] branch dev updated: [STREAMPIPES-196] removed env.template for static .env, renamed .environment to .spenv, introduce checkup on running environment before setting it to new one

This is an automated email from the ASF dual-hosted git repository.

wiener pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-installer.git


The following commit(s) were added to refs/heads/dev by this push:
     new 5f9985c  [STREAMPIPES-196] removed env.template for static .env, renamed .environment to .spenv, introduce checkup on running environment before setting it to new one
5f9985c is described below

commit 5f9985c939d39e34145f725e44daafdb5cac6046
Author: Patrick Wiener <wi...@fzi.de>
AuthorDate: Tue Aug 25 10:28:12 2020 +0200

    [STREAMPIPES-196] removed env.template for static .env, renamed .environment to .spenv, introduce checkup on running environment before setting it to new one
---
 .gitignore                                         |  3 +-
 cli/{bin/templates/env.template => .env}           |  2 +-
 cli/README.md                                      |  8 ++---
 cli/VERSION                                        | 16 ---------
 cli/bin/commands/env                               | 20 ++++++-----
 cli/bin/commands/ps                                |  4 +--
 cli/bin/commands/pull                              |  7 ++++
 cli/bin/commands/up                                | 15 +++-----
 cli/bin/common                                     | 17 ++++-----
 cli/{bin/templates => }/environments/adapter       |  0
 cli/{bin/templates => }/environments/backend       |  0
 cli/{bin/templates => }/environments/basic         |  0
 cli/{bin/templates => }/environments/full          |  0
 cli/{bin/templates => }/environments/lite          |  0
 .../templates => }/environments/pipeline-element   |  0
 cli/{bin/templates => }/environments/ui            |  0
 upgrade_versions.sh                                | 42 +++-------------------
 17 files changed, 42 insertions(+), 92 deletions(-)

diff --git a/.gitignore b/.gitignore
index cdf942c..129541c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,8 +17,7 @@
 .DS_Store
 
 # hidden files in cli
-.env
-.environment
+.spenv
 
 # track env file in compose dir
 !*/compose/.env
diff --git a/cli/bin/templates/env.template b/cli/.env
similarity index 97%
rename from cli/bin/templates/env.template
rename to cli/.env
index 3d6841a..617eb80 100644
--- a/cli/bin/templates/env.template
+++ b/cli/.env
@@ -14,7 +14,7 @@
 # limitations under the License.
 
 SP_DOCKER_REGISTRY=apachestreampipes/
-SP_VERSION=##VERSION##
+SP_VERSION=0.67.0-SNAPSHOT
 SP_SUBNET=172.31.0.0/16
 SP_CONSUL_CONTAINER_IP=172.31.0.9
 COMPOSE_PROJECT_NAME=streampipes
diff --git a/cli/README.md b/cli/README.md
index f895cf6..c9022f1 100644
--- a/cli/README.md
+++ b/cli/README.md
@@ -118,7 +118,7 @@ streampipes down
 
 **Start individual services only?** We got you! You chose a template that suits your needs and now you only want to start individual services from it, e.g. only Kafka and Consul.
 
-> **NOTE**: the service names need to be present and match your current `.environment`.
+> **NOTE**: the service names need to be present and match your current `.spenv` environment.
 
 ```bash
 streampipes up -d kafka consul
@@ -154,7 +154,7 @@ streampipes clean
 ```
 
 ## Modify/Create an environment template
-As of now, this step has to be done **manually**. All environment templates are located in `bin/templates/environments`.
+As of now, this step has to be done **manually**. All environments are located in `environments/`.
 
 ```bash
 ├── adapter               # developing a new connect adapter
@@ -176,7 +176,7 @@ kafka
 <YOUR_NEW_SERVICE>
 ```
 
-**Creating a new** environment template. To create a new environment template, place a new file `bin/templates/environments/<YOUR_NEW_ENVIRONMENT>` in the template directory. Open the file and use the following schema.
+**Creating a new** environment template. To create a new environment template, place a new file `environments/<YOUR_NEW_ENVIRONMENT>` in the template directory. Open the file and use the following schema.
 > **IMPORTANT**: Please make sure to have `[environment:<YOUR_NEW_ENVIRONMENT>]` header in the first line of your new template matching the name of the file. Make sure to use small caps letters (lowercase) only.
 
 ```
@@ -199,7 +199,7 @@ For **Windows 10**, e.g. check this [documentation](https://helpdeskgeek.com/win
 
 
 ## Upgrade to new version
-To upgrade to a new version, simply edit the version tag in `VERSION`.
+To upgrade to a new version, simply edit the version tag `SP_VERSION` in the `.env` file.
 
 ## Bugs and Feature Requests
 
diff --git a/cli/VERSION b/cli/VERSION
deleted file mode 100644
index f809cbf..0000000
--- a/cli/VERSION
+++ /dev/null
@@ -1,16 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-0.67.0-SNAPSHOT
diff --git a/cli/bin/commands/env b/cli/bin/commands/env
index e1c4654..27a84e8 100755
--- a/cli/bin/commands/env
+++ b/cli/bin/commands/env
@@ -16,7 +16,7 @@
 set -e
 . "$STREAMPIPES_WORKDIR/bin/common"
 
-STREAMPIPES_TEMPLATE_PATH=$STREAMPIPES_WORKDIR/bin/templates/environments
+STREAMPIPES_ENVIRONMENTS_PATH=$STREAMPIPES_WORKDIR/environments
 
 cli_help_env() {
   cat <<EOF
@@ -73,7 +73,7 @@ while [[ "$#" -gt 0 ]]; do
 done
 
 show_curr_environment(){
-  if [ ! -f "$STREAMPIPES_WORKDIR/.environment" ]; then
+  if [ ! -f "$STREAMPIPES_WORKDIR/.spenv" ]; then
     fatal "No environment set. See 'streampipes ${0##*/} --help'"
   else
     get_curr_environment
@@ -82,7 +82,7 @@ show_curr_environment(){
 }
 
 check_environment(){
-  template=$STREAMPIPES_TEMPLATE_PATH/$1
+  template=$STREAMPIPES_ENVIRONMENTS_PATH/$1
   if [ ! -f "$template" ]; then
     fatal "Environment not found '$1'. see 'streampipes ${0##*/} --list'"
   fi
@@ -90,7 +90,7 @@ check_environment(){
 
 list_environments(){
   info "Available StreamPipes environment templates:"
-  for entry in "$STREAMPIPES_TEMPLATE_PATH"/*
+  for entry in "$STREAMPIPES_ENVIRONMENTS_PATH"/*
   do
     echo "${entry##*/}"
   done
@@ -99,8 +99,8 @@ list_environments(){
 set_environment(){
   check_environment $set_environment
   info "Set environment to '$set_environment'"
-  cp $STREAMPIPES_TEMPLATE_PATH/$set_environment $STREAMPIPES_WORKDIR/.environment
-  set_lf_line_encoding $STREAMPIPES_WORKDIR/.environment
+  cp $STREAMPIPES_ENVIRONMENTS_PATH/$set_environment $STREAMPIPES_WORKDIR/.spenv
+  set_lf_line_encoding $STREAMPIPES_WORKDIR/.spenv
 }
 
 inspect_environment(){
@@ -111,7 +111,7 @@ inspect_environment(){
   info "Inspect services in environment '$inspect_environment'"
   while IFS='' read -r line; do
     [[ -n "$line" && "$line" != *"$search_str"* && "$line" != [[:blank:]#]* ]] && echo "$line"
-  done < "$STREAMPIPES_TEMPLATE_PATH/$inspect_environment"
+  done < "$STREAMPIPES_ENVIRONMENTS_PATH/$inspect_environment"
 }
 
 if [ "$list_environments" = true ]; then
@@ -123,7 +123,11 @@ if [ -n "$inspect_environment" ]; then
 fi
 
 if [ -n "$set_environment" ]; then
-  set_environment
+  if is_streampipes_running; then
+    warning "Cannot change template on already running environment. Stop it before changing 'streampipes down'."
+  else
+    set_environment
+  fi
 fi
 
 if [[ -z "$1" && "$list_environments" != true && ! -n "$inspect_environment" \
diff --git a/cli/bin/commands/ps b/cli/bin/commands/ps
index 1541304..455c1bd 100755
--- a/cli/bin/commands/ps
+++ b/cli/bin/commands/ps
@@ -33,8 +33,8 @@ if [ "$#" -gt 1 ]; then
 fi
 
 if is_streampipes_running; then
-  load_env_file
-  docker ps --filter "name=${COMPOSE_PROJECT_NAME}_*" --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'
+  project_name=$(sed -n 's/^COMPOSE_PROJECT_NAME=//p' $STREAMPIPES_WORKDIR/.env)
+  docker ps --filter "name=${project_name}_*" --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'
 else
   info "No StreamPipes environment running"
 fi
diff --git a/cli/bin/commands/pull b/cli/bin/commands/pull
index b160362..67bf1c4 100755
--- a/cli/bin/commands/pull
+++ b/cli/bin/commands/pull
@@ -32,6 +32,13 @@ if [ "$#" -gt 1 ]; then
     fatal "Illegal number of arguments, see 'streampipes ${0##*/} --help'"
 fi
 
+environment_exists(){
+  if [ ! -f "$STREAMPIPES_WORKDIR/.spenv" ]; then
+    fatal "Environment missing, need to be set before pulling. See 'streampipes env --help'"
+  fi
+}
+
+environment_exists
 concatenate_compose_files
 get_curr_environment
 info "Pull latest docker images for environment: '$curr_environment'"
diff --git a/cli/bin/commands/up b/cli/bin/commands/up
index ec61a0b..2e2ee5d 100755
--- a/cli/bin/commands/up
+++ b/cli/bin/commands/up
@@ -51,33 +51,27 @@ done
 
 configure(){
 
-  if [ ! -f "$STREAMPIPES_WORKDIR/.environment" ]; then
+  if [ ! -f "$STREAMPIPES_WORKDIR/.spenv" ]; then
     fatal "Environment missing. See 'streampipes env --help'"
   fi
 
   startup_notice
   get_curr_environment
 
-  info "Version: $(cat $STREAMPIPES_WORKDIR/VERSION | grep -v '#' | awk NF)"
+  info "Version: $(show_version_no_build)"
   info "Environment: '$curr_environment'"
   if [ "$no_ports" = true ]; then
     info "Mode: Production mode, all ports closed"
   else
     info "Mode: Development mode, all ports mapped"
   fi
-
-  if [ ! -f "$STREAMPIPES_WORKDIR/.env" ]; then
-    info "Configure $STREAMPIPES_WORKDIR/.env"
-    sed "s/##VERSION##/$(cat $STREAMPIPES_WORKDIR/VERSION | grep -v '#' | awk NF)/g" \
-        $STREAMPIPES_WORKDIR/bin/templates/env.template > $STREAMPIPES_WORKDIR/.env
-  fi
 }
 
 create_external_docker_network() {
 	if [ ! "$(docker network ls | grep spnet)" ]; then
-    #subnet=$(sed -n 's/^SP_SUBNET=//p' $STREAMPIPES_WORKDIR/.env)
 	  info "Creating docker network 'spnet'"
-	  run "docker network create --driver=bridge --subnet=$SP_SUBNET spnet" > /dev/null 2>&1
+    subnet=$(sed -n 's/^SP_SUBNET=//p' $STREAMPIPES_WORKDIR/.env)
+	  run "docker network create --driver=bridge --subnet=$subnet spnet" > /dev/null 2>&1
 	else
 	  info "Docker network 'spnet' already exists. Continuing"
 	fi
@@ -85,7 +79,6 @@ create_external_docker_network() {
 
 start_environment(){
   configure
-  load_env_file
   concatenate_compose_files $no_ports
   create_external_docker_network
   info "Creating docker volumes and starting docker containers"
diff --git a/cli/bin/common b/cli/bin/common
index 4d194f0..5708faa 100644
--- a/cli/bin/common
+++ b/cli/bin/common
@@ -34,7 +34,11 @@ fatal(){
 }
 
 show_version(){
-  echo $(cat $STREAMPIPES_WORKDIR/VERSION), build $(git --git-dir "$(dirname "$STREAMPIPES_WORKDIR")/.git" rev-parse --short HEAD)
+  echo $(sed -n 's/^SP_VERSION=//p' $STREAMPIPES_WORKDIR/.env), build $(git --git-dir "$(dirname "$STREAMPIPES_WORKDIR")/.git" rev-parse --short HEAD)
+}
+
+show_version_no_build(){
+  echo $(sed -n 's/^SP_VERSION=//p' $STREAMPIPES_WORKDIR/.env)
 }
 
 show_banner(){
@@ -97,14 +101,7 @@ get_curr_environment() {
     [[ "$line" == *"$search_str"* ]] &&
     helper=${line#*$search_str}
     curr_environment=${helper%]*}
-  done < "$STREAMPIPES_WORKDIR/.environment"
-}
-
-load_env_file() {
-  if [ -f $STREAMPIPES_WORKDIR/.env ]; then
-      # Load Environment Variables
-      export $(cat $STREAMPIPES_WORKDIR/.env | grep -v '#' | awk '/=/ {print $1}')
-  fi
+  done < "$STREAMPIPES_WORKDIR/.spenv"
 }
 
 concatenate_compose_files() {
@@ -119,7 +116,7 @@ concatenate_compose_files() {
       else
         docker_compose_files="$docker_compose_files -f $STREAMPIPES_WORKDIR/deploy/standalone/$line/docker-compose.yml -f $STREAMPIPES_WORKDIR/deploy/standalone/$line/docker-compose.dev.yml"
       fi
-  done < "$STREAMPIPES_WORKDIR/.environment"
+  done < "$STREAMPIPES_WORKDIR/.spenv"
 }
 
 run() {
diff --git a/cli/bin/templates/environments/adapter b/cli/environments/adapter
similarity index 100%
rename from cli/bin/templates/environments/adapter
rename to cli/environments/adapter
diff --git a/cli/bin/templates/environments/backend b/cli/environments/backend
similarity index 100%
rename from cli/bin/templates/environments/backend
rename to cli/environments/backend
diff --git a/cli/bin/templates/environments/basic b/cli/environments/basic
similarity index 100%
rename from cli/bin/templates/environments/basic
rename to cli/environments/basic
diff --git a/cli/bin/templates/environments/full b/cli/environments/full
similarity index 100%
rename from cli/bin/templates/environments/full
rename to cli/environments/full
diff --git a/cli/bin/templates/environments/lite b/cli/environments/lite
similarity index 100%
rename from cli/bin/templates/environments/lite
rename to cli/environments/lite
diff --git a/cli/bin/templates/environments/pipeline-element b/cli/environments/pipeline-element
similarity index 100%
rename from cli/bin/templates/environments/pipeline-element
rename to cli/environments/pipeline-element
diff --git a/cli/bin/templates/environments/ui b/cli/environments/ui
similarity index 100%
rename from cli/bin/templates/environments/ui
rename to cli/environments/ui
diff --git a/upgrade_versions.sh b/upgrade_versions.sh
index affcfa4..1c98145 100755
--- a/upgrade_versions.sh
+++ b/upgrade_versions.sh
@@ -26,24 +26,7 @@ set_version(){
   case "$(uname -s)" in
       Darwin)
         # for MacOS
-        cat << EOF > ./cli/VERSION
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-$NEW_VERSION
-EOF
+        sed -i '' 's/SP_VERSION=.*/SP_VERSION='$NEW_VERSION'/g' ./cli/.env
         sed -i '' 's/SP_VERSION=.*/SP_VERSION='$NEW_VERSION'/g' ./compose/.env
         sed -i '' 's/  version: .*/  version: "'$NEW_VERSION'"/g' ./k8s/values.yaml
         sed -i '' 's/appVersion: .*/appVersion: "'$NEW_VERSION'"/g' ./k8s/Chart.yaml
@@ -56,28 +39,11 @@ EOF
         ;;
       *)
         # for Linux and Windows
-        cat <<EOF>> ./cli/VERSION
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#    http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-$NEW_VERSION
-EOF
+        sed -i 's/SP_VERSION=.*/SP_VERSION='$NEW_VERSION'/g' ./cli/.env
         sed -i 's/SP_VERSION=.*/SP_VERSION='$NEW_VERSION'/g' ./compose/.env
         sed -i 's/  version: .*/  version: "'$NEW_VERSION'"/g' ./k8s/values.yaml
-        sed -i '' 's/appVersion: .*/appVersion: "'$NEW_VERSION'"/g' ./k8s/Chart.yaml
-        sed -i '' 's/version: .*/version: '$NEW_VERSION'/g' ./k8s/Chart.yaml
+        sed -i 's/appVersion: .*/appVersion: "'$NEW_VERSION'"/g' ./k8s/Chart.yaml
+        sed -i 's/version: .*/version: '$NEW_VERSION'/g' ./k8s/Chart.yaml
 
         for opt in "${options[@]}"
         do