anuj commited on
Commit
41bc73a
·
1 Parent(s): ef798ec
Files changed (2) hide show
  1. Dockerfile +16 -5
  2. start.sh +3 -35
Dockerfile CHANGED
@@ -24,13 +24,24 @@ RUN curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
24
  && apt-get update \
25
  && apt-get install -y mongodb-org mongodb-mongosh
26
 
27
- # Create required directories
28
  RUN mkdir -p /data/db /opt/Rocket.Chat /var/log && \
29
- touch /var/log/mongodb.log
 
 
30
 
31
- # Set proper permissions
32
- RUN chown -R mongodb:mongodb /data/db /var/log/mongodb.log && \
33
- chmod 777 /var/log/mongodb.log
 
 
 
 
 
 
 
 
 
34
 
35
  # Create rocketchat user
36
  RUN useradd -M rocketchat && \
 
24
  && apt-get update \
25
  && apt-get install -y mongodb-org mongodb-mongosh
26
 
27
+ # Create required directories and set permissions
28
  RUN mkdir -p /data/db /opt/Rocket.Chat /var/log && \
29
+ touch /var/log/mongodb.log && \
30
+ chown -R mongodb:mongodb /data/db /var/log/mongodb.log && \
31
+ chmod 777 /data/db /var/log/mongodb.log
32
 
33
+ # Create MongoDB config file
34
+ RUN echo "storage:" > /etc/mongod.conf && \
35
+ echo " dbPath: /data/db" >> /etc/mongod.conf && \
36
+ echo "systemLog:" >> /etc/mongod.conf && \
37
+ echo " destination: file" >> /etc/mongod.conf && \
38
+ echo " path: /var/log/mongodb.log" >> /etc/mongod.conf && \
39
+ echo " logAppend: true" >> /etc/mongod.conf && \
40
+ echo "net:" >> /etc/mongod.conf && \
41
+ echo " bindIp: 127.0.0.1" >> /etc/mongod.conf && \
42
+ echo " port: 27017" >> /etc/mongod.conf && \
43
+ echo "replication:" >> /etc/mongod.conf && \
44
+ echo " replSetName: rs01" >> /etc/mongod.conf
45
 
46
  # Create rocketchat user
47
  RUN useradd -M rocketchat && \
start.sh CHANGED
@@ -1,28 +1,8 @@
1
  #!/bin/bash
2
  set -e
3
 
4
- echo "Creating MongoDB configuration..."
5
- cat > /tmp/mongod.conf << EOF
6
- storage:
7
- dbPath: /data/db
8
- systemLog:
9
- destination: file
10
- path: /var/log/mongodb.log
11
- logAppend: true
12
- net:
13
- bindIp: 127.0.0.1
14
- port: 27017
15
- replication:
16
- replSetName: rs01
17
- EOF
18
-
19
- # Ensure proper permissions
20
- echo "Setting up permissions..."
21
- chown -R mongodb:mongodb /data/db /var/log/mongodb.log
22
-
23
- # Start MongoDB
24
  echo "Starting MongoDB..."
25
- mongod --config /tmp/mongod.conf &
26
 
27
  # Wait for MongoDB to be ready
28
  echo "Waiting for MongoDB to start..."
@@ -49,20 +29,8 @@ mongosh --eval 'rs.initiate({_id: "rs01", members: [{_id: 0, host: "localhost:27
49
  exit 1
50
  }
51
 
52
- # Wait for replica set to initialize
53
- echo "Waiting for replica set to be ready..."
54
- attempt=1
55
- while ! mongosh --eval "rs.status()" | grep -q '"ok" : 1'; do
56
- if [ $attempt -gt $max_attempts ]; then
57
- echo "Replica set failed to initialize after $max_attempts attempts"
58
- exit 1
59
- fi
60
- echo "Attempt $attempt of $max_attempts: Replica set not ready yet..."
61
- sleep 2
62
- attempt=$((attempt + 1))
63
- done
64
-
65
- echo "Replica set initialized successfully"
66
 
67
  # Start Rocket.Chat
68
  echo "Starting Rocket.Chat..."
 
1
  #!/bin/bash
2
  set -e
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  echo "Starting MongoDB..."
5
+ mongod --config /etc/mongod.conf &
6
 
7
  # Wait for MongoDB to be ready
8
  echo "Waiting for MongoDB to start..."
 
29
  exit 1
30
  }
31
 
32
+ echo "Waiting for replica set to initialize..."
33
+ sleep 5
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  # Start Rocket.Chat
36
  echo "Starting Rocket.Chat..."