add start up script (#26)

* add start up script

* add start up script

* add start up script

* polish script

* polish script

* add docker build script

* add docker build script

* polish Dockerfile

Co-authored-by: Evan <evanljp@outlook.com>
diff --git a/.gitignore b/.gitignore
index 51f1814..3161f6d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@
 bin/
 coverage.txt
 
+!/dist/bin/
diff --git a/Makefile b/Makefile
index 0230b7a..8634797 100644
--- a/Makefile
+++ b/Makefile
@@ -73,7 +73,7 @@
 	-rm -rf coverage.txt
 
 .PHONY: build
-build: deps linux darwin windows
+build: clean deps linux darwin windows
 
 .PHONY: check
 check: clean
@@ -86,6 +86,10 @@
 		exit 1; \
 	fi
 
+.PHONY: docker
+docker: release-bin
+	/bin/sh tools/docker_build.sh $(VERSION)
+
 release-src: clean
 	-tar -zcvf $(RELEASE_SRC).tgz \
 	--exclude bin \
@@ -100,6 +104,7 @@
 release-bin: build
 	-mkdir $(RELEASE_BIN)
 	-cp -R bin $(RELEASE_BIN)
+	-cp -R configs $(RELEASE_BIN)
 	-cp -R dist/* $(RELEASE_BIN)
 	-cp -R CHANGES.md $(RELEASE_BIN)
 	-cp -R README.md $(RELEASE_BIN)
diff --git a/cmd/main.go b/cmd/main.go
index cbe819c..61f2851 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -18,6 +18,7 @@
 package main
 
 import (
+	"log"
 	"os"
 	"time"
 
@@ -39,5 +40,7 @@
 		&cmdDocs,
 	}
 	app.Action = cli.ShowAppHelp
-	_ = app.Run(os.Args)
+	if err := app.Run(os.Args); err != nil {
+		log.Fatalln("start SkyWalking Satellite fail", err)
+	}
 }
diff --git a/configs/satellite_config.yaml b/configs/satellite_config.yaml
index 323e945..407b4bc 100644
--- a/configs/satellite_config.yaml
+++ b/configs/satellite_config.yaml
@@ -29,8 +29,6 @@
 
 # The sharing plugins referenced by the specific plugins in the different pipes.
 sharing:
-  common_config:
-    pipe_name: sharing
   clients:
     - plugin_name: "kafka-client"
       brokers: ${SATELLITE_KAFKA_CLIENT_BROKERS:127.0.0.1:9092}
diff --git a/dist/bin/startup.sh b/dist/bin/startup.sh
new file mode 100755
index 0000000..7d88cdc
--- /dev/null
+++ b/dist/bin/startup.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+#
+# 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.
+#
+
+
+HOME_DIR="$(cd "$(dirname "$0")" && cd .. && pwd)"
+BIN_DIR=${HOME_DIR}/bin
+LOG_DIR=${HOME_DIR}/logs
+CONFIG_DIR=${HOME_DIR}/configs
+LOG_FILE_LOCATION=${LOG_DIR}/satellite.log
+
+if [ ! -d "${LOG_DIR}" ]; then
+ mkdir -p "${LOG_DIR}"
+fi
+
+if uname -s | grep Darwin; then
+ START_UP_PROCESS=$(find "$BIN_DIR" -name "skywalking-satellite*darwin*")
+elif uname -s | grep Linux; then
+ START_UP_PROCESS=$(find "$BIN_DIR" -name "skywalking-satellite*linux*")
+else
+ START_UP_PROCESS=$(find "$BIN_DIR" -name "skywalking-satellite*windows*")
+fi
+
+eval exec "$START_UP_PROCESS" start --config="$CONFIG_DIR"/satellite_config.yaml 1> "$LOG_FILE_LOCATION" 2>&1 &
+
+if [ $? -eq 0 ]; then
+ sleep 1
+ echo "SkyWalking Satellite started successfully!"
+else
+ echo "SkyWalking Satellite started failure!"
+ exit 1
+fi
diff --git a/docker/Dockerfile b/docker/Dockerfile
new file mode 100644
index 0000000..4a5ee4d
--- /dev/null
+++ b/docker/Dockerfile
@@ -0,0 +1,37 @@
+# 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.
+
+FROM busybox
+
+ARG DIST_NAME='skywalking-satellite-latest-bin'
+ARG HOME='/skywalking-satellite'
+
+COPY "$DIST_NAME.tgz" /
+
+RUN set -ex; \
+    tar -xzf "$DIST_NAME.tgz"; \
+    rm -rf "$DIST_NAME.tgz"; \
+    ls "$DIST_NAME/bin" |grep -v linux-amd64| xargs -i echo "$DIST_NAME/bin/{}"|xargs rm -rf; \
+    mkdir "$HOME"; \
+    mv "$DIST_NAME"/* "$HOME";
+
+COPY entrypoint.sh "$HOME"/bin
+
+WORKDIR /skywalking-satellite
+
+EXPOSE 12800 11800 1234
+
+ENTRYPOINT ["/bin/sh","bin/entrypoint.sh"]
diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh
new file mode 100755
index 0000000..ee20df0
--- /dev/null
+++ b/docker/entrypoint.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+
+#
+# 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.
+#
+
+HOME_DIR="$(cd "$(dirname "$0")" && cd .. && pwd)"
+CONFIG_FILE=${HOME_DIR}/configs/satellite_config.yaml
+START_UP_PROCESS=$(find "${HOME_DIR}/bin" -name "skywalking-satellite*linux*")
+
+exec "$START_UP_PROCESS" start --config="$CONFIG_FILE"
+
diff --git a/docs/en/setup/README.md b/docs/en/setup/README.md
index 3c5ab09..3f3c364 100644
--- a/docs/en/setup/README.md
+++ b/docs/en/setup/README.md
@@ -2,10 +2,9 @@
 First and most important thing is, SkyWalking Satellite startup behaviours are driven by configs/satellite_config.yaml. Understanding the setting file will help you to read this document.
 
 ## Startup script
-The startup script is /bin/skywalking-satellite-{version}-{plateform}-amd64. 
-1. Start SkyWalking Satellite.
+Startup Script
 ```shell script
-./bin/skywalking-satellite-{version}-{plateform}-amd64 start --config=./configs/satellite_config.yaml
+bin/startup.sh 
 ```
 ## satellite_config.yaml
 The core concept behind this setting file is, SkyWalking Satellite is based on pure modularization design. End user can switch or assemble the collector features by their own requirements.
diff --git a/docs/en/setup/plugins/server_prometheus-server.md b/docs/en/setup/plugins/server_prometheus-server.md
index fa0c2f4..db187ce 100755
--- a/docs/en/setup/plugins/server_prometheus-server.md
+++ b/docs/en/setup/plugins/server_prometheus-server.md
@@ -4,7 +4,7 @@
 ## DefaultConfig
 ```yaml
 # The prometheus server address.
-address: ":9299"
+address: ":1234"
 # The prometheus server metrics endpoint.
 endpoint: "/metrics"
 ```
diff --git a/internal/satellite/config/loader.go b/internal/satellite/config/loader.go
index 11c6032..44f13f9 100644
--- a/internal/satellite/config/loader.go
+++ b/internal/satellite/config/loader.go
@@ -62,19 +62,19 @@
 	}
 	v := viper.New()
 	v.SetConfigType("yaml")
-	cfg := SatelliteConfig{}
+	cfg := NewDefaultSatelliteConfig()
 	if err := v.ReadConfig(bytes.NewReader(content)); err != nil {
 		return nil, err
 	}
 	if err := overrideConfigByEnv(v); err != nil {
 		return nil, fmt.Errorf("cannot override value by env config: %v", err)
 	}
-	if err := v.Unmarshal(&cfg); err != nil {
+	if err := v.Unmarshal(cfg); err != nil {
 		return nil, err
 	}
 	propagateCommonFieldsInSharing(cfg.Sharing)
 	propagateCommonFieldsInPipes(cfg.Pipes)
-	return &cfg, nil
+	return cfg, nil
 }
 
 // propagate the common fields to every modules and the dependency plugins.
@@ -95,7 +95,7 @@
 }
 
 // propagate the common fields to the fields that is one of `plugin.config` or `[]plugin.config` types.
-func propagateCommonFieldsInStruct(cfg interface{}, cf config.CommonFields) {
+func propagateCommonFieldsInStruct(cfg interface{}, commonFields *config.CommonFields) {
 	v := reflect.ValueOf(cfg)
 	if v.Kind() == reflect.Ptr {
 		v = v.Elem()
@@ -104,17 +104,20 @@
 		fieldVal := v.Field(i).Interface()
 		if arr, ok := fieldVal.([]plugin.Config); arr != nil && ok {
 			for _, pc := range arr {
-				propagateCommonFields(pc, cf)
+				propagateCommonFields(pc, commonFields)
 			}
 		} else if pc, ok := fieldVal.(plugin.Config); pc != nil && ok {
-			propagateCommonFields(pc, cf)
+			propagateCommonFields(pc, commonFields)
 		}
 	}
 }
 
 // propagate the common fields to the `plugin.config`.
-func propagateCommonFields(pc plugin.Config, cf config.CommonFields) {
+func propagateCommonFields(pc plugin.Config, cf *config.CommonFields) {
 	v := reflect.ValueOf(cf)
+	if v.Kind() == reflect.Ptr {
+		v = v.Elem()
+	}
 	t := v.Type()
 	for i := 0; i < t.NumField(); i++ {
 		if tagVal := t.Field(i).Tag.Get(config.TagName); tagVal != "" {
diff --git a/internal/satellite/config/loader_test.go b/internal/satellite/config/loader_test.go
index 1249e20..eabebf0 100644
--- a/internal/satellite/config/loader_test.go
+++ b/internal/satellite/config/loader_test.go
@@ -76,7 +76,7 @@
 			Instance: "instance1",
 		},
 		Sharing: &SharingConfig{
-			SharingCommonConfig: config.CommonFields{
+			SharingCommonConfig: &config.CommonFields{
 				PipeName: "sharing",
 			},
 			Clients: []plugin.Config{
@@ -101,13 +101,13 @@
 		},
 		Pipes: []*PipeConfig{
 			{
-				PipeCommonConfig: config.CommonFields{
+				PipeCommonConfig: &config.CommonFields{
 					PipeName: "pipe1",
 				},
 
 				Gatherer: &gatherer.GathererConfig{
 					ServerName: "grpc-server",
-					CommonFields: config.CommonFields{
+					CommonFields: &config.CommonFields{
 						PipeName: "pipe1",
 					},
 					ReceiverConfig: plugin.Config{
@@ -123,12 +123,12 @@
 					},
 				},
 				Processor: &processor.ProcessorConfig{
-					CommonFields: config.CommonFields{
+					CommonFields: &config.CommonFields{
 						PipeName: "pipe1",
 					},
 				},
 				Sender: &sender.SenderConfig{
-					CommonFields: config.CommonFields{
+					CommonFields: &config.CommonFields{
 						PipeName: "pipe1",
 					},
 					FallbackerConfig: plugin.Config{
diff --git a/internal/satellite/config/satellite_config.go b/internal/satellite/config/satellite_config.go
index 2828285..d5ed032 100644
--- a/internal/satellite/config/satellite_config.go
+++ b/internal/satellite/config/satellite_config.go
@@ -37,15 +37,36 @@
 
 // SharingConfig contains some plugins,which could be shared by every namespace. That is useful to reduce resources cost.
 type SharingConfig struct {
-	Clients             []plugin.Config     `mapstructure:"clients"`
-	Servers             []plugin.Config     `mapstructure:"servers"`
-	SharingCommonConfig config.CommonFields `mapstructure:"common_config"`
+	Clients             []plugin.Config      `mapstructure:"clients"`
+	Servers             []plugin.Config      `mapstructure:"servers"`
+	SharingCommonConfig *config.CommonFields `mapstructure:"common_config"`
 }
 
 // PipeConfig initializes the different module in different namespace.
 type PipeConfig struct {
+	PipeCommonConfig *config.CommonFields       `mapstructure:"common_config"`
 	Gatherer         *gatherer.GathererConfig   `mapstructure:"gatherer"`
-	PipeCommonConfig config.CommonFields        `mapstructure:"common_config"`
 	Processor        *processor.ProcessorConfig `mapstructure:"processor"`
 	Sender           *sender.SenderConfig       `mapstructure:"sender"`
 }
+
+// Create a satellite config with default value.
+func NewDefaultSatelliteConfig() *SatelliteConfig {
+	return &SatelliteConfig{
+		Logger: &log.LoggerConfig{
+			LogPattern:  "%time [%level][%field] - %msg",
+			TimePattern: "2006-01-02 15:04:05.000",
+			Level:       "info",
+		},
+		Telemetry: &telemetry.Config{
+			Cluster:  "default_cluster",
+			Service:  "default_service",
+			Instance: "default_instance",
+		},
+		Sharing: &SharingConfig{
+			SharingCommonConfig: &config.CommonFields{
+				PipeName: "sharing",
+			},
+		},
+	}
+}
diff --git a/internal/satellite/module/gatherer/api/config.go b/internal/satellite/module/gatherer/api/config.go
index 9846ffe..e2275fc 100644
--- a/internal/satellite/module/gatherer/api/config.go
+++ b/internal/satellite/module/gatherer/api/config.go
@@ -25,7 +25,7 @@
 // GathererConfig contains all implementation fields.
 type GathererConfig struct {
 	// common config
-	config.CommonFields
+	*config.CommonFields
 	QueueConfig plugin.Config `mapstructure:"queue"` // queue plugin config
 
 	// ReceiverGatherer
diff --git a/internal/satellite/module/processor/api/config.go b/internal/satellite/module/processor/api/config.go
index d8788ea..5b9e06d 100644
--- a/internal/satellite/module/processor/api/config.go
+++ b/internal/satellite/module/processor/api/config.go
@@ -24,7 +24,7 @@
 
 // ProcessorConfig contains all implementation fields.
 type ProcessorConfig struct {
-	config.CommonFields
+	*config.CommonFields
 
 	FilterConfig []plugin.Config `mapstructure:"filters"` // filter plugins
 }
diff --git a/internal/satellite/module/sender/api/config.go b/internal/satellite/module/sender/api/config.go
index 04cfa4d..fb9ccce 100644
--- a/internal/satellite/module/sender/api/config.go
+++ b/internal/satellite/module/sender/api/config.go
@@ -23,7 +23,7 @@
 )
 
 type SenderConfig struct {
-	config.CommonFields
+	*config.CommonFields
 	// plugins config
 	ForwardersConfig []plugin.Config `mapstructure:"forwarders"`  // forwarder plugins config
 	FallbackerConfig plugin.Config   `mapstructure:"fallbacker"`  // fallbacker plugins config
diff --git a/plugins/server/prometheus/prometheus.go b/plugins/server/prometheus/prometheus.go
index ec32098..17b0543 100644
--- a/plugins/server/prometheus/prometheus.go
+++ b/plugins/server/prometheus/prometheus.go
@@ -49,7 +49,7 @@
 func (s *Server) DefaultConfig() string {
 	return `
 # The prometheus server address.
-address: ":9299"
+address: ":1234"
 # The prometheus server metrics endpoint.
 endpoint: "/metrics"
 `
diff --git a/tools/docker_build.sh b/tools/docker_build.sh
new file mode 100644
index 0000000..c61033a
--- /dev/null
+++ b/tools/docker_build.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+
+#
+# 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.
+#
+
+ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd .. && pwd)"
+DOCKER_DIR=$ROOT_DIR/docker
+VERSION=$1
+DIST_NAME=skywalking-satellite-$VERSION-bin
+DIST_FILE=$ROOT_DIR/$DIST_NAME.tgz
+DOCKER_DIST_FILE=$DOCKER_DIR/$DIST_NAME.tgz
+
+if [ ! -f "$DIST_FILE" ]; then
+  echo "$DIST_FILE is not exist, could not build the skywalking-satellite docker image."
+  exit 1
+fi
+
+rm -rf "$DOCKER_DIST_FILE"
+cp "$DIST_FILE" "$DOCKER_DIST_FILE"
+docker build --build-arg DIST_NAME="$DIST_NAME" -t skywalking-satellite:"$VERSION" --no-cache "$DOCKER_DIR"
+
+if [ $? -eq 0 ]; then
+ echo "skywalking-satellite:$VERSION docker images build success!"
+else
+ echo "skywalking-satellite:$VERSION docker images build failure!"
+ exit 1
+fi