From 57374a4df4a0d5f68cb861889774f50af2190844 Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw-openim)" <3293172751nss@gmail.com> Date: Thu, 27 Jul 2023 14:51:58 +0800 Subject: [PATCH 01/13] docs: add readme docs Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- config/config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 6bf3cf06e..b92dc420c 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -126,10 +126,10 @@ api: # Configuration for Aliyun OSS object: enable: "minio" - apiURL: "http://127.0.0.1:10002/object/" + apiURL: http://113.99.98.99:10002/object/ minio: bucket: "openim" - endpoint: http://127.0.0.1:10005 + endpoint: http://113.99.98.99:10005 accessKeyID: root secretAccessKey: openIM123 sessionToken: "" From de641f574c5f95ccd60d254680bd17c682470b69 Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw-openim)" <3293172751nss@gmail.com> Date: Thu, 27 Jul 2023 15:36:11 +0800 Subject: [PATCH 02/13] feat: add script yaml Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- .github/workflows/deploy.yml | 78 ++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ef50743a1..e5e8cbafd 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -15,45 +15,43 @@ name: deploy for dev on: - push: - branches: - - 'devops' # Only for the dev branch - paths: - - '.github/workflows/*' - # - '__test__/**' # dev No immediate testing is required - - 'src/**' - - 'Dockerfile' - - 'docker-compose.yml' - - 'bin/*' + push: + branches: + - 'devops' # Only for the dev branch + paths: + - '.github/workflows/*' + # - '__test__/**' # dev No immediate testing is required + - 'src/**' + - 'Dockerfile' + - 'docker-compose.yml' + - 'bin/*' jobs: - deploy-dev: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: set ssh key # Temporarily set up ssh key - run: | - mkdir -p ~/.ssh/ - # secrets.WFP_ID_RSA set in GitHub - echo "${{secrets.WFP_ID_RSA}}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - ssh-keyscan "182.92.xxx.xxx" >> ~/.ssh/known_hosts - - name: deploy # Deployment - run: | - ssh work@182.92.xxx.xxx " - # 【Attention】Log in with the 'work' account, manually create /home/work/imooc-lego directory - # Then git clone https://username:password@github.com/imooc-lego/biz-editor-server.git -b dev (private repository, use GitHub username and password) - # Remember to delete origin to avoid exposing GitHub password - - cd /home/work/imooc-lego/biz-editor-server; - git remote add origin https://openimbot:${{secrets.WFP_PASSWORD}}@github.com/OpenIMSDK/open-im-server.git; - git checkout dev; - git pull origin dev; # Download the latest code again - git remote remove origin; # Remove origin to avoid exposing GitHub password - # Start docker - docker-compose build editor-server; # Same as the service name in docker-compose.yml - docker-compose up -d; - " - - name: delete ssh key # Delete ssh key - run: rm -rf ~/.ssh/id_rsa + deploy-dev: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: set ssh key # Temporarily set up ssh key + run: | + mkdir -p ~/.ssh/ + # secrets.WFP_ID_RSA set in GitHub + echo "${{secrets.WFP_ID_RSA}}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan "182.92.xxx.xxx" >> ~/.ssh/known_hosts + - name: deploy # Deployment + run: | + ssh work@182.92.xxx.xxx " + # 【Attention】Log in with the 'work' account, manually create /home/work/imooc-lego directory + # Then git clone https://username:password@github.com/imooc-lego/biz-editor-server.git -b dev (private repository, use GitHub username and password) + # Remember to delete origin to avoid exposing GitHub password + cd /home/work/imooc-lego/biz-editor-server; + git remote add origin https://openimbot:${{secrets.WFP_PASSWORD}}@github.com/OpenIMSDK/open-im-server.git; + git checkout dev; + git pull origin dev; # Download the latest code again + git remote remove origin; # Remove origin to avoid exposing GitHub password + # Start docker + docker-compose build editor-server; # Same as the service name in docker-compose.yml + docker-compose up -d; + " + - name: delete ssh key # Delete ssh key + run: rm -rf ~/.ssh/id_rsa \ No newline at end of file From 692ff29a0c5f1bae488adff240090fd5fb4a3250 Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw-openim)" <3293172751nss@gmail.com> Date: Thu, 27 Jul 2023 15:51:57 +0800 Subject: [PATCH 03/13] feat: add script yaml Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- .github/workflows/build-docker-image.yml | 38 +++++++++++++++++++----- .github/workflows/deploy.yml | 2 +- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index ff58d8d8f..ef2659724 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -29,30 +29,31 @@ jobs: - name: Check out the repo uses: actions/checkout@v3 +# docker.io/openim/openim-server:latest - name: Log in to Docker Hub - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + uses: docker/metadata-action@v4.6.0 with: images: openim/openim-server tags: latest - name: Build and push Docker image - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + uses: docker/build-push-action@v4 with: context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - +# registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-server:latest - name: Log in to AliYun Docker Hub - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v2 with: registry: registry.cn-hangzhou.aliyuncs.com username: ${{ secrets.ALIREGISTRY_USERNAME }} @@ -60,19 +61,42 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta2 - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + uses: docker/metadata-action@v4.6.0 with: images: registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-server tags: latest - name: Build and push Docker image - uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + uses: docker/build-push-action@v4 with: context: . push: true tags: ${{ steps.meta2.outputs.tags }} labels: ${{ steps.meta2.outputs.labels }} +# ghcr.io/openim/openim-server:latest + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta3 + uses: docker/metadata-action@v4.6.0 + with: + images: openim/openim-server + tags: latest + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: ${{ steps.meta3.outputs.tags }} + labels: ${{ steps.meta3.outputs.labels }} + # name: OpenIM Build Docker Images # on: # push: diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e5e8cbafd..cee255e54 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -name: deploy for dev +name: OpenIM Deploy for dev on: push: From c509f7d4d29b958a5b18474a17ae4bb135f5845c Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw-openim)" <3293172751nss@gmail.com> Date: Thu, 27 Jul 2023 16:16:13 +0800 Subject: [PATCH 04/13] feat: add test Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- .github/workflows/deploy.yml | 6 ++ .goreleaser.yaml | 120 +++++++++++++++++------------------ 2 files changed, 66 insertions(+), 60 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index cee255e54..2d7798916 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -26,6 +26,12 @@ on: - 'docker-compose.yml' - 'bin/*' +env: + SERVER_PRIVATE_KEY: ${{ secrets.SERVER_PRIVATE_KEY }} # server private key + SERVER_HOST: ${{ secrets.SERVER_HOST }} # server ip address + USER_NAME: ${{ secrets.USER_NAME }} # server username + cache-name: note + jobs: deploy-dev: runs-on: ubuntu-latest diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 996a53745..e9eb44c94 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -335,66 +335,66 @@ changelog: - title: Other work order: 9999 -dockers: - - image_templates: - - "openimsdk/open-im-server:{{ .Tag }}-amd64" - - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64" - dockerfile: Dockerfile - use: buildx - build_flag_templates: - - "--pull" - - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/OpenIMSDK/Open-IM-Server/main/README.md" - - "--label=io.artifacthub.package.logo-url=hhttps://github.com/OpenIMSDK/Open-IM-Server/blob/main/assets/logo/openim-logo-green.png" - - '--label=io.artifacthub.package.maintainers=[{"name":"Xinwei Xiong","email":"3293172751nss@gmail.com"}]' - - "--label=io.artifacthub.package.license=Apace-2.0" - - "--label=org.opencontainers.image.description=OpenIM Open source top instant messaging system" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.name={{.ProjectName}}" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - - "--label=org.opencontainers.image.source={{.GitURL}}" - - "--platform=linux/amd64" - extra_files: - - scripts/entrypoint.sh - - image_templates: - - "goreleaser/goreleaser:{{ .Tag }}-arm64" - - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64" - dockerfile: Dockerfile - use: buildx - build_flag_templates: - - "--pull" - - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/OpenIMSDK/Open-IM-Server/main/README.md" - - "--label=io.artifacthub.package.logo-url=hhttps://github.com/OpenIMSDK/Open-IM-Server/blob/main/assets/logo/openim-logo-green.png" - - '--label=io.artifacthub.package.maintainers=[{"name":"Xinwei Xiong","email":"3293172751nss@gmail.com"}]' - - "--label=io.artifacthub.package.license=Apace-2.0" - - "--label=org.opencontainers.image.description=OpenIM Open source top instant messaging system" - - "--label=org.opencontainers.image.created={{.Date}}" - - "--label=org.opencontainers.image.name={{.ProjectName}}" - - "--label=org.opencontainers.image.revision={{.FullCommit}}" - - "--label=org.opencontainers.image.version={{.Version}}" - - "--label=org.opencontainers.image.source={{.GitURL}}" - - "--platform=linux/arm64" - goarch: arm64 - extra_files: - - scripts/entrypoint.sh - -docker_manifests: - - name_template: "goreleaser/goreleaser:{{ .Tag }}" - image_templates: - - "goreleaser/goreleaser:{{ .Tag }}-amd64" - - "goreleaser/goreleaser:{{ .Tag }}-arm64" - - name_template: "ghcr.io/goreleaser/goreleaser:{{ .Tag }}" - image_templates: - - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64" - - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64" - - name_template: "goreleaser/goreleaser:latest" - image_templates: - - "goreleaser/goreleaser:{{ .Tag }}-amd64" - - "goreleaser/goreleaser:{{ .Tag }}-arm64" - - name_template: "ghcr.io/goreleaser/goreleaser:latest" - image_templates: - - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64" - - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64" +# dockers: +# - image_templates: +# - "openimsdk/open-im-server:{{ .Tag }}-amd64" +# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64" +# dockerfile: Dockerfile +# use: buildx +# build_flag_templates: +# - "--pull" +# - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/OpenIMSDK/Open-IM-Server/main/README.md" +# - "--label=io.artifacthub.package.logo-url=hhttps://github.com/OpenIMSDK/Open-IM-Server/blob/main/assets/logo/openim-logo-green.png" +# - '--label=io.artifacthub.package.maintainers=[{"name":"Xinwei Xiong","email":"3293172751nss@gmail.com"}]' +# - "--label=io.artifacthub.package.license=Apace-2.0" +# - "--label=org.opencontainers.image.description=OpenIM Open source top instant messaging system" +# - "--label=org.opencontainers.image.created={{.Date}}" +# - "--label=org.opencontainers.image.name={{.ProjectName}}" +# - "--label=org.opencontainers.image.revision={{.FullCommit}}" +# - "--label=org.opencontainers.image.version={{.Version}}" +# - "--label=org.opencontainers.image.source={{.GitURL}}" +# - "--platform=linux/amd64" +# extra_files: +# - scripts/entrypoint.sh +# - image_templates: +# - "goreleaser/goreleaser:{{ .Tag }}-arm64" +# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64" +# dockerfile: Dockerfile +# use: buildx +# build_flag_templates: +# - "--pull" +# - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/OpenIMSDK/Open-IM-Server/main/README.md" +# - "--label=io.artifacthub.package.logo-url=hhttps://github.com/OpenIMSDK/Open-IM-Server/blob/main/assets/logo/openim-logo-green.png" +# - '--label=io.artifacthub.package.maintainers=[{"name":"Xinwei Xiong","email":"3293172751nss@gmail.com"}]' +# - "--label=io.artifacthub.package.license=Apace-2.0" +# - "--label=org.opencontainers.image.description=OpenIM Open source top instant messaging system" +# - "--label=org.opencontainers.image.created={{.Date}}" +# - "--label=org.opencontainers.image.name={{.ProjectName}}" +# - "--label=org.opencontainers.image.revision={{.FullCommit}}" +# - "--label=org.opencontainers.image.version={{.Version}}" +# - "--label=org.opencontainers.image.source={{.GitURL}}" +# - "--platform=linux/arm64" +# goarch: arm64 +# extra_files: +# - scripts/entrypoint.sh + +# docker_manifests: +# - name_template: "goreleaser/goreleaser:{{ .Tag }}" +# image_templates: +# - "goreleaser/goreleaser:{{ .Tag }}-amd64" +# - "goreleaser/goreleaser:{{ .Tag }}-arm64" +# - name_template: "ghcr.io/goreleaser/goreleaser:{{ .Tag }}" +# image_templates: +# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64" +# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64" +# - name_template: "goreleaser/goreleaser:latest" +# image_templates: +# - "goreleaser/goreleaser:{{ .Tag }}-amd64" +# - "goreleaser/goreleaser:{{ .Tag }}-arm64" +# - name_template: "ghcr.io/goreleaser/goreleaser:latest" +# image_templates: +# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64" +# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64" nfpms: - id: packages From e9f5752e29ca978f811f51cc8941f476141be8f6 Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw-openim)" <3293172751nss@gmail.com> Date: Thu, 27 Jul 2023 16:27:43 +0800 Subject: [PATCH 05/13] feat: add test Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- .github/workflows/deploy.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2d7798916..6695d4092 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -26,12 +26,6 @@ on: - 'docker-compose.yml' - 'bin/*' -env: - SERVER_PRIVATE_KEY: ${{ secrets.SERVER_PRIVATE_KEY }} # server private key - SERVER_HOST: ${{ secrets.SERVER_HOST }} # server ip address - USER_NAME: ${{ secrets.USER_NAME }} # server username - cache-name: note - jobs: deploy-dev: runs-on: ubuntu-latest @@ -44,6 +38,14 @@ jobs: echo "${{secrets.WFP_ID_RSA}}" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa ssh-keyscan "182.92.xxx.xxx" >> ~/.ssh/known_hosts + - name: executing remote ssh commands using password + uses: appleboy/ssh-action@v1.0.0 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + port: ${{ secrets.PORT }} + script: whoami - name: deploy # Deployment run: | ssh work@182.92.xxx.xxx " From 340ce42b17122f228a2d962b2493ee8da8eb25af Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 27 Jul 2023 20:27:05 +0800 Subject: [PATCH 06/13] fix bug: reject group req bug --- internal/rpc/group/group.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 4ce3d4216..65beae37e 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -17,14 +17,15 @@ package group import ( "context" "fmt" - "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" - "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" "math/big" "math/rand" "strconv" "strings" "time" + "github.com/OpenIMSDK/Open-IM-Server/pkg/authverify" + "github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor" + pbConversation "github.com/OpenIMSDK/protocol/conversation" "github.com/OpenIMSDK/protocol/wrapperspb" @@ -718,11 +719,11 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup if err := s.GroupDatabase.HandlerGroupRequest(ctx, req.GroupID, req.FromUserID, req.HandledMsg, req.HandleResult, member); err != nil { return nil, err } - if err := s.conversationRpcClient.GroupChatFirstCreateConversation(ctx, req.GroupID, []string{req.FromUserID}); err != nil { - return nil, err - } switch req.HandleResult { case constant.GroupResponseAgree: + if err := s.conversationRpcClient.GroupChatFirstCreateConversation(ctx, req.GroupID, []string{req.FromUserID}); err != nil { + return nil, err + } s.Notification.GroupApplicationAcceptedNotification(ctx, req) case constant.GroupResponseRefuse: s.Notification.GroupApplicationRejectedNotification(ctx, req) From 5eb97766b64c04cec5e33d9a36a6cea0ee67f293 Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong(cubxxw-openim)" <3293172751nss@gmail.com> Date: Thu, 27 Jul 2023 20:44:36 +0800 Subject: [PATCH 07/13] feat: add go relase Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- .github/workflows/build-docker-image.yml | 22 ++++---- .github/workflows/deploy.yml | 68 ++++++++++++----------- docs/conversions/images.md | 69 ++++++++++++++++++++++++ docs/conversions/version.md | 6 ++- 4 files changed, 124 insertions(+), 41 deletions(-) create mode 100644 docs/conversions/images.md diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index ef2659724..4d1a61583 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -18,6 +18,7 @@ on: push: branches: - main + - release-* tags: - v* workflow_dispatch: @@ -29,6 +30,10 @@ jobs: - name: Check out the repo uses: actions/checkout@v3 + - name: Build OpenIM Server + run: | + sudo make build + # docker.io/openim/openim-server:latest - name: Log in to Docker Hub uses: docker/login-action@v2 @@ -41,13 +46,12 @@ jobs: uses: docker/metadata-action@v4.6.0 with: images: openim/openim-server - tags: latest - name: Build and push Docker image uses: docker/build-push-action@v4 with: context: . - push: true + push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} @@ -64,15 +68,14 @@ jobs: uses: docker/metadata-action@v4.6.0 with: images: registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-server - tags: latest - name: Build and push Docker image uses: docker/build-push-action@v4 with: context: . - push: true - tags: ${{ steps.meta2.outputs.tags }} - labels: ${{ steps.meta2.outputs.labels }} + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} # ghcr.io/openim/openim-server:latest - name: Log in to GitHub Container Registry @@ -87,15 +90,14 @@ jobs: uses: docker/metadata-action@v4.6.0 with: images: openim/openim-server - tags: latest - name: Build and push Docker image uses: docker/build-push-action@v4 with: context: . - push: true - tags: ${{ steps.meta3.outputs.tags }} - labels: ${{ steps.meta3.outputs.labels }} + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} # name: OpenIM Build Docker Images # on: diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6695d4092..ea28440e9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -18,6 +18,7 @@ on: push: branches: - 'devops' # Only for the dev branch + - 'main' paths: - '.github/workflows/*' # - '__test__/**' # dev No immediate testing is required @@ -30,36 +31,43 @@ jobs: deploy-dev: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: set ssh key # Temporarily set up ssh key - run: | - mkdir -p ~/.ssh/ - # secrets.WFP_ID_RSA set in GitHub - echo "${{secrets.WFP_ID_RSA}}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - ssh-keyscan "182.92.xxx.xxx" >> ~/.ssh/known_hosts + - uses: actions/checkout@v3 - name: executing remote ssh commands using password uses: appleboy/ssh-action@v1.0.0 + env: + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USERNAME }} - password: ${{ secrets.PASSWORD }} - port: ${{ secrets.PORT }} - script: whoami - - name: deploy # Deployment - run: | - ssh work@182.92.xxx.xxx " - # 【Attention】Log in with the 'work' account, manually create /home/work/imooc-lego directory - # Then git clone https://username:password@github.com/imooc-lego/biz-editor-server.git -b dev (private repository, use GitHub username and password) - # Remember to delete origin to avoid exposing GitHub password - cd /home/work/imooc-lego/biz-editor-server; - git remote add origin https://openimbot:${{secrets.WFP_PASSWORD}}@github.com/OpenIMSDK/open-im-server.git; - git checkout dev; - git pull origin dev; # Download the latest code again - git remote remove origin; # Remove origin to avoid exposing GitHub password - # Start docker - docker-compose build editor-server; # Same as the service name in docker-compose.yml - docker-compose up -d; - " - - name: delete ssh key # Delete ssh key - run: rm -rf ~/.ssh/id_rsa \ No newline at end of file + host: "${{ secrets.SG_M1_HOST }}, ${{ secrets.SG_N1_HOST }}, ${{ secrets.SG_N2_HOST}}" + username: ${{ secrets.SG_USERNAME }} + password: ${{ secrets.SG_PASSWORD }} + port: ${{ secrets.SG_PORT }} + envs: OWNER,REPO + script_stop: true + script: | + mkdir -p /test/openim + cd /test/openim + pwd;ls -al + echo "OWNER: $OWNER" + echo "REPO: $REPO" + git clone -b develop https://github.com/${OWNER}/${REPO}.git; cd ${REPO} + docker compose up -d + + + # - name: deploy # Deployment + # run: | + # ssh work@182.92.xxx.xxx " + # # 【Attention】Log in with the 'work' account, manually create /home/work/imooc-lego directory + # # Then git clone https://username:password@github.com/imooc-lego/biz-editor-server.git -b dev (private repository, use GitHub username and password) + # # Remember to delete origin to avoid exposing GitHub password + # cd /home/work/imooc-lego/biz-editor-server; + # git remote add origin https://openimbot:${{secrets.WFP_PASSWORD}}@github.com/OpenIMSDK/open-im-server.git; + # git checkout dev; + # git pull origin dev; # Download the latest code again + # git remote remove origin; # Remove origin to avoid exposing GitHub password + # # Start docker + # docker-compose build editor-server; # Same as the service name in docker-compose.yml + # docker-compose up -d; + # " + # - name: delete ssh key # Delete ssh key + # run: rm -rf ~/.ssh/id_rsa \ No newline at end of file diff --git a/docs/conversions/images.md b/docs/conversions/images.md new file mode 100644 index 000000000..750956ec0 --- /dev/null +++ b/docs/conversions/images.md @@ -0,0 +1,69 @@ +# OpenIM Image Management Strategy and Pulling Guide + +OpenIM is an efficient, stable, and scalable instant messaging framework that provides convenient deployment methods through Docker images. OpenIM manages multiple image sources, hosted respectively on GitHub (ghcr), Alibaba Cloud, and Docker Hub. This document is aimed at detailing the image management strategy of OpenIM and providing the steps for pulling these images. + +## Image Management Strategy + +OpenIM's versions correspond to GitHub's tag versions. Each time we release a new version and tag it on GitHub, an automated process is triggered that pushes the new Docker image version to the following three platforms: + +1. **GitHub (ghcr.io):** We use GitHub Container Registry (ghcr.io) to host OpenIM's Docker images. This allows us to better integrate with the GitHub source code repository, providing better version control and continuous integration/deployment (CI/CD) features. You can view all GitHub images [here](https://github.com/orgs/OpenIMSDK/packages). +2. **Alibaba Cloud (registry.cn-hangzhou.aliyuncs.com):** For users in Mainland China, we also host OpenIM's Docker images on Alibaba Cloud to provide faster pull speeds. You can view all Alibaba Cloud images on this [page](https://cr.console.aliyun.com/cn-hangzhou/instances/repositories) of Alibaba Cloud Image Service (note that you need to log in to your Alibaba Cloud account first). +3. **Docker Hub (docker.io):** Docker Hub is the most commonly used Docker image hosting platform, and we also host OpenIM's images there to facilitate developers worldwide. You can view all Docker Hub images on the [OpenIM's Docker Hub page](https://hub.docker.com/r/openim). + +## Methods and Steps for Pulling Images + +When pulling OpenIM's Docker images, you can choose the most suitable source based on your geographic location and network conditions. Here are the steps to pull OpenIM images from each source: + +1. First, make sure Docker is installed on your machine. If not, you can refer to the [Docker official documentation](https://docs.docker.com/get-docker/) for installation. + +2. Open the terminal and run the following commands to pull the images: + + For OpenIM Server: + + - Pull from GitHub: + + ``` + bashCopy code + docker pull ghcr.io/openim/openim-server:latest + ``` + + - Pull from Alibaba Cloud: + + ``` + bashCopy code + docker pull registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-server:latest + ``` + + - Pull from Docker Hub: + + ``` + bashCopy code + docker pull docker.io/openim/openim-server:latest + ``` + + For OpenIM Chat: + + - Pull from GitHub: + + ``` + bashCopy code + docker pull ghcr.io/openim/openim-chat:latest + ``` + + - Pull from Alibaba Cloud: + + ``` + bashCopy code + docker pull registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:latest + ``` + + - Pull from Docker Hub: + + ``` + bashCopy code + docker pull docker.io/openim/openim-chat:latest + ``` + +3. Run the `docker images` command to confirm that the image has been successfully pulled. + +This concludes OpenIM's image management strategy and the steps for pulling images. If you have any questions, please feel free to ask. \ No newline at end of file diff --git a/docs/conversions/version.md b/docs/conversions/version.md index a421dd549..bf1062b77 100644 --- a/docs/conversions/version.md +++ b/docs/conversions/version.md @@ -54,4 +54,8 @@ git merge release-v3.1 git push origin main ``` -Remember, communication with your team is key throughout this process, keeping everyone up-to-date with the changes being made. \ No newline at end of file +Remember, communication with your team is key throughout this process, keeping everyone up-to-date with the changes being made. + + +## Docker images version management + From e24b0e21149ebd316d3ee5ad9baf1ea5d09e4468 Mon Sep 17 00:00:00 2001 From: pluto <83957921+plutoyty@users.noreply.github.com> Date: Fri, 28 Jul 2023 17:54:29 +0800 Subject: [PATCH 08/13] Get user online status (#693) * Resolving code conflicts after project directory changes and Add subscribe and unsubscribe mongodb operations * Organize and update module dependencies * Get user online status * Get user online status * Get user online status --- internal/api/route.go | 1 + internal/api/user.go | 4 ++ internal/rpc/user/user.go | 15 ++++-- pkg/common/db/cache/user.go | 85 ++++++++++++++++++++++++++++++-- pkg/common/db/controller/user.go | 16 ++++++ 5 files changed, 114 insertions(+), 7 deletions(-) diff --git a/internal/api/route.go b/internal/api/route.go index 0f46f0f0c..1926b55f1 100644 --- a/internal/api/route.go +++ b/internal/api/route.go @@ -81,6 +81,7 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive userRouterGroup.POST("/get_users_online_token_detail", ParseToken, u.GetUsersOnlineTokenDetail) userRouterGroup.POST("/subscribe_users_status", ParseToken, u.UnSubscriberStatus) userRouterGroup.POST("/unsubscribe_users_status", ParseToken, u.UnSubscriberStatus) + userRouterGroup.POST("/get_users_status", ParseToken, u.GetUserStatus) } // friend routing group diff --git a/internal/api/user.go b/internal/api/user.go index 108ccac69..3eb136b3d 100644 --- a/internal/api/user.go +++ b/internal/api/user.go @@ -194,3 +194,7 @@ func (u *UserApi) SubscriberStatus(c *gin.Context) { func (u *UserApi) UnSubscriberStatus(c *gin.Context) { a2r.Call(user.UserClient.SubscribeOrCancelUsersStatus, u.Client, c) } + +func (u *UserApi) GetUserStatus(c *gin.Context) { + a2r.Call(user.UserClient.GetUserStatus, u.Client, c) +} diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 576492566..53598db0b 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -261,11 +261,18 @@ func (s *userServer) SubscribeOrCancelUsersStatus(ctx context.Context, req *pbus } func (s *userServer) GetUserStatus(ctx context.Context, req *pbuser.GetUserStatusReq) (resp *pbuser.GetUserStatusResp, err error) { - //TODO implement me - panic("implement me") + //TODO 是否加一个参数校验-判断req.userID的数量,每一个获取加一个限制,一次请求限制500? + onlineStatusList, err := s.UserDatabase.GetUserStatus(ctx, req.UserIDs) + if err != nil { + return nil, err + } + return &pbuser.GetUserStatusResp{StatusList: onlineStatusList}, nil } func (s *userServer) SetUserStatus(ctx context.Context, req *pbuser.SetUserStatusReq) (resp *pbuser.SetUserStatusResp, err error) { - //TODO implement me - panic("implement me") + err = s.UserDatabase.SetUserStatus(ctx, req.StatusList) + if err != nil { + return nil, err + } + return &pbuser.SetUserStatusResp{}, nil } diff --git a/pkg/common/db/cache/user.go b/pkg/common/db/cache/user.go index 455bc9ebe..5c76af22f 100644 --- a/pkg/common/db/cache/user.go +++ b/pkg/common/db/cache/user.go @@ -16,6 +16,9 @@ package cache import ( "context" + "encoding/json" + "github.com/OpenIMSDK/protocol/user" + "strconv" "time" "github.com/dtm-labs/rockscache" @@ -25,9 +28,12 @@ import ( ) const ( - userExpireTime = time.Second * 60 * 60 * 12 - userInfoKey = "USER_INFO:" - userGlobalRecvMsgOptKey = "USER_GLOBAL_RECV_MSG_OPT_KEY:" + userExpireTime = time.Second * 60 * 60 * 12 + userInfoKey = "USER_INFO:" + userGlobalRecvMsgOptKey = "USER_GLOBAL_RECV_MSG_OPT_KEY:" + olineStatusKey = "ONLINE_STATUS:" + userOlineStatusExpireTime = time.Second * 60 * 60 * 24 + statusMod = 500 ) type UserCache interface { @@ -38,10 +44,13 @@ type UserCache interface { DelUsersInfo(userIDs ...string) UserCache GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error) DelUsersGlobalRecvMsgOpt(userIDs ...string) UserCache + GetUserStatus(ctx context.Context, userIDs []string) ([]*user.OnlineStatus, error) + SetUserStatus(ctx context.Context, list []*user.OnlineStatus) error } type UserCacheRedis struct { metaCache + rdb redis.UniversalClient userDB relationTb.UserModelInterface expireTime time.Duration rcClient *rockscache.Client @@ -54,6 +63,7 @@ func NewUserCacheRedis( ) UserCache { rcClient := rockscache.NewClient(rdb, options) return &UserCacheRedis{ + rdb: rdb, metaCache: NewMetaCacheRedis(rcClient), userDB: userDB, expireTime: userExpireTime, @@ -63,6 +73,7 @@ func NewUserCacheRedis( func (u *UserCacheRedis) NewCache() UserCache { return &UserCacheRedis{ + rdb: u.rdb, metaCache: NewMetaCacheRedis(u.rcClient, u.metaCache.GetPreDelKeys()...), userDB: u.userDB, expireTime: u.expireTime, @@ -145,3 +156,71 @@ func (u *UserCacheRedis) DelUsersGlobalRecvMsgOpt(userIDs ...string) UserCache { cache.AddKeys(keys...) return cache } + +func (u *UserCacheRedis) getOnlineStatusKey(userID string) string { + return olineStatusKey + userID +} + +// GetUserStatus get user status +func (u *UserCacheRedis) GetUserStatus(ctx context.Context, userIDs []string) ([]*user.OnlineStatus, error) { + var res []*user.OnlineStatus + for _, userID := range userIDs { + UserIDNum, err := strconv.Atoi(userID) + if err != nil { + return nil, err + } + var modKey = strconv.Itoa(UserIDNum % statusMod) + var onlineStatus user.OnlineStatus + key := olineStatusKey + modKey + result, err := u.rdb.HGet(ctx, key, userID).Result() + if err != nil { + if err == redis.Nil { + // key or field does not exist + res = append(res, &user.OnlineStatus{ + UserID: userID, + Status: 0, + PlatformID: -1, + }) + continue + } else { + return nil, err + } + } + err = json.Unmarshal([]byte(result), &onlineStatus) + if err != nil { + return nil, err + } + onlineStatus.UserID = userID + res = append(res, &onlineStatus) + } + return res, nil +} + +// SetUserStatus Set the user status and save it in redis +func (u *UserCacheRedis) SetUserStatus(ctx context.Context, list []*user.OnlineStatus) error { + for _, status := range list { + var isNewKey int64 + UserIDNum, err := strconv.Atoi(status.UserID) + if err != nil { + return err + } + var modKey = strconv.Itoa(UserIDNum % statusMod) + key := olineStatusKey + modKey + jsonData, err := json.Marshal(status) + if err != nil { + return err + } + isNewKey, err = u.rdb.Exists(ctx, key).Result() + if err != nil { + return err + } + _, err = u.rdb.HSet(ctx, key, status.UserID, string(jsonData)).Result() + if err != nil { + return err + } + if isNewKey > 0 { + u.rdb.Expire(ctx, key, userOlineStatusExpireTime) + } + } + return nil +} diff --git a/pkg/common/db/controller/user.go b/pkg/common/db/controller/user.go index 83942ce22..5b303ebd7 100644 --- a/pkg/common/db/controller/user.go +++ b/pkg/common/db/controller/user.go @@ -18,6 +18,7 @@ import ( "context" unRelationTb "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" "github.com/OpenIMSDK/protocol/constant" + "github.com/OpenIMSDK/protocol/user" "time" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache" @@ -56,6 +57,10 @@ type UserDatabase interface { GetAllSubscribeList(ctx context.Context, userID string) ([]string, error) // GetSubscribedList Get all subscribed lists GetSubscribedList(ctx context.Context, userID string) ([]string, error) + // GetUserStatus Get the online status of the user + GetUserStatus(ctx context.Context, userIDs []string) ([]*user.OnlineStatus, error) + // SetUserStatus Set the user status and store the user status in redis + SetUserStatus(ctx context.Context, list []*user.OnlineStatus) error } type userDatabase struct { @@ -195,3 +200,14 @@ func (u *userDatabase) GetSubscribedList(ctx context.Context, userID string) ([] //TODO 获取所有被订阅 return nil, nil } + +// GetUserStatus get user status +func (u *userDatabase) GetUserStatus(ctx context.Context, userIDs []string) ([]*user.OnlineStatus, error) { + onlineStatusList, err := u.cache.GetUserStatus(ctx, userIDs) + return onlineStatusList, err +} + +// SetUserStatus Set the user status and save it in redis +func (u *userDatabase) SetUserStatus(ctx context.Context, list []*user.OnlineStatus) error { + return u.cache.SetUserStatus(ctx, list) +} From c9c698551bc03c3ba74ae83220bf82c652b6d376 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 28 Jul 2023 20:16:32 +0800 Subject: [PATCH 09/13] fix bug: join group failed --- internal/rpc/group/group.go | 2 +- pkg/common/db/controller/group.go | 5 +++++ pkg/common/db/relation/group_model.go | 4 ++++ pkg/common/db/table/relation/group.go | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 65beae37e..a7680dfaa 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -1040,7 +1040,7 @@ func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbGrou groupIDs := utils.Distinct(utils.Slice(requests, func(e *relationTb.GroupRequestModel) string { return e.GroupID })) - groups, err := s.GroupDatabase.FindGroup(ctx, groupIDs) + groups, err := s.GroupDatabase.FindNotDismissedGroup(ctx, groupIDs) if err != nil { return nil, err } diff --git a/pkg/common/db/controller/group.go b/pkg/common/db/controller/group.go index e2b5f90b3..ba4ae18df 100644 --- a/pkg/common/db/controller/group.go +++ b/pkg/common/db/controller/group.go @@ -39,6 +39,7 @@ type GroupDatabase interface { CreateGroup(ctx context.Context, groups []*relationTb.GroupModel, groupMembers []*relationTb.GroupMemberModel) error TakeGroup(ctx context.Context, groupID string) (group *relationTb.GroupModel, err error) FindGroup(ctx context.Context, groupIDs []string) (groups []*relationTb.GroupModel, err error) + FindNotDismissedGroup(ctx context.Context, groupIDs []string) (groups []*relationTb.GroupModel, err error) SearchGroup( ctx context.Context, keyword string, @@ -581,3 +582,7 @@ func (g *groupDatabase) CountRangeEverydayTotal(ctx context.Context, start time. func (g *groupDatabase) FindGroupRequests(ctx context.Context, groupID string, userIDs []string) (int64, []*relationTb.GroupRequestModel, error) { return g.groupRequestDB.FindGroupRequests(ctx, groupID, userIDs) } + +func (g *groupDatabase) FindNotDismissedGroup(ctx context.Context, groupIDs []string) (groups []*relationTb.GroupModel, err error) { + return g.groupDB.FindNotDismissedGroup(ctx, groupIDs) +} diff --git a/pkg/common/db/relation/group_model.go b/pkg/common/db/relation/group_model.go index 697427e04..853f5dccd 100644 --- a/pkg/common/db/relation/group_model.go +++ b/pkg/common/db/relation/group_model.go @@ -99,3 +99,7 @@ func (g *GroupGorm) CountRangeEverydayTotal(ctx context.Context, start time.Time } return v, nil } + +func (g *GroupGorm) FindNotDismissedGroup(ctx context.Context, groupIDs []string) (groups []*relation.GroupModel, err error) { + return groups, utils.Wrap(g.DB.Where("group_id in (?) and status != ?", groupIDs, constant.GroupStatusDismissed).Find(&groups).Error, "") +} diff --git a/pkg/common/db/table/relation/group.go b/pkg/common/db/table/relation/group.go index 2bafb53ec..6759e0d35 100644 --- a/pkg/common/db/table/relation/group.go +++ b/pkg/common/db/table/relation/group.go @@ -51,6 +51,7 @@ type GroupModelInterface interface { UpdateMap(ctx context.Context, groupID string, args map[string]interface{}) (err error) UpdateStatus(ctx context.Context, groupID string, status int32) (err error) Find(ctx context.Context, groupIDs []string) (groups []*GroupModel, err error) + FindNotDismissedGroup(ctx context.Context, groupIDs []string) (groups []*GroupModel, err error) Take(ctx context.Context, groupID string) (group *GroupModel, err error) Search( ctx context.Context, From a73d8fe4f6b762c5bf31eea5bc9e5f6cb67e83fa Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 28 Jul 2023 20:21:40 +0800 Subject: [PATCH 10/13] fix bug: join group failed --- .github/workflows/build-docker-image.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index d58bf7ad0..3dd64c930 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -47,8 +47,6 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} -======= ->>>>>>> upstream/main - name: Build and push Docker image uses: docker/build-push-action@v4 with: From baae864903699fa46767201ebc4883d0f21318a6 Mon Sep 17 00:00:00 2001 From: skiffer-git <72860476+skiffer-git@users.noreply.github.com> Date: Fri, 28 Jul 2023 22:14:14 +0800 Subject: [PATCH 11/13] synchronize the image and tag name of open-im-server --- docker-compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index cd80dbf19..e019d853e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -100,7 +100,7 @@ services: openim_server: - image: ghcr.io/openimsdk/openim-server:v3.0 + image: ghcr.io/openimsdk/openim-server:v3.1.0 container_name: openim-server volumes: - ./logs:/Open-IM-Server/logs From 28177654c7ebab4dfeb4ce1561487701ca122783 Mon Sep 17 00:00:00 2001 From: skiffer-git <72860476+skiffer-git@users.noreply.github.com> Date: Fri, 28 Jul 2023 22:19:05 +0800 Subject: [PATCH 12/13] restore the IP in the env to 127.0.0.1 --- .env | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.env b/.env index 910d864b8..048662d97 100644 --- a/.env +++ b/.env @@ -1,5 +1,5 @@ USER=root PASSWORD=openIM123 -MINIO_ENDPOINT=http://113.99.98.99:10005 -API_URL=http://113.99.98.99:10002/object/ -DATA_DIR=./ \ No newline at end of file +MINIO_ENDPOINT=http://127.0.0.1:10005 +API_URL=http://127.0.0.1:10002/object/ +DATA_DIR=./ From 1e2d175c67274d50a95dfb4268ee1c0a33fc3cb3 Mon Sep 17 00:00:00 2001 From: skiffer-git <72860476+skiffer-git@users.noreply.github.com> Date: Fri, 28 Jul 2023 22:37:35 +0800 Subject: [PATCH 13/13] synchronize the image and tag name of chat --- docker-compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index e019d853e..d5565ca52 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -124,7 +124,7 @@ services: max-file: "2" openim_chat: - image: ghcr.io/openimsdk/openim-chat:v1.0.0 + image: ghcr.io/openimsdk/openim-chat:v1.1.0 container_name: openim_chat restart: always depends_on: