Skip to content

Commit

Permalink
Add docker test
Browse files Browse the repository at this point in the history
  • Loading branch information
abericyang@gmail.com committed May 16, 2019
1 parent b7ce169 commit 2eceb17
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 9 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,19 @@ logs
/.maintainer.yml
/_config.yml
a.txt
/bow/runner/bow_darwin_amd64
/bow/runner/bow_linux_amd64
/shunt/runner/shunt_darwin_amd64
/shunt/runner/shunt_linux_amd64
/bow/runner/bow_freebsd_amd64
/bow/runner/bow_linux_386
/bow/runner/bow_windows_amd64
/bow/runner/bow_freebsd_386
/bow/runner/bow_darwin_386
/bow/runner/bow_windows_386
/shunt/runner/shunt_windows_386
/shunt/runner/shunt_windows_amd64
/shunt/runner/shunt_freebsd_386
/shunt/runner/shunt_freebsd_amd64
/shunt/runner/shunt_linux_386
/shunt/runner/shunt_darwin_386
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:1.12.3 as builder
LABEL app="rivet" by="ennoo"
ENV REPO=$GOPATH/src/github.com/ennoo/rivet
WORKDIR $REPO
RUN go get github.com/ennoo/rivet
RUN CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o $REPO/rivet/bow/runner/bow_darwin_amd64 $REPO/rivet/bow/runner

FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder $REPO/rivet/bow/runner/bow_darwin_amd64 .
EXPOSE 19219
CMD ["./bow_darwin_amd64"]
72 changes: 71 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,74 @@ veralls:

test:
@echo "test"
go test -v -cover $(PKGS_WITH_OUT_EXAMPLES)
go test -v -cover $(PKGS_WITH_OUT_EXAMPLES)

build_all: build_bow_all build_shunt_all

build_bow_all: build_bow_amd64_all build_bow_386_all

build_bow_amd64_all: build_bow_darwin_amd64 build_bow_linux_amd64 build_bow_windows_amd64 build_bow_freebsd_amd64

build_bow_386_all: build_bow_darwin_386 build_bow_linux_386 build_bow_windows_386 build_bow_freebsd_386

build_shunt_all: build_shunt_amd64_all build_shunt_386_all

build_shunt_amd64_all: build_shunt_darwin_amd64 build_shunt_linux_amd64 build_shunt_windows_amd64 build_shunt_freebsd_amd64

build_shunt_386_all: build_shunt_darwin_386 build_shunt_linux_386 build_shunt_windows_386 build_shunt_freebsd_386


build_bow_darwin_amd64_docker:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ./rivet/bow/runner/bow_darwin_amd64 ./rivet/bow/runner

build_bow_darwin_amd64:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o $(GOPATH)/src/github.com/ennoo/rivet/bow/runner/bow_darwin_amd64 $(GOPATH)/src/github.com/ennoo/rivet/bow/runner

build_bow_linux_amd64:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(GOPATH)/src/github.com/ennoo/rivet/bow/runner/bow_linux_amd64 $(GOPATH)/src/github.com/ennoo/rivet/bow/runner

build_bow_windows_amd64:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o $(GOPATH)/src/github.com/ennoo/rivet/bow/runner/bow_windows_amd64 $(GOPATH)/src/github.com/ennoo/rivet/bow/runner

build_bow_freebsd_amd64:
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -o $(GOPATH)/src/github.com/ennoo/rivet/bow/runner/bow_freebsd_amd64 $(GOPATH)/src/github.com/ennoo/rivet/bow/runner


build_bow_darwin_386:
CGO_ENABLED=0 GOOS=darwin GOARCH=386 go build -o $(GOPATH)/src/github.com/ennoo/rivet/bow/runner/bow_darwin_386 $(GOPATH)/src/github.com/ennoo/rivet/bow/runner

build_bow_linux_386:
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o $(GOPATH)/src/github.com/ennoo/rivet/bow/runner/bow_linux_386 $(GOPATH)/src/github.com/ennoo/rivet/bow/runner

