Skip to content

Commit

Permalink
Merge pull request #119 from eolinker/release/v0.13.0
Browse files Browse the repository at this point in the history
Release/v0.13.0
  • Loading branch information
Dot-Liu authored Jun 28, 2023
2 parents af6c54a + 9f344c1 commit f458b29
Show file tree
Hide file tree
Showing 24 changed files with 204 additions and 615 deletions.
61 changes: 21 additions & 40 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ stages:
# - check
- build
- deploy
- publish
# - publish

variables:
PATH: /usr/local/sonar-scanner/sonar-scanner-4.4.0.2170-linux/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/data/golang/go/bin/:/root/go/bin
GOROOT: /data/golang/go
PATH: /opt/go/go/bin/:/opt/node/node/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
GOROOT: /opt/go/go
GOPROXY: https://goproxy.cn
APP: apinto
VERSION: $CI_COMMIT_SHORT_SHA
SAVE_DIR: /opt/apinto
VERSION: $CI_COMMIT_SHORT_SHA
APP: apinto
APP_PRE: ${APP}-${VERSION}
BUILD_DIR: apserver-build

default:
before_script:
Expand All @@ -30,25 +31,14 @@ merge-informer: # 飞书回调
curl -X POST -H "Content-Type: application/json" \
-d "{\"msg_type\":\"text\",\"content\":{\"text\":\"项目:${CI_PROJECT_NAME}\\n提交人:${GITLAB_USER_NAME}\\n提交信息:${CI_MERGE_REQUEST_TITLE}\\n合并分支信息:${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME} -> ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}\\n差异性地址:${DIFF_URL}\\n请及时review代码\"}}" \
https://open.feishu.cn/open-apis/bot/v2/hook/1c334752-2874-41a1-8f1b-3060f2d46b6c
# checker:
# stage: check
# rules:
# - if: $CI_COMMIT_BRANCH=="develop"
# script:
# - set +e
# - go mod tidy
# - go test -covermode=atomic -coverpkg=./... -coverprofile=coverage.data -timeout=1m ./...
# - golangci-lint run --timeout=3m --out-format checkstyle --issues-exit-code 0 ./... > report.xml
# - sonar-scanner
builder:
stage: build
rules:
- if: $CI_COMMIT_BRANCH=="develop"
# when: on_success
- if: $CI_COMMIT_BRANCH=="test"
# when: on_success
- if: $CI_COMMIT_BRANCH=="main"
script:
- sed -i '/replace github.com\/eolinker\/eosc => */d' go.mod
# - sed -i '/replace github.com\/eolinker\/eosc => */d' go.mod
- cd ../eosc && git pull && cd ../apinto
- go mod tidy
- cd build/cmd && ./package.sh $VERSION
cache:
Expand All @@ -57,35 +47,26 @@ builder:
deployer:
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH=="develop"
- if: $CI_COMMIT_BRANCH=="main"
variables:
DEPLOY_SERVER: root@172.18.189.43
DEPLOY_DESC: "DEV 环境"
- if: $CI_COMMIT_BRANCH=="test"
variables:
DEPLOY_SERVER: root@172.18.65.60
DEPLOY_DESC: "TEST 环境"
dependencies:
- builder
script:
- set -e
- scp out/${APP_PRE}.linux.x64.tar.gz ${DEPLOY_SERVER}:${SAVE_DIR}
- ssh ${DEPLOY_SERVER} "set -e; cd ${SAVE_DIR}; mkdir -p ${APP_PRE};tar -zxvf ${APP_PRE}.linux.x64.tar.gz -C ${APP_PRE};cd ${APP_PRE}/${APP}; ./install.sh upgrade;cd ${SAVE_DIR}; ./clean.sh ${APP_PRE}"
- cp out/${APP_PRE}.linux.x64.tar.gz ${SAVE_DIR}
- cd ${SAVE_DIR};cd ${SAVE_DIR}; mkdir -p ${APP_PRE};tar -zxvf ${APP_PRE}.linux.x64.tar.gz -C ${APP_PRE};cd ${APP_PRE}/${APP}
- ln -snF ${SAVE_DIR}/etc/tmp ./ && cp ${SAVE_DIR}/etc/apinto.yml ./ && cp ${SAVE_DIR}/etc/config.yml ./
- pwd
- ./apinto stop
- sleep 10s
- ./apinto start
- ps -ef | grep apinto
- cd ${SAVE_DIR}; ./clean.sh ${APP_PRE}
- |
curl -X POST -H "Content-Type: application/json" \
-d "{\"msg_type\":\"text\",\"content\":{\"text\":\"项目:apinto\\n环境:${DEPLOY_DESC}\\n更新部署完成.\"}}" \
https://open.feishu.cn/open-apis/bot/v2/hook/1c334752-2874-41a1-8f1b-3060f2d46b6c
when: on_success
cache:
paths:
- out/
publisher:
stage: publish
only:
- tags
script:
- sed -i '/replace github.com\/eolinker\/eosc => */d' go.mod
- go mod tidy
- GOVERSION=$(go version) EoscVersion=$(sed -n 's/.*eosc v/v/p' go.mod) goreleaser release --skip-validate --rm-dist --skip-publish
- mkdir -p /data/pkg/apinto/${CI_COMMIT_TAG}
- cp -if dist/*.tar.gz /data/pkg/apinto/${CI_COMMIT_TAG}
- out/
4 changes: 2 additions & 2 deletions discovery/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func (n *_BaseNode) Last() time.Time {

}

func newBaseNode(ip string, port int, statusChecker _INodeStatusCheck) *_BaseNode {
return &_BaseNode{ip: ip, port: port, status: Running, statusChecker: statusChecker}
func newBaseNode(id string, ip string, port int, statusChecker _INodeStatusCheck) *_BaseNode {
return &_BaseNode{id: id, ip: ip, port: port, status: Running, statusChecker: statusChecker}
}

func (n *_BaseNode) ID() string {
Expand Down
2 changes: 1 addition & 1 deletion discovery/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (ac *appContainer) Get(ip string, port int) INode {
return node
}

ac.nodes.Set(id, newBaseNode(ip, port, ac))
ac.nodes.Set(id, newBaseNode(id, ip, port, ac))
node, _ = ac.nodes.Get(id)
return node
}
Expand Down
22 changes: 10 additions & 12 deletions drivers/discovery/consul/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ func newClients(addrs []string, param map[string]string) *consulClients {
clients := make([]*api.Client, 0, len(addrs))

defaultConfig := api.DefaultConfig()
if _, has := param["token"]; has {
defaultConfig.Token = param["token"]
if v, has := param["token"]; has {
defaultConfig.Token = v
}
if _, has := param["namespace"]; has {
defaultConfig.Namespace = param["namespace"]
if v, has := param["namespace"]; has {
defaultConfig.Namespace = v
}

for _, addr := range addrs {
Expand Down Expand Up @@ -53,8 +53,9 @@ func (c *consulClients) getNodes(service string) ([]discovery.NodeInfo, error) {
nodeList := make([]discovery.NodeInfo, 0, 2)
nodeIDSet := make(map[string]struct{})
for _, client := range c.clients {
clientNodes := getNodesFromClient(client, service)
if len(clientNodes) == 0 {
clientNodes, err := getNodesFromClient(client, service)
if err != nil {
log.Warnf("consul client down for service %s", service)
continue
}
for _, n := range clientNodes {
Expand All @@ -64,19 +65,16 @@ func (c *consulClients) getNodes(service string) ([]discovery.NodeInfo, error) {
nodeIDSet[n.id] = struct{}{}
}
}
if len(nodeList) == 0 {
return nil, discovery.ErrDiscoveryDown
}

return nodeList, nil
}

// getNodesFromClient 从连接的客户端返回健康的节点信息
func getNodesFromClient(client *api.Client, service string) []*consulNodeInfo {
func getNodesFromClient(client *api.Client, service string) ([]*consulNodeInfo, error) {
queryOptions := &api.QueryOptions{}
serviceEntryArr, _, err := client.Health().Service(service, "", true, queryOptions)
if err != nil {
return nil
return nil, err
}

nodes := make([]*consulNodeInfo, 0, len(serviceEntryArr))
Expand All @@ -91,5 +89,5 @@ func getNodesFromClient(client *api.Client, service string) []*consulNodeInfo {
})
}

return nodes
return nodes, nil
}
3 changes: 0 additions & 3 deletions drivers/discovery/consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func (c *consul) Start() error {
nodeSet, err := c.clients.getNodes(serviceName)
if err != nil {
log.Warnf("consul %s:%s for service %s", c.Name(), discovery.ErrDiscoveryDown, serviceName)
continue
}
//更新目标服务的节点列表
c.services.Set(serviceName, nodeSet)
Expand Down Expand Up @@ -83,8 +82,6 @@ func (c *consul) Stop() error {

// GetApp 获取服务发现中目标服务的app
func (c *consul) GetApp(serviceName string) (discovery.IApp, error) {
var err error
var has bool
c.locker.RLock()
app, has := c.services.GetApp(serviceName)
c.locker.RUnlock()
Expand Down
9 changes: 2 additions & 7 deletions drivers/discovery/eureka/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ func newClient(address []string, params url.Values) *client {

// GetNodeList 从eureka接入地址中获取对应服务的节点列表
func (c *client) GetNodeList(serviceName string) ([]discovery.NodeInfo, error) {
isOk := false
nodes := make([]discovery.NodeInfo, 0, 5)
sets := make(map[string]struct{})
for _, addr := range c.address {
app, err := c.GetApplication(addr, serviceName)
if err != nil {
log.Info("eureka get node instance list error:", err)
log.Warnf("eureka get node instance list fail. err: %w", err)
continue
}
isOk = true
for _, ins := range app.Instances {
if ins.Status != eurekaStatusUp {
continue
Expand All @@ -54,12 +52,9 @@ func (c *client) GetNodeList(serviceName string) ([]discovery.NodeInfo, error) {
}
nodes = append(nodes, node)
}

}
}
if !isOk {
return nil, discovery.ErrDiscoveryDown
}

return nodes, nil
}

Expand Down
3 changes: 0 additions & 3 deletions drivers/discovery/eureka/eureka.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ func (e *eureka) Start() error {
res, err := e.client.GetNodeList(serviceName)
if err != nil {
log.Warnf("eureka %s:%w for service %s", e.Name(), discovery.ErrDiscoveryDown, serviceName)
continue
}
//更新目标服务的节点列表
e.locker.Lock()
e.services.Set(serviceName, res)
e.locker.Unlock()
}
}
}
Expand Down
Loading

0 comments on commit f458b29

Please sign in to comment.