Signed-off-by: Gordon <46924906+FGadvancer@users.noreply.github.com>pull/699/head
commit
7eeb3d6792
@ -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/openimsdk/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/openimsdk/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.
|
@ -0,0 +1,42 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package unrelation
|
||||
|
||||
import "context"
|
||||
|
||||
// SubscribeUser collection constant.
|
||||
const (
|
||||
SubscribeUser = "subscribe_user"
|
||||
)
|
||||
|
||||
// UserModel collection structure.
|
||||
type UserModel struct {
|
||||
UserID string `bson:"user_id" json:"userID"`
|
||||
UserIDList []string `bson:"user_id_list" json:"userIDList"`
|
||||
}
|
||||
|
||||
func (UserModel) TableName() string {
|
||||
return SubscribeUser
|
||||
}
|
||||
|
||||
// UserModelInterface Operation interface of user mongodb.
|
||||
type UserModelInterface interface {
|
||||
// AddSubscriptionList Subscriber's handling of thresholds.
|
||||
AddSubscriptionList(ctx context.Context, userID string, userIDList []string) error
|
||||
// UnsubscriptionList Handling of unsubscribe.
|
||||
UnsubscriptionList(ctx context.Context, userID string, userIDList []string) error
|
||||
// RemoveSubscribedListFromUser Among the unsubscribed users, delete the user from the subscribed list.
|
||||
RemoveSubscribedListFromUser(ctx context.Context, userID string, userIDList []string) error
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package unrelation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
|
||||
"github.com/OpenIMSDK/tools/utils"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"log"
|
||||
)
|
||||
|
||||
// prefixes and suffixes.
|
||||
const (
|
||||
SubscriptionPrefix = "subscription_prefix"
|
||||
SubscribedPrefix = "subscribed_prefix"
|
||||
)
|
||||
|
||||
// MaximumSubscription Maximum number of subscriptions.
|
||||
const (
|
||||
MaximumSubscription = 3000
|
||||
)
|
||||
|
||||
func NewUserMongoDriver(database *mongo.Database) unrelation.UserModelInterface {
|
||||
return &UserMongoDriver{
|
||||
userCollection: database.Collection(unrelation.SubscribeUser),
|
||||
}
|
||||
}
|
||||
|
||||
type UserMongoDriver struct {
|
||||
userCollection *mongo.Collection
|
||||
}
|
||||
|
||||
// AddSubscriptionList Subscriber's handling of thresholds.
|
||||
func (u *UserMongoDriver) AddSubscriptionList(ctx context.Context, userID string, userIDList []string) error {
|
||||
// Check the number of lists in the key.
|
||||
filter := bson.M{SubscriptionPrefix + userID: bson.M{"$size": 1}}
|
||||
result, err := u.userCollection.Find(context.Background(), filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var newUserIDList []string
|
||||
for result.Next(context.Background()) {
|
||||
err := result.Decode(&newUserIDList)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
// If the threshold is exceeded, pop out the previous MaximumSubscription - len(userIDList) and insert it.
|
||||
if len(newUserIDList)+len(userIDList) > MaximumSubscription {
|
||||
newUserIDList = newUserIDList[MaximumSubscription-len(userIDList):]
|
||||
_, err := u.userCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"user_id": SubscriptionPrefix + userID},
|
||||
bson.M{"$set": bson.M{"user_id_list": newUserIDList}},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//for i := 1; i <= MaximumSubscription-len(userIDList); i++ {
|
||||
// _, err := u.userCollection.UpdateOne(
|
||||
// ctx,
|
||||
// bson.M{"user_id": SubscriptionPrefix + userID},
|
||||
// bson.M{SubscriptionPrefix + userID: bson.M{"$pop": -1}},
|
||||
// )
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//}
|
||||
}
|
||||
upsert := true
|
||||
opts := &options.UpdateOptions{
|
||||
Upsert: &upsert,
|
||||
}
|
||||
_, err = u.userCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"user_id": SubscriptionPrefix + userID},
|
||||
bson.M{"$addToSet": bson.M{"user_id_list": bson.M{"$each": userIDList}}},
|
||||
opts,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, user := range userIDList {
|
||||
_, err = u.userCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"user_id": SubscribedPrefix + user},
|
||||
bson.M{"$addToSet": bson.M{"user_id_list": userID}},
|
||||
opts,
|
||||
)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "transaction failed")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnsubscriptionList Handling of unsubscribe.
|
||||
func (u *UserMongoDriver) UnsubscriptionList(ctx context.Context, userID string, userIDList []string) error {
|
||||
_, err := u.userCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"user_id": SubscriptionPrefix + userID},
|
||||
bson.M{"$pull": bson.M{"user_id_list": bson.M{"$in": userIDList}}},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = u.RemoveSubscribedListFromUser(ctx, userID, userIDList)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveSubscribedListFromUser Among the unsubscribed users, delete the user from the subscribed list.
|
||||
func (u *UserMongoDriver) RemoveSubscribedListFromUser(ctx context.Context, userID string, userIDList []string) error {
|
||||
var newUserIDList []string
|
||||
for _, value := range userIDList {
|
||||
newUserIDList = append(newUserIDList, SubscribedPrefix+value)
|
||||
}
|
||||
_, err := u.userCollection.UpdateOne(
|
||||
ctx,
|
||||
bson.M{"user_id": bson.M{"$in": newUserIDList}},
|
||||
bson.M{"$pull": bson.M{"user_id_list": userID}},
|
||||
)
|
||||
return utils.Wrap(err, "")
|
||||
}
|
Loading…
Reference in new issue