build_bow_windows_386:
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o $(GOPATH)/src/github.com/ennoo/rivet/bow/runner/bow_windows_386 $(GOPATH)/src/github.com/ennoo/rivet/bow/runner

build_bow_freebsd_386:
CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -o $(GOPATH)/src/github.com/ennoo/rivet/bow/runner/bow_freebsd_386 $(GOPATH)/src/github.com/ennoo/rivet/bow/runner



build_shunt_darwin_amd64:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner/shunt_darwin_amd64 $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner

build_shunt_linux_amd64:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner/shunt_linux_amd64 $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner

build_shunt_windows_amd64:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner/shunt_windows_amd64 $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner

build_shunt_freebsd_amd64:
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -o $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner/shunt_freebsd_amd64 $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner


build_shunt_darwin_386:
CGO_ENABLED=0 GOOS=darwin GOARCH=386 go build -o $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner/shunt_darwin_386 $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner

build_shunt_linux_386:
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner/shunt_linux_386 $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner

build_shunt_windows_386:
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -o $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner/shunt_windows_386 $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner

build_shunt_freebsd_386:
CGO_ENABLED=0 GOOS=freebsd GOARCH=386 go build -o $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner/shunt_freebsd_386 $(GOPATH)/src/github.com/ennoo/rivet/shunt/runner
71 changes: 71 additions & 0 deletions bow/runner/bow.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2019. ENNOO - All Rights Reserved.
*
* Licensed 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.
*/

package main

import (
"github.com/ennoo/rivet"
"github.com/ennoo/rivet/bow"
"github.com/ennoo/rivet/trans/response"
"github.com/ennoo/rivet/utils/env"
"github.com/ennoo/rivet/utils/log"
"go.uber.org/zap/zapcore"
"strings"
)

func main() {
rivet.Initialize(false, true, false)
rivet.Log().Conf(&log.Config{
FilePath: strings.Join([]string{"./logs/rivet.log"}, ""),
Level: zapcore.DebugLevel,
MaxSize: 128,
MaxBackups: 30,
MaxAge: 30,
Compress: true,
ServiceName: env.GetEnvDefault("SERVICE_NAME", "shunt1"),
})
rivet.UseBow(func(result *response.Result) bool {
return true
})
rivet.Bow().Add(
&bow.RouteService{
Name: "test1",
InURI: "hello1",
OutRemote: "http://localhost:8081",
OutURI: "rivet/shunt",
Limit: &bow.Limit{
LimitMillisecond: int64(3 * 1000),
LimitCount: 3,
LimitIntervalMillisecond: 150,
LimitChan: make(chan int, 10),
},
},
&bow.RouteService{
Name: "test2",
InURI: "hello2",
OutRemote: "https://localhost:8092",
OutURI: "rivet/shunt",
Limit: &bow.Limit{
LimitMillisecond: int64(3 * 1000),
LimitCount: 3,
LimitIntervalMillisecond: 150,
LimitChan: make(chan int, 10),
},
},
)
rivet.ListenAndServe(&rivet.ListenServe{
Engine: rivet.SetupRouter(),
DefaultPort: "19219",
}, strings.Join([]string{env.GetEnv(env.GOPath), "/src/github.com/ennoo/rivet/examples/tls/rootCA.crt"}, ""))
}
2 changes: 1 addition & 1 deletion examples/bow1/bow1.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package main

