Skip to content

Commit

Permalink
refactor mesher pkg, add build script for local dev (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiaoliang authored Jul 1, 2019
1 parent ae64dd0 commit 41e7e43
Show file tree
Hide file tree
Showing 110 changed files with 445 additions and 391 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ vendor
_build
coverage.txt
go.sum
release
8 changes: 4 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ pipeline {
agent any

stages {
stage('Build Mesher') {
stage('Build proxy') {
steps {
echo 'Making Package'
sh 'bash -x scripts/build/build.sh'
sh 'bash -x ci/build.sh'
}
}
stage('Create Docker Image') {
stage('Create proxy image') {
steps {
echo 'Building Docker Image'
sh 'bash -x scripts/build/build_image.sh'
sh 'bash -x ci/build_image.sh'
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ a go micro service framework
Refer to [mesher-examples](https://github.com/go-mesh/mesher-examples)

### How to build and run

#### Build from scratch
1. Install ServiceComb [service-center](https://github.com/ServiceComb/service-center/releases)

2. build and run, use go mod(go 1.11+, experimental but a recommended way)
Expand All @@ -35,6 +35,15 @@ GO111MODULE=on go mod vendor
go build mesher.go
./mesher
```
####Build script
```bash
cd build
./build_proxy.sh

```
it will build binary and docker image
- tar file: release/mesher-latest-linux-amd64.tar
- docker: servicecomb/mesher:latest

# Documentations

Expand Down
62 changes: 0 additions & 62 deletions adminapi/restful.go

This file was deleted.

64 changes: 0 additions & 64 deletions adminapi/router.go

This file was deleted.

64 changes: 64 additions & 0 deletions build/build_proxy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
set -e
set -x
export BUILD_DIR=$(cd "$(dirname "$0")"; pwd)
export PROJECT_DIR=$(dirname ${BUILD_DIR})

if [ -z "${GOPATH}" ]; then
echo "missing GOPATH env, can not build"
exit 1
fi
echo "GOPATH is "${GOPATH}


#To checkout to particular commit or tag
if [ "$VERSION" == "" ]; then
echo "using latest code"
VERSION="latest"
else
git checkout $VERSION
fi

release_dir=$PROJECT_DIR/release
mkdir -p $release_dir
cd $PROJECT_DIR
GO111MODULE=on go mod download
GO111MODULE=on go mod vendor
go build -o mesher -a

cp -r $PROJECT_DIR/licenses $release_dir
cp -r $PROJECT_DIR/conf $release_dir
cp $PROJECT_DIR/start.sh $release_dir
cp $PROJECT_DIR/mesher $release_dir
if [ ! "$GIT_COMMIT" ];then
export GIT_COMMIT=`git rev-parse HEAD`
fi

export GIT_COMMIT=`echo $GIT_COMMIT | cut -b 1-7`
BUILD_TIME=$(date +"%Y-%m-%d %H:%M:%S +%z")

cat << EOF > $release_dir/VERSION
---
version: $VERSION
commit: $GIT_COMMIT
built: $BUILD_TIME
EOF


cd $release_dir

chmod +x start.sh mesher

pkg_name="mesher-$VERSION-linux-amd64.tar.gz"

tar zcvf $pkg_name licenses conf mesher VERSION
tar zcvf mesher.tar.gz licenses conf mesher VERSION start.sh





echo "building docker..."
cd ${release_dir}
cp ${PROJECT_DIR}/build/docker/proxy/Dockerfile ./
sudo docker build -t servicecomb/mesher:${VERSION} .
File renamed without changes.
2 changes: 1 addition & 1 deletion conf/lager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ logger_file: log/mesher.log

# LogFormatText: json/plaintext (such as log4j),default to false
# if set logger_file and log_format_text to true, turns out log4j format log
log_format_text: true
log_format_text: false

#rollingPolicy daily/size; defines rotate according to daily or size
rollingPolicy: size
Expand Down
3 changes: 3 additions & 0 deletions conf/mesher.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ admin: #admin API
#pprof:
# enable: false


# this health check will ping local service port to check if service is still alive, if service can not reachable, mesher
# will update status to OUT_OF_SERVICE in service center
#localHealthCheck:
# - port: 8080
# uri: /health
Expand Down
22 changes: 11 additions & 11 deletions mesher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ package main
import (
_ "net/http/pprof"

_ "github.com/go-mesh/mesher/resolver/authority"
_ "github.com/go-mesh/mesher/proxy/resolver/authority"

_ "github.com/go-mesh/mesher/handler"
_ "github.com/go-mesh/mesher/protocol/dubbo/client/chassis"
_ "github.com/go-mesh/mesher/protocol/dubbo/server"
_ "github.com/go-mesh/mesher/protocol/dubbo/simpleRegistry"
_ "github.com/go-mesh/mesher/proxy/handler"
_ "github.com/go-mesh/mesher/proxy/protocol/dubbo/client/chassis"
_ "github.com/go-mesh/mesher/proxy/protocol/dubbo/server"
_ "github.com/go-mesh/mesher/proxy/protocol/dubbo/simpleRegistry"

_ "github.com/go-chassis/go-chassis/configcenter" //use config center
//protocols
_ "github.com/go-mesh/mesher/protocol/grpc"
_ "github.com/go-mesh/mesher/protocol/http"
_ "github.com/go-mesh/mesher/proxy/protocol/grpc"
_ "github.com/go-mesh/mesher/proxy/protocol/http"

"github.com/go-mesh/mesher/server"
"github.com/go-mesh/mesher/proxy/server"

_ "github.com/go-mesh/mesher/pkg/egress/archaius"
_ "github.com/go-mesh/mesher/pkg/egress/pilot"
_ "github.com/go-mesh/mesher/proxy/pkg/egress/archaius"
_ "github.com/go-mesh/mesher/proxy/pkg/egress/pilot"

_ "github.com/go-mesh/mesher/control/istio"
_ "github.com/go-mesh/mesher/proxy/control/istio"
)

func main() {
Expand Down
1 change: 0 additions & 1 deletion plugins/control/README.md

This file was deleted.

24 changes: 12 additions & 12 deletions bootstrap/bootstrap.go → proxy/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ import (
"log"
"strings"

"github.com/go-mesh/mesher/adminapi"
"github.com/go-mesh/mesher/adminapi/version"
"github.com/go-mesh/mesher/cmd"
"github.com/go-mesh/mesher/common"
"github.com/go-mesh/mesher/config"
"github.com/go-mesh/mesher/register"
"github.com/go-mesh/mesher/resolver"
"github.com/go-mesh/mesher/proxy/cmd"
"github.com/go-mesh/mesher/proxy/common"
"github.com/go-mesh/mesher/proxy/config"
"github.com/go-mesh/mesher/proxy/register"
"github.com/go-mesh/mesher/proxy/resolver"

"github.com/go-chassis/go-chassis"
"github.com/go-chassis/go-chassis/core/handler"
chassisHandler "github.com/go-chassis/go-chassis/core/handler"
"github.com/go-chassis/go-chassis/core/lager"
"github.com/go-chassis/go-chassis/core/metadata"
"github.com/go-mesh/mesher/control"
"github.com/go-mesh/mesher/pkg/egress"
"github.com/go-mesh/mesher/pkg/metrics"
"github.com/go-mesh/mesher/pkg/runtime"
"github.com/go-mesh/mesher/proxy/control"
"github.com/go-mesh/mesher/proxy/pkg/egress"
"github.com/go-mesh/mesher/proxy/pkg/metrics"
"github.com/go-mesh/mesher/proxy/pkg/runtime"
"github.com/go-mesh/mesher/proxy/resource/v1"
"github.com/go-mesh/mesher/proxy/resource/v1/version"
"github.com/go-mesh/openlogging"
)

Expand All @@ -56,7 +56,7 @@ func Start() error {
return err
}
metrics.Init()
if err := adminapi.Init(); err != nil {
if err := v1.Init(); err != nil {
log.Println("Error occurred in starting admin server", err)
}
if err := register.AdaptEndpoints(); err != nil {
Expand Down
11 changes: 6 additions & 5 deletions cmd/cmd.go → proxy/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package cmd
import (
"fmt"
chassiscommon "github.com/go-chassis/go-chassis/core/common"
"github.com/go-mesh/mesher/common"
"github.com/go-mesh/mesher/proxy/common"
"github.com/urfave/cli"
"log"
"os"
Expand All @@ -45,17 +45,18 @@ var Configs *ConfigFromCmd
func parseConfigFromCmd(args []string) (err error) {
app := cli.NewApp()
app.HideVersion = true
app.Usage = "Service mesh."
app.Usage = "a service mesh that governance your service traffic."
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config",
Usage: "mesher config file, example: --config=mesher.yaml",
Destination: &Configs.ConfigFile,
},
cli.StringFlag{
Name: "mode",
Value: common.ModeSidecar,
Usage: fmt.Sprintf("mesher running mode [ %s|%s ]", common.ModePerHost, common.ModeSidecar),
Name: "mode",
Value: common.ModeSidecar,
Usage: fmt.Sprintf("mesher running mode [ %s|%s|%s ]",
common.ModePerHost, common.ModeSidecar, common.ModeIngress),
Destination: &Configs.Mode,
},
cli.StringFlag{
Expand Down
4 changes: 2 additions & 2 deletions cmd/cmd_test.go → proxy/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package cmd_test

import (
"github.com/go-chassis/go-chassis/core/lager"
"github.com/go-mesh/mesher/cmd"
"github.com/go-mesh/mesher/common"
"github.com/go-mesh/mesher/proxy/cmd"
"github.com/go-mesh/mesher/proxy/common"
"github.com/stretchr/testify/assert"
"os"
"testing"
Expand Down
3 changes: 3 additions & 0 deletions common/common.go → proxy/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const ComponentName = "mesher"
//ModeSidecar is constant for side car mode
const ModeSidecar = "sidecar"

//ModeIngress run as a api gateway, or ingress in k8s
const ModeIngress = "ingress"

//ModePerHost is constant for side car mode
const ModePerHost = "per-host"

Expand Down
Loading

0 comments on commit 41e7e43

Please sign in to comment.