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/18 09:08:32 UTC

[incubator-streampipes-installer] branch new_installer updated: [STREAMPIPES-196] refactored start/stop to up/down to match docker-compose naming

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

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


The following commit(s) were added to refs/heads/new_installer by this push:
     new 7c6ba8b  [STREAMPIPES-196] refactored start/stop to up/down to match docker-compose naming
7c6ba8b is described below

commit 7c6ba8bd793842e5921a3890bb35dd0e799b8512
Author: Patrick Wiener <wi...@fzi.de>
AuthorDate: Tue Aug 18 11:08:16 2020 +0200

    [STREAMPIPES-196] refactored start/stop to up/down to match docker-compose naming
---
 cli/README.md                   | 26 ++++++++++-----
 cli/bin/commands/{stop => down} | 18 +++++-----
 cli/bin/commands/ps             |  5 +--
 cli/bin/commands/{start => up}  | 74 ++++++++++++++++++++++++-----------------
 cli/bin/common                  | 15 ++++++---
 cli/streampipes                 | 16 ++++-----
 6 files changed, 94 insertions(+), 60 deletions(-)

diff --git a/cli/README.md b/cli/README.md
index 4530cfa..69ae017 100644
--- a/cli/README.md
+++ b/cli/README.md
@@ -37,14 +37,14 @@ Options:
 
 Commands:
   clean       Clean all configs/docker data volumes from system
+  down        Stop and remove StreamPipes containers, networks and volumes
   info        Get information
   logs        Get container logs for specific container
   ps          List all StreamPipes container for running environment
   pull        Download latest images from Dockerhub
   restart     Restart StreamPipes environment
-  start       Start StreamPipes environment
-  stop        Stop and Remove StreamPipes environment
   template    Select StreamPipes environment template
+  up          Create and start StreamPipes container environment
 
 Run 'streampipes COMMAND --help' for more info on a command.
 ```
@@ -74,12 +74,12 @@ streampipes template --set pipeline-element
 ```
 
 **Start** environment ( default: `dev` mode).
-> **NOTE**: `dev` mode is enabled by default since we rely on open ports to core service such as `consul`, `couchdb`, `kafka` etc. to reach from the IDE when developing.
+> **NOTE**: `dev` mode is enabled by default since we rely on open ports to core service such as `consul`, `couchdb`, `kafka` etc. to reach from the IDE when developing. If you don't want to map ports (except the UI port), then use the `--no-ports` flag.
 
 ```bash
-streampipes start
-# start in regular mode with unmapped ports
-# streampipes start --user
+streampipes up -d
+# start in production mode with unmapped ports
+# streampipes up -d --no-ports
 ```
 Now you're good to go to write your new pipeline element :tada: :tada: :tada:
 
@@ -89,11 +89,21 @@ Now you're good to go to write your new pipeline element :tada: :tada: :tada:
 
 **Stop** environment and remove docker container
 ```bash
-streampipes stop
+streampipes down
+# want to also clean docker data volumes when stopping the environment?
+# streampipes down -v
 ```
 
 ## Additionally, useful commands
 
+**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`.
+
+```bash
+streampipes up -d kafka consul
+```
+
 **Get logs** of specific service
 ```bash
 streampipes logs --follow backend
