Skip to content

Commit

Permalink
test(.travis.yml): try Bottle-Mongo's Travis-CI setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sefriol committed Jun 21, 2020
1 parent e26063b commit 6f79907
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 16 deletions.
65 changes: 49 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: node_js

sudo: false

node_js:
- '10'
- '11'
Expand All @@ -11,22 +9,57 @@ node_js:
install: npm install

before_script:
- echo "replication:" | sudo tee -a /etc/mongod.conf
- |-
echo " replSetName: \"rs0\"" | sudo tee -a /etc/mongod.conf
- sudo service mongod restart
- sleep 20
- |
mongo --eval 'rs.initiate({_id:"rs0", members: [{"_id":1, "host":"localhost:27017"},{"_id":2, "host":"localhost:27018"},{"_id":3, "host":"localhost:27019"}]})'
- sudo systemctl stop mongod
# List existing mongo process
# Set up a shared authentication key
# - openssl rand -base64 741 | sudo tee /etc/mongodb.authkey
# - sudo chown mongodb /etc/mongodb.authkey
# - sudo chmod 600 /etc/mongodb.authkey

# Begin modification of the default mongoDB instance
# - echo "replSet = rs0" | sudo tee -a /etc/mongodb.conf
# - echo "oplogSize = 250" | sudo tee -a /etc/mongodb.conf
# - echo "keyFile = /etc/mongodb.authkey" | sudo tee -a /etc/mongodb.conf
# - echo "dbpath = /var/lib/mongodb/rs0" | sudo tee -a /etc/mongodb.conf
- sudo cp .travis/mongo.conf /etc/mongodb.conf
# Wipe out the data directory so we are clean with our configuration
- sudo rm -rf /var/lib/mongodb/*
- sudo rm -rf /var/log/mongodb/mongodb.log

# Create new directory for first replica set
- sudo mkdir /var/lib/mongodb/rs0
- sudo chown mongodb /var/lib/mongodb/rs0

# Start up the service using the normal init script
- sudo cat /etc/mongodb.conf
- sudo -u mongodb mongod --config /etc/mongodb.conf --logpath /tmp/mongodb_rs0.log || { sudo cat /tmp/mongodb_rs0.log; exit 1; }
# - sudo systemctl start mongod || { cat /var/log/mongodb/mongodb.log; exit 1; }

# Just wait until we are sure it is up
- bash -c "while true; do mongo --quiet --port 27017 --eval 'if (!db.stats().ok) { quit(1) }' || { sleep 2; continue; } && break; done;"

#- echo "logpath = /tmp/mongodb_rs0.log" | sudo tee -a /etc/mongodb.conf
- sudo cp /etc/mongodb.conf /etc/mongodb_rs1.conf
#- echo "port = 27018" | sudo tee -a /etc/mongodb_rs1.conf
- |
mongo --eval 'rs.status().ok'
sudo sed -i 's,port: 27017,port: 27018,' /etc/mongodb_rs1.conf
- sudo sed -i 's,/var/lib/mongodb/rs0,/var/lib/mongodb/rs1,' /etc/mongodb_rs1.conf
- sudo sed -i 's,/tmp/mongodb_rs0.log,/tmp/mongodb_rs1.log,' /etc/mongodb_rs1.conf

# Create the data directory for the secondary
- sudo mkdir /var/lib/mongodb/rs1
- sudo chown mongodb /var/lib/mongodb/rs1

# Start the secondary instance using the plain mongod command
- sudo cat /etc/mongodb_rs1.conf
- sudo -u mongodb mongod --config /etc/mongodb_rs1.conf --logpath /tmp/mongodb_rs1.log|| { sudo cat /tmp/mongodb_rs1.log; exit 1; }

# Wait for the secondary to start up
- mongo --port 27018 --eval 'db.stats()'
- bash -c "while true; do mongo --quiet --port 27018 --eval 'if (!db.stats().ok) { quit(1) }' || { sleep 2; continue; } && break; done;"
- |
while [[ $? -eq 0 ]];
do
sleep 5
echo sleeping for 5s
mongo --eval 'rs.status().ok'
done
mongo --eval 'rs.initiate({_id:"rs0", members: [{"_id":0, "host":"travis:27017"},{"_id":1, "host":"travis:27018"}]})'
- bash -c "while true; do mongo --quiet --eval 'if (!rs.status().ok) { quit(1) }' || { sleep 2; continue; } && break; done;"

script:
- echo "Running tests against $(node -v)..."
Expand Down
18 changes: 18 additions & 0 deletions .travis/mongo.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
systemLog:
destination: file
path: "/tmp/mongodb_rs0.log"
logAppend: true
storage:
dbPath: "/var/lib/mongodb/rs0"
journal:
enabled: true
processManagement:
fork: true
net:
bindIp: 127.0.0.1
port: 27017
setParameter:
enableLocalhostAuthBypass: true
replication:
replSetName: "rs0"
oplogSizeMB: 250

0 comments on commit 6f79907

Please sign in to comment.