build: update mongo and kafka start logic. (#2858)
* build: update mongo and kafka start logic. * build: update go version image in dockerfile. * build: remove zookeeper image. * add authSource comment. * update tools version. * add created sucess print. * remove unused script. * format.pull/2861/head
parent
12790e141d
commit
e0284724b5
@ -1,55 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# 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.
|
||||
|
||||
# Wait for Kafka to be ready
|
||||
|
||||
KAFKA_SERVER=localhost:9092
|
||||
|
||||
MAX_ATTEMPTS=300
|
||||
attempt_num=1
|
||||
|
||||
echo "Waiting for Kafka to be ready..."
|
||||
|
||||
until /opt/bitnami/kafka/bin/kafka-topics.sh --list --bootstrap-server $KAFKA_SERVER; do
|
||||
echo "Attempt $attempt_num of $MAX_ATTEMPTS: Kafka not ready yet..."
|
||||
if [ $attempt_num -eq $MAX_ATTEMPTS ]; then
|
||||
echo "Kafka not ready after $MAX_ATTEMPTS attempts, exiting"
|
||||
exit 1
|
||||
fi
|
||||
attempt_num=$((attempt_num+1))
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "Kafka is ready. Creating topics..."
|
||||
|
||||
|
||||
topics=("toRedis" "toMongo" "toPush" "toOfflinePush")
|
||||
partitions=8
|
||||
replicationFactor=1
|
||||
|
||||
for topic in "${topics[@]}"; do
|
||||
if /opt/bitnami/kafka/bin/kafka-topics.sh --create \
|
||||
--bootstrap-server $KAFKA_SERVER \
|
||||
--replication-factor $replicationFactor \
|
||||
--partitions $partitions \
|
||||
--topic $topic
|
||||
then
|
||||
echo "Topic $topic created."
|
||||
else
|
||||
echo "Failed to create topic $topic."
|
||||
fi
|
||||
done
|
||||
|
||||
echo "All topics created."
|
@ -1,66 +0,0 @@
|
||||
# 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.
|
||||
mongosh <<EOF
|
||||
var maxRetries = 300;
|
||||
var connected = false;
|
||||
var rootUsername = '$MONGO_INITDB_ROOT_USERNAME';
|
||||
var rootPassword = '$MONGO_INITDB_ROOT_PASSWORD';
|
||||
var dbName = '$MONGO_INITDB_DATABASE';
|
||||
var openimUsername = '$MONGO_OPENIM_USERNAME';
|
||||
var openimPassword = '$MONGO_OPENIM_PASSWORD';
|
||||
|
||||
while (!connected && maxRetries > 0) {
|
||||
try {
|
||||
db = connect('mongodb://127.0.0.1:27017/admin');
|
||||
var authResult = db.auth(rootUsername, rootPassword);
|
||||
if (authResult) {
|
||||
print('Authentication successful for root user: ' + rootUsername);
|
||||
connected = true;
|
||||
} else {
|
||||
print('Authentication failed for root user: ' + rootUsername + ' with password: ' + rootPassword);
|
||||
quit(1);
|
||||
}
|
||||
} catch (e) {
|
||||
maxRetries--;
|
||||
print('Connection failed, retrying... Remaining attempts: ' + maxRetries);
|
||||
sleep(1000); // Sleep for 1 second
|
||||
}
|
||||
}
|
||||
|
||||
if (connected) {
|
||||
db = db.getSiblingDB(dbName);
|
||||
var createUserResult = db.createUser({
|
||||
user: openimUsername,
|
||||
pwd: openimPassword,
|
||||
roles: [{
|
||||
role: 'readWrite',
|
||||
db: dbName
|
||||
}]
|
||||
});
|
||||
|
||||
if (createUserResult.ok == 1) {
|
||||
print('User creation successful. User: ' + openimUsername + ', Database: ' + dbName);
|
||||
} else {
|
||||
print('User creation failed for user: ' + openimUsername + ' in database: ' + dbName);
|
||||
quit(1);
|
||||
}
|
||||
} else {
|
||||
print('Failed to connect to MongoDB after 300 retries.');
|
||||
quit(1);
|
||||
}
|
||||
EOF
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in new issue