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 b37c944  [STREAMPIPES-341] added flags for storing and activating 
newly added services
b37c944 is described below

commit b37c94437e4254f01dd92eb324586b58dac43ea0
Author: Patrick Wiener <[email protected]>
AuthorDate: Thu Apr 8 18:27:00 2021 +0200

    [STREAMPIPES-341] added flags for storing and activating newly added 
services
---
 cli/README.md        | 26 ++++++++++++--------
 cli/bin/commands/add | 67 +++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 66 insertions(+), 27 deletions(-)

diff --git a/cli/README.md b/cli/README.md
index 0cfde35..d65cac7 100644
--- a/cli/README.md
+++ b/cli/README.md
@@ -175,33 +175,39 @@ streampipes clean
 # streampipes clean --volumes
 ```
 
-## Add newly developed StreamPipes Pipeline Elements to catalog
+## Add newly developed StreamPipes Pipeline Elements to service catalog
 As you develop new pipeline elements, e.g., adapters, processors or sinks, you 
might want to add them to your existing environment. Adding these components 
requires minimal effort.
-We can simply use `streampipes add` command to populate relevant Docker 
Compose files under the StreamPipes working directory 
(`/path/to/cli/deploy/standalone/`).
+We can simply use `streampipes add` command to populate relevant Docker 
Compose files under the StreamPipes working directory (`deploy/standalone/`).
 
 > **NOTE**: This requires your own pipeline elements to be already 
 > containerized and accessible to pull, e.g., from a public Docker repository 
 > such as DockerHub. If you use a private
 > repository make sure your local Docker Daemon has access to it.
 
 ```bash
 # check out streampipes add --help for more options
-# add new pipeline element to catalog, here my-processor, optional 
image=my-processo-image:0.67.0, ports 8090:8090 (external:internal)
-streampipes add my-processor --image my-processor-image:0.67.0 --ports 
8090:8090
+# add new pipeline element to catalog, here my-processor
+streampipes add my-processor
 [INFO] Create new directory for: /path/to/cli/deploy/standalone/my-processor
 [INFO] Generate Docker Compose files for my-processor
-[INFO] Add service to current environment: lite ?
-Add [y/n]: y
-[INFO] Added service to .spenv
+
+# add new pipeline element with custom image and ports
+streampipes add my-processor --image myrepo/myprocessor:0.67.0 --ports 
8090:8090 --ports 8091:8091
+
+# [Optional] add new pipeline element and persistently store service in 
environment (here: lite) and activate service in current environment (.spenv)
+[INFO] Create new directory for: /path/to/cli/deploy/standalone/my-processor
+[INFO] Generate Docker Compose files for my-processor
+[INFO] Add my-processor to current environment in .spenv
+[INFO] Store my-processor in environment lite
 ```
 
-This creates necessary Docker Compose files in the local catalog:
+In general, this creates necessary Docker Compose files in the local service 
catalog:
 ```bash
 cli/deploy/standalone/my-processor
 ├── docker-compose.dev.yml
 └── docker-compose.yml
 ```
-Additionally, you were asked wether you want to add the new service to your 
current environment file `.spenv` (see `streampipes env`).
 
-You can now directly start you new pipeline element using the following 
command:
+If you activated the pipeline element while adding via the flag `--activate`, 
you can directly start you new pipeline element using the following command. 
Otherwise, you will have to manually add it at a later point.
+> **NOTE**: The service name **must** match the directory name under 
`deploy/standalone/<service_name>`
 ```bash
 streampipes up -d my-processor
 ```
diff --git a/cli/bin/commands/add b/cli/bin/commands/add
index e667c32..44d16e7 100755
--- a/cli/bin/commands/add
+++ b/cli/bin/commands/add
@@ -16,8 +16,10 @@
 set -e
 . "$STREAMPIPES_WORKDIR/bin/common"
 
+STREAMPIPES_ENVIRONMENTS_PATH=$STREAMPIPES_WORKDIR/environments
 docker_compose_api_version=3.4
 svc_has_ports=false
+activate_svc=false
 
 cli_help_start() {
   cat <<EOF
@@ -26,12 +28,21 @@ Add new StreamPipes service to catalog.
 Usage: streampipes add SERVICE [OPTIONS]
 
 Examples:
+# Create Docker Compose files using default image scheme
 streampipes add my-service
-streampipes add my-service --image apachestreampipes/my-service:0.68.0 --ports 
8090:8090 --ports 8091:8091
+
+# Create Docker Compose files with custom image tag and port mappings
+streampipes add my-service --image myrepo/my-service:0.68.0 --ports 8090:8090 
--ports 8091:8091
+
+# Create Docker Compose files, persistently store in environment (lite), and 
add to .spenv 
+streampipes add my-service --store lite --activate
+
 
 Options:
-  -i, --image     Name of image (Default: 
${SP_DOCKER_REGISTRY}/my-service:${SP_VERSION})
-  -p, --ports     Port mapping for this service (externalPort:internalPort)
+  -a, --activate  Add service to current working environment .spenv
+  -i, --image     Name of image (default: 
${SP_DOCKER_REGISTRY}/my-service:${SP_VERSION})
+  -p, --ports     Port mapping for this service (external:internal)
+  -s, --store     Store service in specific environment (see 'streampipes env 
--list')
 EOF
 
   exit 1
@@ -45,12 +56,13 @@ fi
 
 while [[ "$#" -gt 0 ]]; do
     case $1 in
+        -a|--activate) activate_svc=true; shift ;;
         -i|--image)
           if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
             svc_img_tag="$2"
             shift 2
           else
-            fatal "StreamPipes service image name for $1 is missing" >&2
+            fatal "Image tag for $1 is missing" >&2
           fi
           ;;
         -p|--ports)
@@ -62,6 +74,14 @@ while [[ "$#" -gt 0 ]]; do
             fatal "Ports for $1 is missing" >&2
           fi
           ;;
+        -s|--store)
+          if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
+            set_environment="$2"
+            shift 2
+          else
+            fatal "Environment name for $1 is missing" >&2
+          fi
+          ;;
         -*|--*=) fatal "Unsupported flag $1, see 'streampipes ${0##*/} 
--help'" >&2 ; shift ;;
         # *) fatal "Wrong usage, see 'streampipes ${0##*/} --help'" ;;
         *)
@@ -107,6 +127,8 @@ services:
     depends_on:
       - "consul"
       - "backend"
+    environment:
+      - SP_HOST=${svc_name}
     logging:
       driver: "json-file"
       options:
@@ -160,7 +182,7 @@ create_dir(){
     info "Create new directory for: $1"
   else
     warning "Service already exists $svc_name"
-    read -p 'Continue [y/n]: ' continue
+    read -p 'Would you like to overwrite existing files? [y/n]: ' continue
     if [ "$continue" == "n" ] || [ "$continue" == "n" ]; then
         exit 1
     fi
@@ -173,6 +195,13 @@ check_img_or_default(){
   fi
 }
 
+check_environment(){
+  template=$STREAMPIPES_ENVIRONMENTS_PATH/$1
+  if [ ! -f "$template" ]; then
+    fatal "Environment not found '$1'. see 'streampipes env --list'"
+  fi
+}
+
 create_docker_compose_files(){
   info "Generate Docker Compose files for $svc_name"
   check_img_or_default
@@ -185,28 +214,32 @@ create_docker_compose_files(){
   fi
 }
 
-append_to_curr_env(){
-  info "Added service to .spenv"
+append_to_curr_environment(){
+  info "Add $svc_name to current environment in .spenv"
   curr_env_file=$STREAMPIPES_WORKDIR/.spenv
   grep -qxF $svc_name $curr_env_file || echo $svc_name >> $curr_env_file
 }
 
-add_to_current_environment(){
-  get_curr_environment
-  info "Add service to current environment: $curr_environment ?"
-  read -p "Add [y/n]: " add
-  if [ "$add" == "n" ] || [ "$add" == "n" ]; then
-      exit 1
-  else
-    append_to_curr_env
-  fi
+store_in_environment() {
+  check_environment $set_environment
+  info "Store $svc_name in environment $set_environment"
+  template=$STREAMPIPES_ENVIRONMENTS_PATH/$set_environment
+  grep -qxF $svc_name $template || echo $svc_name >> $template
 }
 
+
 add_service() {
   svc_dir=$STREAMPIPES_WORKDIR/deploy/standalone/${svc_name}
   create_dir $svc_dir
   create_docker_compose_files $svc_dir
-  add_to_current_environment
+
+  if $activate_svc; then 
+    append_to_curr_environment
+  fi
+  
+  if [ ! -z "$set_environment" ]; then
+    store_in_environment
+  fi
 }
 
 add_service
\ No newline at end of file

Reply via email to