@@ -111,7 +121,7 @@ streampipes restart
 # streampipes restart backend consul
 ```
 
-**Clean** your system and remove created StreamPipes Docker volumes
+**Clean** your system and remove created StreamPipes Docker volumes (if not already cleaned when shutting down the environment (see above `streampipes down -v`).
 ```bash
 streampipes clean
 ```
diff --git a/cli/bin/commands/stop b/cli/bin/commands/down
similarity index 82%
rename from cli/bin/commands/stop
rename to cli/bin/commands/down
index 54c093a..d6402a9 100755
--- a/cli/bin/commands/stop
+++ b/cli/bin/commands/down
@@ -16,11 +16,13 @@
 set -e
 . "$STREAMPIPES_WORKDIR/bin/common"
 
+clean_volumes=false
+
 cli_help_stop() {
   cat <<EOF
-Stop and remove StreamPipes environment
+Stops and removes StreamPipes environment containers, networks, volumes, and images
 
-Usage: streampipes stop [OPTIONS]
+Usage: streampipes down [OPTIONS]
 
 Options:
   -v, --volumes   Remove named volumes
@@ -37,14 +39,14 @@ fi
 
 while [[ "$#" -gt 0 ]]; do
     case $1 in
-        -v|--volumes) clean=true; shift ;;
+        -v|--volumes) clean_volumes=true; shift ;;
         -|--*=) fatal "Unsupported flag $1, see 'streampipes ${0##*/} --help'" >&2 ; shift ;;
         *) fatal "Wrong usage, see 'streampipes ${0##*/} --help'" ;;
     esac
 done
 
-remove_network(){
-  info "Remove network: 'spnet'"
+remove_external_docker_network(){
+  info "Remove docker network: 'spnet'"
   run "docker network rm spnet" > /dev/null 2>&1
 }
 
@@ -53,14 +55,14 @@ if is_streampipes_running; then
   concatenate_compose_files
   info "Stop environment: $curr_environment"
 
-  if [ "$clean" = true ]; then
+  if [ "$clean_volumes" = true ]; then
     info "Remove all StreamPipes container and named volumes"
     run "$docker_compose_files down -v"
-    remove_network
+    remove_external_docker_network
   else
     info "Remove all StreamPipes container"
     run "$docker_compose_files down"
-    remove_network
+    remove_external_docker_network
   fi
 
 else
diff --git a/cli/bin/commands/ps b/cli/bin/commands/ps
index b4f1082..1541304 100755
--- a/cli/bin/commands/ps
+++ b/cli/bin/commands/ps
@@ -18,7 +18,7 @@ set -e
 
 cli_help_ps() {
   cat << EOF
-List all StreamPipes container for running environment
+List all StreamPipes containers, volumes for running environment
 
 Usage: streampipes ps
 EOF
@@ -33,7 +33,8 @@ if [ "$#" -gt 1 ]; then
 fi
 
 if is_streampipes_running; then
-  docker ps --format 'table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}'
+  load_env_file
+  docker ps --filter "name=${COMPOSE_PROJECT_NAME}_*" --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'
 else
   info "No StreamPipes environment running"
 fi
diff --git a/cli/bin/commands/start b/cli/bin/commands/up
similarity index 53%
rename from cli/bin/commands/start
rename to cli/bin/commands/up
index f037d22..772cba2 100755
--- a/cli/bin/commands/start
+++ b/cli/bin/commands/up
@@ -16,21 +16,23 @@
 set -e
 . "$STREAMPIPES_WORKDIR/bin/common"
 
-DEPLOY_MODE="dev"
+no_ports=false
 
 cli_help_start() {
   cat <<EOF
-Start StreamPipes environment
+  Starts selected StreamPipes environment and attaches to containers for a service.
 
-Usage: streampipes start [OPTIONS]
+  Usage: streampipes up [OPTIONS] [SERVICE...]
 
-Examples:
-streampipes start
-streampipes start --user
+  Examples:
+  streampipes up -d
+  streampipes up -d --no-ports
 
-Options:
-  -d, --dev     Map docker service ports to host in dev mode (default)
-  -u, --user    No docker service ports mapped to host (user mode)
+  Options:
+    -d, --detach      Detach mode: Run containers in the background
+    -np, --no-ports   Per default, all docker service ports are mapped to the
+                      host. Using this option prevents service ports to be mapped
+                      to the host, except the UI port (generally port 80).
 EOF
 
   exit 1
@@ -38,16 +40,12 @@ EOF
 
 [ "$1" == '--help' ] || [ "$1" == '-h' ] && cli_help_start
 
-if [ "$#" -gt 1 ]; then
-    fatal "Illegal number of arguments, see 'streampipes ${0##*/} --help'"
-fi
-
 while [[ "$#" -gt 0 ]]; do
     case $1 in
-        -d|--dev) DEPLOY_MODE="dev"; shift ;;
-        -u|--user) DEPLOY_MODE="user"; shift ;;
+        -d|--detach) detach=true; shift ;;
+        -np|--no-ports) no_ports=true; shift ;;
         -*|--*=) fatal "Unsupported flag $1, see 'streampipes ${0##*/} --help'" >&2 ;;
-        *) fatal "Wrong usage, see 'streampipes ${0##*/} --help'" ;;
+        *) svc+=("$1"); shift ;;
     esac
 done
 
@@ -61,13 +59,11 @@ configure(){
   get_curr_environment
 
   info "Version: $(cat $STREAMPIPES_WORKDIR/VERSION)"
-
-  if [ "$DEPLOY_MODE" == "dev" ]; then
-    info "Environment: '$curr_environment'"
-    info "Mode: '$DEPLOY_MODE'"
-  elif [ "$DEPLOY_MODE" == "user" ]; then
-    info "Environment: '$curr_environment'"
-    info "Mode: '$DEPLOY_MODE'"
+  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
@@ -77,11 +73,11 @@ configure(){
   fi
 }
 
-create_docker_network() {
+create_external_docker_network() {
 	if [ ! "$(docker network ls | grep spnet)" ]; then
-    subnet=$(sed -n 's/^SP_SUBNET=//p' $STREAMPIPES_WORKDIR/.env)
+    #subnet=$(sed -n 's/^SP_SUBNET=//p' $STREAMPIPES_WORKDIR/.env)
 	  info "Creating docker network 'spnet'"
-	  run "docker network create --driver=bridge --subnet=$subnet spnet" > /dev/null 2>&1
+	  run "docker network create --driver=bridge --subnet=$SP_SUBNET spnet" > /dev/null 2>&1
 	else
 	  info "Docker network 'spnet' already exists. Continuing"
 	fi
@@ -89,11 +85,29 @@ create_docker_network() {
 
 start_environment(){
   configure
-  concatenate_compose_files $DEPLOY_MODE
-  create_docker_network
+  load_env_file
+  concatenate_compose_files $no_ports
+  create_external_docker_network
   info "Creating docker volumes and starting docker containers"
-  run "$docker_compose_files up -d"
-  deployment_notice
+
+  # check if starting whole environment or individual services
+  if [ -z "$svc" ]; then
+      # environment
+      if [ "$detach" = true ]; then
+        run "$docker_compose_files up -d"
+        deployment_notice
+      else
+        run "$docker_compose_files up"
+      fi
+  else
+      # individual services
+      if [ "$detach" = true ]; then
+        run "$docker_compose_files up -d ${svc[*]}"
+        deployment_notice
+      else
+        run "$docker_compose_files up ${svc[*]}"
+      fi
+  fi
 }
 
 start_environment
diff --git a/cli/bin/common b/cli/bin/common
index 60e1ebd..9742157 100644
--- a/cli/bin/common
+++ b/cli/bin/common
@@ -97,17 +97,24 @@ get_curr_environment() {
   fi
 }
 
+load_env_file() {
+  if [ -f $STREAMPIPES_WORKDIR/.env ]; then
+      # Load Environment Variables
+      export $(cat .env | grep -v '#' | awk '/=/ {print $1}')
+  fi
+}
+
 concatenate_compose_files() {
-  DEPLOY_MODE=$1
+  no_ports=$1
   search_str="[environment:"
 
   docker_compose_files="docker-compose --env-file $STREAMPIPES_WORKDIR/.env"
   while IFS='' read -r line || [[ -n "$line" ]]; do
     if [[ "$line" != *"$search_str"* ]]; then
-      if [ "$DEPLOY_MODE" == "dev" ]; then
-        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"
-      else
+      if [ "$no_ports" = true ]; then
         docker_compose_files="$docker_compose_files -f $STREAMPIPES_WORKDIR/deploy/standalone/$line/docker-compose.yml"
+      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
     fi
   done < "$STREAMPIPES_WORKDIR/.environment"
diff --git a/cli/streampipes b/cli/streampipes
index 149ecdb..51e2689 100755
--- a/cli/streampipes
+++ b/cli/streampipes
@@ -30,14 +30,14 @@ Options:
 
 Commands:
   clean       Clean all configs/docker data volumes from system
+  down        Stop and remove StreamPipes containers, networks and volumes
   info        Get information
   logs        Get container logs for specific container
   ps          List all StreamPipes container for running environment
   pull        Download latest images from Dockerhub
   restart     Restart StreamPipes environment
-  start       Start StreamPipes environment
-  stop        Stop and Remove StreamPipes environment
   template    Select StreamPipes environment template
+  up          Create and start StreamPipes container environment
 
 Run '$cli_name COMMAND --help' for more info on a command.
 EOF
@@ -49,6 +49,9 @@ case "$1" in
   clean)
     "$STREAMPIPES_WORKDIR/bin/commands/clean" "$2"
     ;;
+  down)
+    "$STREAMPIPES_WORKDIR/bin/commands/down" "${@:2}"
+    ;;
   info)
     "$STREAMPIPES_WORKDIR/bin/commands/info" "$2"
     ;;
@@ -67,15 +70,12 @@ case "$1" in
   restart)
     "$STREAMPIPES_WORKDIR/bin/commands/restart" "${@:2}"
     ;;
-  start)
-    "$STREAMPIPES_WORKDIR/bin/commands/start" "${@:2}"
-    ;;
-  stop)
-    "$STREAMPIPES_WORKDIR/bin/commands/stop" "${@:2}"
-    ;;
   template)
     "$STREAMPIPES_WORKDIR/bin/commands/template" "${@:2}"
     ;;
+  up)
+    "$STREAMPIPES_WORKDIR/bin/commands/up" "${@:2}"
+    ;;
   -v|--version)
     show_version
     ;;