feat: Add the help chart script to support k8s deployment (#1145)

* Code adaptation k8s: service discovery and registration adaptation, configuration adaptation

* Initial submission of the help charts script for openim API

* change the help charts script

* change the help charts script

* change helm chart codes

* change dockerfiles script

* change chart script:add configmap mounts

* change chart script:change repository

* change chart script:msggateway add one service

* change config.yaml

* roll back some config values

* change chart script:change Ingress rule with a rewrite annotation

* add mysql charts scrible

* change chart script:add mysql.config.yaml

* add nfs provisioner charts

* change chart script:add nfs.config.yaml

* add ingress-nginx charts

* change chart script:add ingress-nginx.config.yaml

* add redis &mongodb charts

* add kafka&minio charts

* change chart script:change redis.values.yaml

* change chart script:add redis.config.yaml

* change chart script:change redis.config.yaml

* change chart script:change mongodb.value.yaml

* change chart script:change mongodb.value.yaml

* change chart script:add mongodb.config.yaml

* change chart script:change minio.values.yaml

* change chart script:add minio.config.yaml

* change chart script:change kafka.values.yaml

* change chart script:add kafka.config.yaml

* change chart script:change services.config.yaml

* bug fix:Delete websocket's Port restrictions

* bug fix:change port value

* change chart script:Submit a stable version script

* fix bug:Implement option interface

* fix bug:change K8sDR.Register

* change config.yaml

* change chats script:minio service add ingress

* change chats script:minio service add ingress

* change chats script:kafka.replicaCount=3& change minio.api ingress

* delete change chats script

* change config.yaml

* change openim.yaml

---------

Co-authored-by: lin.huang <lin.huang@apulis.com>
This commit is contained in:
xuexihuang 2023-10-16 18:02:12 +08:00 committed by GitHub
parent 81cc1f355a
commit abf8e37e78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 628 additions and 61 deletions

View File

@ -17,15 +17,13 @@ package main
import (
"context"
"fmt"
"github.com/openimsdk/open-im-server/v3/pkg/common/discovery_register"
"net"
"strconv"
"time"
_ "net/http/pprof"
"strconv"
"github.com/OpenIMSDK/protocol/constant"
"github.com/OpenIMSDK/tools/discoveryregistry"
openkeeper "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper"
"github.com/OpenIMSDK/tools/log"
"github.com/openimsdk/open-im-server/v3/internal/api"
@ -44,6 +42,7 @@ func main() {
}
func run(port int) error {
fmt.Println("*****openimapi port:", port)
if port == 0 {
return fmt.Errorf("port is empty")
}
@ -53,11 +52,13 @@ func run(port int) error {
}
fmt.Println("api start init discov client")
var client discoveryregistry.SvcDiscoveryRegistry
client, err = openkeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
openkeeper.WithFreq(time.Hour), openkeeper.WithUserNameAndPassword(
config.Config.Zookeeper.Username,
config.Config.Zookeeper.Password,
), openkeeper.WithRoundRobin(), openkeeper.WithTimeout(10), openkeeper.WithLogger(log.NewZkLogger()))
client, err = discovery_register.NewDiscoveryRegister(config.Config.Envs.Discovery)
/*
client, err = openkeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
openkeeper.WithFreq(time.Hour), openkeeper.WithUserNameAndPassword(
config.Config.Zookeeper.Username,
config.Config.Zookeeper.Password,
), openkeeper.WithRoundRobin(), openkeeper.WithTimeout(10), openkeeper.WithLogger(log.NewZkLogger()))*/
if err != nil {
return err
}

View File

@ -21,7 +21,7 @@ import (
)
func main() {
pushCmd := cmd.NewRpcCmd("push")
pushCmd := cmd.NewRpcCmd(cmd.RpcPushServer)
pushCmd.AddPortFlag()
pushCmd.AddPrometheusPortFlag()
if err := pushCmd.Exec(); err != nil {

View File

@ -21,7 +21,7 @@ import (
)
func main() {
authCmd := cmd.NewRpcCmd("auth")
authCmd := cmd.NewRpcCmd(cmd.RpcAuthServer)
authCmd.AddPortFlag()
authCmd.AddPrometheusPortFlag()
if err := authCmd.Exec(); err != nil {

View File

@ -21,7 +21,7 @@ import (
)
func main() {
rpcCmd := cmd.NewRpcCmd("conversation")
rpcCmd := cmd.NewRpcCmd(cmd.RpcConversationServer)
rpcCmd.AddPortFlag()
rpcCmd.AddPrometheusPortFlag()
if err := rpcCmd.Exec(); err != nil {

View File

@ -21,7 +21,7 @@ import (
)
func main() {
rpcCmd := cmd.NewRpcCmd("friend")
rpcCmd := cmd.NewRpcCmd(cmd.RpcFriendServer)
rpcCmd.AddPortFlag()
rpcCmd.AddPrometheusPortFlag()
if err := rpcCmd.Exec(); err != nil {

View File

@ -21,7 +21,7 @@ import (
)
func main() {
rpcCmd := cmd.NewRpcCmd("group")
rpcCmd := cmd.NewRpcCmd(cmd.RpcGroupServer)
rpcCmd.AddPortFlag()
rpcCmd.AddPrometheusPortFlag()
if err := rpcCmd.Exec(); err != nil {

View File

@ -21,7 +21,7 @@ import (
)
func main() {
rpcCmd := cmd.NewRpcCmd("msg")
rpcCmd := cmd.NewRpcCmd(cmd.RpcMsgServer)
rpcCmd.AddPortFlag()
rpcCmd.AddPrometheusPortFlag()
if err := rpcCmd.Exec(); err != nil {

View File

@ -21,7 +21,7 @@ import (
)
func main() {
rpcCmd := cmd.NewRpcCmd("third")
rpcCmd := cmd.NewRpcCmd(cmd.RpcThirdServer)
rpcCmd.AddPortFlag()
rpcCmd.AddPrometheusPortFlag()
if err := rpcCmd.Exec(); err != nil {

View File

@ -21,7 +21,7 @@ import (
)
func main() {
rpcCmd := cmd.NewRpcCmd("user")
rpcCmd := cmd.NewRpcCmd(cmd.RpcUserServer)
rpcCmd.AddPortFlag()
rpcCmd.AddPrometheusPortFlag()
if err := rpcCmd.Exec(); err != nil {

View File

@ -26,6 +26,9 @@
# Zookeeper address
# Zookeeper username
# Zookeeper password
envs:
discovery: zookeeper
zookeeper:
schema: openim
address: [ 172.28.0.1:12181 ]
@ -213,6 +216,7 @@ log:
# Websocket connection handshake timeout
longConnSvr:
openImWsPort: [ 10001 ]
openImMessageGatewayPort: [ 10140 ]
websocketMaxConnNum: 100000
websocketMaxMsgLen: 4096
websocketTimeout: 10

View File

@ -19,6 +19,9 @@
# --| target: config/config.yaml
# -----------------------------------------------------------------
envs:
discovery: ${ENVS_DISCOVERY}
###################### Zookeeper ######################
# Zookeeper configuration
# It's not recommended to modify the schema

View File

@ -143,9 +143,6 @@ func NewWsServer(opts ...Option) (*WsServer, error) {
for _, o := range opts {
o(&config)
}
if config.port < 1024 {
return nil, errors.New("port not allow to listen")
}
v := validator.New()
return &WsServer{
port: config.port,

View File

@ -16,14 +16,11 @@ package msgtransfer
import (
"fmt"
"sync"
"time"
"github.com/openimsdk/open-im-server/v3/pkg/common/discovery_register"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"sync"
openkeeper "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper"
"github.com/OpenIMSDK/tools/log"
"github.com/OpenIMSDK/tools/mw"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
@ -62,9 +59,11 @@ func StartTransfer(prometheusPort int) error {
if err := mongo.CreateMsgIndex(); err != nil {
return err
}
client, err := openkeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
openkeeper.WithFreq(time.Hour), openkeeper.WithRoundRobin(), openkeeper.WithUserNameAndPassword(config.Config.Zookeeper.Username,
config.Config.Zookeeper.Password), openkeeper.WithTimeout(10), openkeeper.WithLogger(log.NewZkLogger()))
client, err := discovery_register.NewDiscoveryRegister(config.Config.Envs.Discovery)
/*
client, err := openkeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
openkeeper.WithFreq(time.Hour), openkeeper.WithRoundRobin(), openkeeper.WithUserNameAndPassword(config.Config.Zookeeper.Username,
config.Config.Zookeeper.Password), openkeeper.WithTimeout(10), openkeeper.WithLogger(log.NewZkLogger()))*/
if err != nil {
return err
}

View File

@ -17,14 +17,12 @@ package tools
import (
"context"
"fmt"
"math"
"time"
"github.com/openimsdk/open-im-server/v3/pkg/common/discovery_register"
"github.com/redis/go-redis/v9"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"math"
"github.com/OpenIMSDK/tools/discoveryregistry/zookeeper"
"github.com/OpenIMSDK/tools/errs"
"github.com/OpenIMSDK/tools/log"
"github.com/OpenIMSDK/tools/mcontext"
@ -74,9 +72,11 @@ func InitMsgTool() (*MsgTool, error) {
if err != nil {
return nil, err
}
discov, err := zookeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
zookeeper.WithFreq(time.Hour), zookeeper.WithRoundRobin(), zookeeper.WithUserNameAndPassword(config.Config.Zookeeper.Username,
config.Config.Zookeeper.Password), zookeeper.WithTimeout(10), zookeeper.WithLogger(log.NewZkLogger()))
discov, err := discovery_register.NewDiscoveryRegister(config.Config.Envs.Discovery)
/*
discov, err := zookeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
zookeeper.WithFreq(time.Hour), zookeeper.WithRoundRobin(), zookeeper.WithUserNameAndPassword(config.Config.Zookeeper.Username,
config.Config.Zookeeper.Password), zookeeper.WithTimeout(10), zookeeper.WithLogger(log.NewZkLogger()))*/
if err != nil {
return nil, err
}

37
manifest/build-docker.sh Executable file
View File

@ -0,0 +1,37 @@
#!/bin/bash
IMAGEHUB="registry.cn-shenzhen.aliyuncs.com/huanglin_hub"
PROJECT=$1
ALLPRO="all"
servers=(openim-api openim-crontask openim-msggateway openim-msgtransfer openim-push openim-rpc-auth openim-rpc-conversation openim-rpc-friend openim-rpc-group openim-rpc-msg openim-rpc-third openim-rpc-user)
if [ "$1" != "" ]
then
if [[ "${servers[@]}" =~ "${1}" ]]
then
echo "building ${PROJECT}"
DOCKER_PUSHIMG=${IMAGEHUB}/${PROJECT}:dev
docker rmi ${DOCKER_PUSHIMG}
docker build -f manifest/dockerfiles/${PROJECT}/Dockerfile -t ${DOCKER_PUSHIMG} .
docker push ${DOCKER_PUSHIMG}
elif [[ ! "${servers[@]}" =~ "${1}" ]]
then
if [ ${PROJECT} == ${ALLPRO} ]
then
echo "building allproject"
for element in ${servers[@]}
do
SUB_IMG=${element}
SUB_PUSHIMG=${IMAGEHUB}/${element}:dev
docker rmi ${SUB_PUSHIMG}
docker build -f manifest/dockerfiles/${SUB_IMG}/Dockerfile -t ${SUB_PUSHIMG} .
docker push ${SUB_PUSHIMG}
done
else
echo "输入的项目名称不正确"
fi
fi
else
echo "请传入一个参数"
fi

View File

@ -0,0 +1,27 @@
# build container
FROM golang:1.20-alpine3.18 AS builder
ENV GOPROXY https://goproxy.cn,direct
ENV GOSUMDB=sum.golang.google.cn
ENV GO111MODULE=on
WORKDIR /app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add git pkgconfig build-base
ADD go.mod .
ADD go.sum .
RUN go mod download
ADD . .
RUN go build -o cmd/openim-api/openim-api cmd/openim-api/main.go
# archive container
FROM alpine:3.18
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add ca-certificates libdrm
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata
WORKDIR /app/bin
COPY --from=builder /app/cmd/openim-api/openim-api /app/bin/
ENTRYPOINT ["/app/bin/openim-api"]

View File

@ -0,0 +1,27 @@
# build container
FROM golang:1.20-alpine3.18 AS builder
ENV GOPROXY https://goproxy.cn,direct
ENV GOSUMDB=sum.golang.google.cn
ENV GO111MODULE=on
WORKDIR /app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add git pkgconfig build-base
ADD go.mod .
ADD go.sum .
RUN go mod download
ADD . .
RUN go build -o cmd/openim-crontask/openim-crontask cmd/openim-crontask/main.go
# archive container
FROM alpine:3.18
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add ca-certificates libdrm
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata
WORKDIR /app/bin
COPY --from=builder /app/cmd/openim-crontask/openim-crontask /app/bin/
ENTRYPOINT ["/app/bin/openim-crontask"]

View File

@ -0,0 +1,27 @@
# build container
FROM golang:1.20-alpine3.18 AS builder
ENV GOPROXY https://goproxy.cn,direct
ENV GOSUMDB=sum.golang.google.cn
ENV GO111MODULE=on
WORKDIR /app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add git pkgconfig build-base
ADD go.mod .
ADD go.sum .
RUN go mod download
ADD . .
RUN go build -o cmd/openim-msggateway/openim-msggateway cmd/openim-msggateway/main.go
# archive container
FROM alpine:3.18
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add ca-certificates libdrm
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata
WORKDIR /app/bin
COPY --from=builder /app/cmd/openim-msggateway/openim-msggateway /app/bin/
ENTRYPOINT ["/app/bin/openim-msggateway"]

View File

@ -0,0 +1,27 @@
# build container
FROM golang:1.20-alpine3.18 AS builder
ENV GOPROXY https://goproxy.cn,direct
ENV GOSUMDB=sum.golang.google.cn
ENV GO111MODULE=on
WORKDIR /app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add git pkgconfig build-base
ADD go.mod .
ADD go.sum .
RUN go mod download
ADD . .
RUN go build -o cmd/openim-msgtransfer/openim-msgtransfer cmd/openim-msgtransfer/main.go
# archive container
FROM alpine:3.18
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add ca-certificates libdrm
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata
WORKDIR /app/bin
COPY --from=builder /app/cmd/openim-msgtransfer/openim-msgtransfer /app/bin/
ENTRYPOINT ["/app/bin/openim-msgtransfer"]

View File

@ -0,0 +1,27 @@
# build container
FROM golang:1.20-alpine3.18 AS builder
ENV GOPROXY https://goproxy.cn,direct
ENV GOSUMDB=sum.golang.google.cn
ENV GO111MODULE=on
WORKDIR /app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add git pkgconfig build-base
ADD go.mod .
ADD go.sum .
RUN go mod download
ADD . .
RUN go build -o cmd/openim-push/openim-push cmd/openim-push/main.go
# archive container
FROM alpine:3.18
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add ca-certificates libdrm
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata
WORKDIR /app/bin
COPY --from=builder /app/cmd/openim-push/openim-push /app/bin/
ENTRYPOINT ["/app/bin/openim-push"]

View File

@ -0,0 +1,27 @@
# build container
FROM golang:1.20-alpine3.18 AS builder
ENV GOPROXY https://goproxy.cn,direct
ENV GOSUMDB=sum.golang.google.cn
ENV GO111MODULE=on
WORKDIR /app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add git pkgconfig build-base
ADD go.mod .
ADD go.sum .
RUN go mod download
ADD . .
RUN go build -o cmd/openim-rpc/openim-rpc-auth/openim-rpc-auth cmd/openim-rpc/openim-rpc-auth/main.go
# archive container
FROM alpine:3.18
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add ca-certificates libdrm
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata
WORKDIR /app/bin
COPY --from=builder /app/cmd/openim-rpc/openim-rpc-auth/openim-rpc-auth /app/bin/
ENTRYPOINT ["/app/bin/openim-rpc-auth"]

View File

@ -0,0 +1,27 @@
# build container
FROM golang:1.20-alpine3.18 AS builder
ENV GOPROXY https://goproxy.cn,direct
ENV GOSUMDB=sum.golang.google.cn
ENV GO111MODULE=on
WORKDIR /app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add git pkgconfig build-base
ADD go.mod .
ADD go.sum .
RUN go mod download
ADD . .
RUN go build -o cmd/openim-rpc/openim-rpc-conversation/openim-rpc-conversation cmd/openim-rpc/openim-rpc-conversation/main.go
# archive container
FROM alpine:3.18
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add ca-certificates libdrm
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata
WORKDIR /app/bin
COPY --from=builder /app/cmd/openim-rpc/openim-rpc-conversation/openim-rpc-conversation /app/bin/
ENTRYPOINT ["/app/bin/openim-rpc-conversation"]

View File

@ -0,0 +1,27 @@
# build container
FROM golang:1.20-alpine3.18 AS builder
ENV GOPROXY https://goproxy.cn,direct
ENV GOSUMDB=sum.golang.google.cn
ENV GO111MODULE=on
WORKDIR /app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add git pkgconfig build-base
ADD go.mod .
ADD go.sum .
RUN go mod download
ADD . .
RUN go build -o cmd/openim-rpc/openim-rpc-friend/openim-rpc-friend cmd/openim-rpc/openim-rpc-friend/main.go
# archive container
FROM alpine:3.18
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add ca-certificates libdrm
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata
WORKDIR /app/bin
COPY --from=builder /app/cmd/openim-rpc/openim-rpc-friend/openim-rpc-friend /app/bin/
ENTRYPOINT ["/app/bin/openim-rpc-friend"]

View File

@ -0,0 +1,27 @@
# build container
FROM golang:1.20-alpine3.18 AS builder
ENV GOPROXY https://goproxy.cn,direct
ENV GOSUMDB=sum.golang.google.cn
ENV GO111MODULE=on
WORKDIR /app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add git pkgconfig build-base
ADD go.mod .
ADD go.sum .
RUN go mod download
ADD . .
RUN go build -o cmd/openim-rpc/openim-rpc-group/openim-rpc-group cmd/openim-rpc/openim-rpc-group/main.go
# archive container
FROM alpine:3.18
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add ca-certificates libdrm
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata
WORKDIR /app/bin
COPY --from=builder /app/cmd/openim-rpc/openim-rpc-group/openim-rpc-group /app/bin/
ENTRYPOINT ["/app/bin/openim-rpc-group"]

View File

@ -0,0 +1,27 @@
# build container
FROM golang:1.20-alpine3.18 AS builder
ENV GOPROXY https://goproxy.cn,direct
ENV GOSUMDB=sum.golang.google.cn
ENV GO111MODULE=on
WORKDIR /app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add git pkgconfig build-base
ADD go.mod .
ADD go.sum .
RUN go mod download
ADD . .
RUN go build -o cmd/openim-rpc/openim-rpc-msg/openim-rpc-msg cmd/openim-rpc/openim-rpc-msg/main.go
# archive container
FROM alpine:3.18
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add ca-certificates libdrm
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata
WORKDIR /app/bin
COPY --from=builder /app/cmd/openim-rpc/openim-rpc-msg/openim-rpc-msg /app/bin/
ENTRYPOINT ["/app/bin/openim-rpc-msg"]

View File

@ -0,0 +1,27 @@
# build container
FROM golang:1.20-alpine3.18 AS builder
ENV GOPROXY https://goproxy.cn,direct
ENV GOSUMDB=sum.golang.google.cn
ENV GO111MODULE=on
WORKDIR /app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add git pkgconfig build-base
ADD go.mod .
ADD go.sum .
RUN go mod download
ADD . .
RUN go build -o cmd/openim-rpc/openim-rpc-third/openim-rpc-third cmd/openim-rpc/openim-rpc-third/main.go
# archive container
FROM alpine:3.18
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add ca-certificates libdrm
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata
WORKDIR /app/bin
COPY --from=builder /app/cmd/openim-rpc/openim-rpc-third/openim-rpc-third /app/bin/
ENTRYPOINT ["/app/bin/openim-rpc-third"]

View File

@ -0,0 +1,27 @@
# build container
FROM golang:1.20-alpine3.18 AS builder
ENV GOPROXY https://goproxy.cn,direct
ENV GOSUMDB=sum.golang.google.cn
ENV GO111MODULE=on
WORKDIR /app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add git pkgconfig build-base
ADD go.mod .
ADD go.sum .
RUN go mod download
ADD . .
RUN go build -o cmd/openim-rpc/openim-rpc-user/openim-rpc-user cmd/openim-rpc/openim-rpc-user/main.go
# archive container
FROM alpine:3.18
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk --no-cache add ca-certificates libdrm
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata
WORKDIR /app/bin
COPY --from=builder /app/cmd/openim-rpc/openim-rpc-user/openim-rpc-user /app/bin/
ENTRYPOINT ["/app/bin/openim-rpc-user"]

View File

@ -14,14 +14,21 @@
package cmd
import "github.com/spf13/cobra"
import (
"fmt"
"github.com/OpenIMSDK/protocol/constant"
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/spf13/cobra"
)
type ApiCmd struct {
*RootCmd
}
func NewApiCmd() *ApiCmd {
return &ApiCmd{NewRootCmd("api")}
ret := &ApiCmd{NewRootCmd("api")}
ret.SetRootCmdPt(ret)
return ret
}
func (a *ApiCmd) AddApi(f func(port int) error) {
@ -29,3 +36,11 @@ func (a *ApiCmd) AddApi(f func(port int) error) {
return f(a.getPortFlag(cmd))
}
}
func (a *ApiCmd) GetPortFromConfig(portType string) int {
fmt.Println("GetPortFromConfig:", portType)
if portType == constant.FlagPort {
return config2.Config.Api.OpenImApiPort[0]
} else {
return 0
}
}

View File

@ -0,0 +1,12 @@
package cmd
const (
RpcPushServer = "push"
RpcAuthServer = "auth"
RpcConversationServer = "conversation"
RpcFriendServer = "friend"
RpcGroupServer = "group"
RpcMsgServer = "msg"
RpcThirdServer = "third"
RpcUserServer = "user"
)

View File

@ -21,7 +21,9 @@ type CronTaskCmd struct {
}
func NewCronTaskCmd() *CronTaskCmd {
return &CronTaskCmd{NewRootCmd("cronTask", WithCronTaskLogName())}
ret := &CronTaskCmd{NewRootCmd("cronTask", WithCronTaskLogName())}
ret.SetRootCmdPt(ret)
return ret
}
func (c *CronTaskCmd) addRunE(f func() error) {

View File

@ -16,6 +16,8 @@ package cmd
import (
"github.com/openimsdk/open-im-server/v3/internal/msggateway"
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
//"github.com/openimsdk/open-im-server/internal/msggateway".
"github.com/spf13/cobra"
@ -26,8 +28,10 @@ type MsgGatewayCmd struct {
*RootCmd
}
func NewMsgGatewayCmd() MsgGatewayCmd {
return MsgGatewayCmd{NewRootCmd("msgGateway")}
func NewMsgGatewayCmd() *MsgGatewayCmd {
ret := &MsgGatewayCmd{NewRootCmd("msgGateway")}
ret.SetRootCmdPt(ret)
return ret
}
func (m *MsgGatewayCmd) AddWsPortFlag() {
@ -36,6 +40,9 @@ func (m *MsgGatewayCmd) AddWsPortFlag() {
func (m *MsgGatewayCmd) getWsPortFlag(cmd *cobra.Command) int {
port, _ := cmd.Flags().GetInt(constant.FlagWsPort)
if port == 0 {
port = m.PortFromConfig(constant.FlagWsPort)
}
return port
}
@ -49,3 +56,14 @@ func (m *MsgGatewayCmd) Exec() error {
m.addRunE()
return m.Execute()
}
func (m *MsgGatewayCmd) GetPortFromConfig(portType string) int {
if portType == constant.FlagWsPort {
return config2.Config.LongConnSvr.OpenImWsPort[0]
} else if portType == constant.FlagPort {
return config2.Config.LongConnSvr.OpenImMessageGatewayPort[0]
} else if portType == constant.FlagPrometheusPort {
return 0
} else {
return 0
}
}

View File

@ -24,8 +24,10 @@ type MsgTransferCmd struct {
*RootCmd
}
func NewMsgTransferCmd() MsgTransferCmd {
return MsgTransferCmd{NewRootCmd("msgTransfer")}
func NewMsgTransferCmd() *MsgTransferCmd {
ret := &MsgTransferCmd{NewRootCmd("msgTransfer")}
ret.SetRootCmdPt(ret)
return ret
}
func (m *MsgTransferCmd) addRunE() {

View File

@ -26,11 +26,15 @@ import (
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
)
type RootCmdPt interface {
GetPortFromConfig(portType string) int
}
type RootCmd struct {
Command cobra.Command
Name string
port int
prometheusPort int
cmdItf RootCmdPt
}
type CmdOpts struct {
@ -76,7 +80,9 @@ func NewRootCmd(name string, opts ...func(*CmdOpts)) (rootCmd *RootCmd) {
rootCmd.addConfFlag()
return rootCmd
}
func (r *RootCmd) SetRootCmdPt(cmdItf RootCmdPt) {
r.cmdItf = cmdItf
}
func (r *RootCmd) addConfFlag() {
r.Command.Flags().StringP(constant.FlagConf, "c", "", "Path to config file folder")
}
@ -87,6 +93,9 @@ func (r *RootCmd) AddPortFlag() {
func (r *RootCmd) getPortFlag(cmd *cobra.Command) int {
port, _ := cmd.Flags().GetInt(constant.FlagPort)
if port == 0 {
port = r.PortFromConfig(constant.FlagPort)
}
return port
}
@ -100,6 +109,9 @@ func (r *RootCmd) AddPrometheusPortFlag() {
func (r *RootCmd) getPrometheusPortFlag(cmd *cobra.Command) int {
port, _ := cmd.Flags().GetInt(constant.FlagPrometheusPort)
if port == 0 {
port = r.PortFromConfig(constant.FlagPrometheusPort)
}
return port
}
@ -120,3 +132,12 @@ func (r *RootCmd) Execute() error {
func (r *RootCmd) AddCommand(cmds ...*cobra.Command) {
r.Command.AddCommand(cmds...)
}
func (r *RootCmd) GetPortFromConfig(portType string) int {
fmt.Println("RootCmd.GetPortFromConfig:", portType)
return 0
}
func (r *RootCmd) PortFromConfig(portType string) int {
fmt.Println("PortFromConfig:", portType)
return r.cmdItf.GetPortFromConfig(portType)
}

View File

@ -16,7 +16,8 @@ package cmd
import (
"errors"
"github.com/OpenIMSDK/protocol/constant"
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/spf13/cobra"
"google.golang.org/grpc"
@ -30,8 +31,9 @@ type RpcCmd struct {
}
func NewRpcCmd(name string) *RpcCmd {
authCmd := &RpcCmd{NewRootCmd(name)}
return authCmd
ret := &RpcCmd{NewRootCmd(name)}
ret.SetRootCmdPt(ret)
return ret
}
func (a *RpcCmd) Exec() error {
@ -51,3 +53,40 @@ func (a *RpcCmd) StartSvr(
}
return startrpc.Start(a.GetPortFlag(), name, a.GetPrometheusPortFlag(), rpcFn)
}
func (a *RpcCmd) GetPortFromConfig(portType string) int {
switch a.Name {
case RpcPushServer:
if portType == constant.FlagPort {
return config2.Config.RpcPort.OpenImPushPort[0]
}
case RpcAuthServer:
if portType == constant.FlagPort {
return config2.Config.RpcPort.OpenImAuthPort[0]
}
case RpcConversationServer:
if portType == constant.FlagPort {
return config2.Config.RpcPort.OpenImConversationPort[0]
}
case RpcFriendServer:
if portType == constant.FlagPort {
return config2.Config.RpcPort.OpenImFriendPort[0]
}
case RpcGroupServer:
if portType == constant.FlagPort {
return config2.Config.RpcPort.OpenImGroupPort[0]
}
case RpcMsgServer:
if portType == constant.FlagPort {
return config2.Config.RpcPort.OpenImMessagePort[0]
}
case RpcThirdServer:
if portType == constant.FlagPort {
return config2.Config.RpcPort.OpenImThirdPort[0]
}
case RpcUserServer:
if portType == constant.FlagPort {
return config2.Config.RpcPort.OpenImUserPort[0]
}
}
return 0
}

View File

@ -46,6 +46,9 @@ type POfflinePush struct {
}
type configStruct struct {
Envs struct {
Discovery string `yaml:"discovery"`
}
Zookeeper struct {
Schema string `yaml:"schema"`
ZkAddr []string `yaml:"address"`
@ -185,10 +188,11 @@ type configStruct struct {
} `yaml:"log"`
LongConnSvr struct {
OpenImWsPort []int `yaml:"openImWsPort"`
WebsocketMaxConnNum int `yaml:"websocketMaxConnNum"`
WebsocketMaxMsgLen int `yaml:"websocketMaxMsgLen"`
WebsocketTimeout int `yaml:"websocketTimeout"`
OpenImMessageGatewayPort []int `yaml:"openImMessageGatewayPort"`
OpenImWsPort []int `yaml:"openImWsPort"`
WebsocketMaxConnNum int `yaml:"websocketMaxConnNum"`
WebsocketMaxMsgLen int `yaml:"websocketMaxMsgLen"`
WebsocketTimeout int `yaml:"websocketTimeout"`
} `yaml:"longConnSvr"`
Push struct {

View File

@ -0,0 +1,88 @@
package discovery_register
import (
"context"
"errors"
"fmt"
"github.com/OpenIMSDK/tools/discoveryregistry"
openkeeper "github.com/OpenIMSDK/tools/discoveryregistry/zookeeper"
"github.com/OpenIMSDK/tools/log"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"google.golang.org/grpc"
"time"
)
func NewDiscoveryRegister(envType string) (discoveryregistry.SvcDiscoveryRegistry, error) {
var client discoveryregistry.SvcDiscoveryRegistry
var err error
switch envType {
case "zookeeper":
client, err = openkeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
openkeeper.WithFreq(time.Hour), openkeeper.WithUserNameAndPassword(
config.Config.Zookeeper.Username,
config.Config.Zookeeper.Password,
), openkeeper.WithRoundRobin(), openkeeper.WithTimeout(10), openkeeper.WithLogger(log.NewZkLogger()))
case "k8s":
client, err = NewK8sDiscoveryRegister()
default:
client = nil
err = errors.New("envType not correct")
}
return client, err
}
type K8sDR struct {
options []grpc.DialOption
rpcRegisterAddr string
}
func NewK8sDiscoveryRegister() (discoveryregistry.SvcDiscoveryRegistry, error) {
return &K8sDR{}, nil
}
func (cli *K8sDR) Register(serviceName, host string, port int, opts ...grpc.DialOption) error {
cli.rpcRegisterAddr = serviceName
return nil
}
func (cli *K8sDR) UnRegister() error {
return nil
}
func (cli *K8sDR) CreateRpcRootNodes(serviceNames []string) error {
return nil
}
func (cli *K8sDR) RegisterConf2Registry(key string, conf []byte) error {
return nil
}
func (cli *K8sDR) GetConfFromRegistry(key string) ([]byte, error) {
return nil, nil
}
func (cli *K8sDR) GetConns(ctx context.Context, serviceName string, opts ...grpc.DialOption) ([]*grpc.ClientConn, error) {
conn, err := grpc.DialContext(ctx, serviceName, append(cli.options, opts...)...)
return []*grpc.ClientConn{conn}, err
}
func (cli *K8sDR) GetConn(ctx context.Context, serviceName string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
return grpc.DialContext(ctx, serviceName, append(cli.options, opts...)...)
}
func (cli *K8sDR) GetSelfConnTarget() string {
return cli.rpcRegisterAddr
}
func (cli *K8sDR) AddOption(opts ...grpc.DialOption) {
cli.options = append(cli.options, opts...)
}
func (cli *K8sDR) CloseConn(conn *grpc.ClientConn) {
conn.Close()
}
// do not use this method for call rpc
func (cli *K8sDR) GetClientLocalConns() map[string][]*grpc.ClientConn {
fmt.Println("should not call this function!!!!!!!!!!!!!!!!!!!!!!!!!")
return nil
}

View File

@ -16,19 +16,16 @@ package startrpc
import (
"fmt"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
"github.com/openimsdk/open-im-server/v3/pkg/common/discovery_register"
"net"
"strconv"
"time"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"github.com/OpenIMSDK/tools/discoveryregistry"
"github.com/OpenIMSDK/tools/discoveryregistry/zookeeper"
"github.com/OpenIMSDK/tools/log"
"github.com/OpenIMSDK/tools/mw"
"github.com/OpenIMSDK/tools/network"
"github.com/OpenIMSDK/tools/prome"
@ -60,15 +57,17 @@ func Start(
return err
}
defer listener.Close()
zkClient, err := zookeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
zookeeper.WithFreq(time.Hour), zookeeper.WithUserNameAndPassword(
config.Config.Zookeeper.Username,
config.Config.Zookeeper.Password,
), zookeeper.WithRoundRobin(), zookeeper.WithTimeout(10), zookeeper.WithLogger(log.NewZkLogger()))
zkClient, err := discovery_register.NewDiscoveryRegister(config.Config.Envs.Discovery)
/*
zkClient, err := zookeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema,
zookeeper.WithFreq(time.Hour), zookeeper.WithUserNameAndPassword(
config.Config.Zookeeper.Username,
config.Config.Zookeeper.Password,
), zookeeper.WithRoundRobin(), zookeeper.WithTimeout(10), zookeeper.WithLogger(log.NewZkLogger()))*/
if err != nil {
return utils.Wrap1(err)
}
defer zkClient.CloseZK()
//defer zkClient.CloseZK()
zkClient.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials()))
registerIP, err := network.GetRpcRegisterIP(config.Config.Rpc.RegisterIP)
if err != nil {

View File

@ -150,6 +150,8 @@ def "OPENIM_CHAT_NAME" "chat" # openim-chat chat用户名
# TODO 注意: 一般的配置都可以使用 def 函数来定义,如果是包含特殊字符,比如说:
# TODO readonly MSG_DESTRUCT_TIME=${MSG_DESTRUCT_TIME:-'0 2 * * *'}
# TODO 使用 readonly 来定义合适,负责无法正常解析, 并且 yaml 模板需要加 "" 来包裹
###################### Env 配置信息 ######################
def "ENVS_DISCOVERY" "zookeeper"
###################### Zookeeper 配置信息 ######################
def "ZOOKEEPER_SCHEMA" "openim" # Zookeeper的模式