import (
"github.com/ennoo/rivet/rivet"
"github.com/ennoo/rivet"
"github.com/ennoo/rivet/trans/response"
"github.com/ennoo/rivet/utils/env"
"strings"
Expand Down
2 changes: 1 addition & 1 deletion examples/bow2/bow2.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package main

import (
"github.com/ennoo/rivet"
"github.com/ennoo/rivet/bow"
"github.com/ennoo/rivet/rivet"
"github.com/ennoo/rivet/trans/response"
"github.com/ennoo/rivet/utils/env"
"strings"
Expand Down
2 changes: 1 addition & 1 deletion examples/shunt1/shunt1.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package main

import (
"github.com/ennoo/rivet"
"github.com/ennoo/rivet/discovery"
"github.com/ennoo/rivet/rivet"
"github.com/ennoo/rivet/shunt"
"github.com/ennoo/rivet/trans/response"
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion examples/trans1/trans1.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package main

import (
"fmt"
"github.com/ennoo/rivet"
"github.com/ennoo/rivet/discovery"
"github.com/ennoo/rivet/examples/model"
"github.com/ennoo/rivet/rivet"
"github.com/ennoo/rivet/trans/request"
"github.com/ennoo/rivet/trans/response"
"github.com/ennoo/rivet/utils/ip"
Expand Down
2 changes: 1 addition & 1 deletion examples/trans1/trans_tls1.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package main

import (
"github.com/ennoo/rivet"
"github.com/ennoo/rivet/examples/model"
"github.com/ennoo/rivet/rivet"
"github.com/ennoo/rivet/trans/response"
"github.com/ennoo/rivet/utils/env"
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion examples/trans2/trans2.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package main

import (
"github.com/ennoo/rivet"
"github.com/ennoo/rivet/discovery"
"github.com/ennoo/rivet/examples/model"
"github.com/ennoo/rivet/rivet"
"github.com/ennoo/rivet/trans/response"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/trans2/trans_tls2.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package main

import (
"github.com/ennoo/rivet"
"github.com/ennoo/rivet/examples/model"
"github.com/ennoo/rivet/rivet"
"github.com/ennoo/rivet/trans/response"
"github.com/ennoo/rivet/utils/env"
"strings"
Expand Down
2 changes: 1 addition & 1 deletion examples/trans3/trans3.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package main

import (
"github.com/ennoo/rivet"
"github.com/ennoo/rivet/discovery"
"github.com/ennoo/rivet/examples/model"
"github.com/ennoo/rivet/rivet"
"github.com/ennoo/rivet/trans/response"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
70 changes: 70 additions & 0 deletions shunt/runner/shunt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2019. ENNOO - All Rights Reserved.
*
* Licensed 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.
*/

package main

import (
"github.com/ennoo/rivet"
"github.com/ennoo/rivet/discovery"
"github.com/ennoo/rivet/shunt"
"github.com/ennoo/rivet/trans/response"
"github.com/ennoo/rivet/utils/env"
"github.com/ennoo/rivet/utils/log"
"go.uber.org/zap/zapcore"
"net/http"
"strings"
)

func main() {
rivet.Initialize(true, true, true)
rivet.Log().Conf(&log.Config{
FilePath: strings.Join([]string{"./logs/rivet.log"}, ""),
Level: zapcore.DebugLevel,
MaxSize: 128,
MaxBackups: 30,
MaxAge: 30,
Compress: true,
ServiceName: env.GetEnvDefault("SERVICE_NAME", "shunt1"),
})
rivet.UseDiscovery(discovery.ComponentConsul, "127.0.0.1:8500", "shunt", "127.0.0.1", 8083)
rivet.Shunt().Register("test", shunt.Round)
rivet.Shunt().Register("test1", shunt.Random)
rivet.Shunt().Register("test2", shunt.Hash)
//addAddress()
rivet.ListenAndServe(&rivet.ListenServe{
Engine: rivet.SetupRouter(testShunt1),
DefaultPort: "19219",
})
}

func testShunt1(router *response.Router) {
// 仓库相关路由设置
router.Group = router.Engine.Group("/rivet")
router.GET("/shunt/:serviceName", shunt3)
router.POST("/shunt", shunt4)
}

func shunt3(router *response.Router) {
rivet.Response().Do(router.Context, func(result *response.Result) {
serviceName := router.Context.Param("serviceName")
rivet.Shunt().Register(serviceName, shunt.Round)
result.SaySuccess(router.Context, "test2")
})
}

func shunt4(router *response.Router) {
rivet.Request().Callback(router.Context, http.MethodPost, "test", "rivet/shunt", func() *response.Result {
return &response.Result{ResultCode: response.Success, Msg: "降级处理"}
})
}

0 comments on commit 2eceb17

Please sign in to comment.