initial import

This commit is contained in:
kevin
2020-07-26 17:09:05 +08:00
commit 7e3a369a8f
647 changed files with 54754 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
FROM golang:1.13-alpine AS builder
LABEL stage=gobuilder
ENV CGO_ENABLED 0
ENV GOOS linux
ENV GOPROXY https://goproxy.cn,direct
WORKDIR $GOPATH/src/zero
COPY . .
RUN go build -ldflags="-s -w" -o /app/unaryserver example/rpc/server/unary/server.go
FROM alpine
RUN apk add --no-cache tzdata
ENV TZ Asia/Shanghai
WORKDIR /app
COPY --from=builder /app/unaryserver /app/unaryserver
COPY example/rpc/server/unary/etc/k8s.json /app/
CMD ["./unaryserver", "-f", "k8s.json"]

View File

@@ -0,0 +1,11 @@
version := v1
build:
cd $(GOPATH)/src/zero && docker build -t registry.cn-hangzhou.aliyuncs.com/xapp/unaryserver:$(version) . -f example/rpc/server/unary/Dockerfile
docker image prune --filter label=stage=gobuilder -f
push: build
docker push registry.cn-hangzhou.aliyuncs.com/xapp/unaryserver:$(version)
deploy: push
kubectl -n adhoc set image deployment/unaryserver-deployment unaryserver=registry-vpc.cn-hangzhou.aliyuncs.com/xapp/unaryserver:$(version)

View File

@@ -0,0 +1,13 @@
{
"Name": "rpc.unary",
"Log": {
"Mode": "volume"
},
"ListenOn": "localhost:3456",
"Etcd": {
"Hosts": [
"localhost:2379"
],
"Key": "rpcx"
}
}

View File

@@ -0,0 +1,17 @@
{
"Name": "rpc.unary",
"MetricsUrl": "http://localhost:2222/add",
"ListenOn": "localhost:3457",
"Auth": false,
"Etcd": {
"Hosts": [
"localhost:2379"
],
"Key": "rpcx"
},
"Redis": {
"Host": "localhost:6379",
"Type": "node",
"Key": "apps"
}
}

View File

@@ -0,0 +1,12 @@
{
"Name": "rpc.unary",
"ListenOn": "0.0.0.0:3456",
"Auth": false,
"Etcd": {
"Hosts": [
"etcd.discov:2379"
],
"Key": "rpcx"
},
"Timeout": 500
}

View File

@@ -0,0 +1,55 @@
package main
import (
"context"
"flag"
"fmt"
"os"
"sync"
"time"
"zero/core/conf"
"zero/example/rpc/remote/unary"
"zero/rpcx"
"google.golang.org/grpc"
)
var configFile = flag.String("f", "etc/config.json", "the config file")
type GreetServer struct {
lock sync.Mutex
alive bool
downTime time.Time
}
func NewGreetServer() *GreetServer {
return &GreetServer{
alive: true,
}
}
func (gs *GreetServer) Greet(ctx context.Context, req *unary.Request) (*unary.Response, error) {
fmt.Println("=>", req)
hostname, err := os.Hostname()
if err != nil {
return nil, err
}
return &unary.Response{
Greet: "hello from " + hostname,
}, nil
}
func main() {
flag.Parse()
var c rpcx.RpcServerConf
conf.MustLoad(*configFile, &c)
server := rpcx.MustNewServer(c, func(grpcServer *grpc.Server) {
unary.RegisterGreeterServer(grpcServer, NewGreetServer())
})
server.Start()
}

View File

@@ -0,0 +1,25 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: unaryserver-deployment
namespace: adhoc
labels:
app: unaryserver
spec:
replicas: 3
selector:
matchLabels:
app: unaryserver
template:
metadata:
labels:
app: unaryserver
spec:
containers:
- name: unaryserver
image: registry-vpc.cn-hangzhou.aliyuncs.com/xapp/unaryserver:v1
imagePullPolicy: Always
ports:
- containerPort: 3456
imagePullSecrets:
- name: aliyun