Skip to content

Commit

Permalink
feat: Add the help chart script to support k8s deployment (#1145)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
xuexihuang and lin.huang authored Oct 16, 2023
1 parent 81cc1f3 commit abf8e37
Show file tree
Hide file tree
Showing 38 changed files with 628 additions and 61 deletions.
19 changes: 10 additions & 9 deletions cmd/openim-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/openim-push/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/openim-rpc/openim-rpc-auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/openim-rpc/openim-rpc-conversation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/openim-rpc/openim-rpc-friend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/openim-rpc/openim-rpc-group/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/openim-rpc/openim-rpc-msg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/openim-rpc/openim-rpc-third/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/openim-rpc/openim-rpc-user/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
# Zookeeper address
# Zookeeper username
# Zookeeper password
envs:
discovery: zookeeper

zookeeper:
schema: openim
address: [ 172.28.0.1:12181 ]
Expand Down Expand Up @@ -213,6 +216,7 @@ log:
# Websocket connection handshake timeout
longConnSvr:
openImWsPort: [ 10001 ]
openImMessageGatewayPort: [ 10140 ]
websocketMaxConnNum: 100000
websocketMaxMsgLen: 4096
websocketTimeout: 10
Expand Down
3 changes: 3 additions & 0 deletions deployments/templates/openim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
# --| target: config/config.yaml
# -----------------------------------------------------------------

envs:
discovery: ${ENVS_DISCOVERY}

###################### Zookeeper ######################
# Zookeeper configuration
# It's not recommended to modify the schema
Expand Down
3 changes: 0 additions & 3 deletions internal/msggateway/n_ws_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 7 additions & 8 deletions internal/msgtransfer/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions internal/tools/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
37 changes: 37 additions & 0 deletions manifest/build-docker.sh
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions manifest/dockerfiles/openim-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
27 changes: 27 additions & 0 deletions manifest/dockerfiles/openim-crontask/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
27 changes: 27 additions & 0 deletions manifest/dockerfiles/openim-msggateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
27 changes: 27 additions & 0 deletions manifest/dockerfiles/openim-msgtransfer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
27 changes: 27 additions & 0 deletions manifest/dockerfiles/openim-push/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
Loading

0 comments on commit abf8e37

Please sign in to comment.