Upgrading RocketChat to 1.0.x and MongoDB to 4.0

With the recent release of Rocket.Chat 1.0.x (after a couple years undergoing development at a fairly blistering pace), it's time for many of us to upgrade!

Previously, I showed how to install Rocket.Chat via Docker Compose but that was a much earlier version of Rocket.Chat and version 3.4 of MongoDB, which is now quite old (by FOSS standards at least). And it turns out upgrading everything has a few gotchas, so here's how I managed to do it.

Before you do anything do a backup of your MongoDB!

The first thing you need to do is upgrade the way in which you're running MongoDB. You have to enable a capability called "Local Replication".

Update your Docker Compose configuration

My first step, after logging into my virtual machine via SSH as the unprivileged user that I created to run docker commands, was to update my docker-compose.yml file (if you followed my previous instructions, you'll find it in /home/www/docker-rocketchat-wekan-mongo). 

First, make a backup of it nearby...

cd /home/www/docker-rocketchat-wekan-mongo
cp docker-compose.yml docker-compose.yml-mongo3.4

and then edit the file to say this:

version: '2'
services:
  mongo:
    restart: unless-stopped
    image: mongo:3.4
    volumes:
      - [data directory path]:/data/db
      - [backup directory path]:/backups
    command: --smallfiles --oplogSize 128 --replSet rs0
  # this container's job is just run the command to initialize the replica set.
  # it will run the command and remove himself (it will not stay running)
  mongo-init-replica:
    image: mongo:3.4
    command: 'bash -c "for i in `seq 1 30`; do mongo mongo/rocketchat --eval \"rs.initiate({ _id: ''rs0'', members: [ { _id: 0, host: ''localhost:27017'' } ]})\" && s=$$? && break || s=$$?; echo \"Tried $$i times. Waiting 5 secs...\"; sleep 5; done; (exit $$s)"'
    depends_on:
      - mongo

  rocketchat:
    restart: unless-stopped
    image: rocketchat/rocket.chat:latest

    command: bash -c 'for i in `seq 1 30`; do node main.js && s=$$? && break || s=$$?; echo "Tried $$i times. Waiting 5 secs..."; sleep 5; done; (exit $$s)'
    ports:
      - "127.0.0.1:[port number]:3000" # should be a free port above 1024
    depends_on:
      - mongo
    environment:
      - MONGO_URL=mongodb://mongo/rocket
      - MONGO_OPLOG_URL=mongodb://mongo/local
      - ROOT_URL=[domain name (including schema, e.g. http://)]
    volumes:
      - [upload directory path]:/var/www/rocket.chat/uploads

    labels:
      - "traefik.backend=rocketchat"
      - "traefik.frontend.rule=Host: [your domain name (not including schema)]"

Now, having updated your docker-compose.yml file, you have to do a couple other things. To do the upgrade from MongoDB 3.4 to 4.0, you have to do the interim upgrade to 3.6 first.

Enabling Local Replication

First you need to check what version of MongoDB you're currently using - both the version you're running and the "Feature Compatibility Version" (you can run a newer version of MongoDB, but configure it to only run features from some previous version to avoid breaking older software that depends on old features)... Do this as follows.

Access your MongoDB instance:

docker-compose exec mongo bash

That should give you a command prompt that looks like this:

root@a56eefe9f352: #

but the container identifier (after the @) will be different (but the same length). At that prompt, you can run this command:

mongo --eval "db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )"

Tip: if you're on a Linux desktop, you can copy this command (via CTRL-C) from this document and past it into your SSH terminal window (via CTRL+SHIFT-V).

It should tell you you're either running "featureCompatibilityVersion" 3.2 or 3.4. If it's the latter, skip this next step. If not, run this next:

mongo --eval "db.adminCommand( { setFeatureCompatibilityVersion: '3.4' } )"

to set the version to 3.4. If the command succeeds you'll likely see something like

{ "ok" : 1 }

as the response.

Now you can upgrade your Mongo 3.4 is the latest version (should be 3.4.20 at the time of this writing). Get out of the container (back to your Docker host) via CTRL-D (or "exit" - they're synonymous for logging out of a terminal session). Then you can run:

docker-compose pull mongo

That should update both your Mongo docker container to the latest version in the 3.4 series.

The final step to enabling local replication is to run

docker-compose up -d mongo mongo-init-replica && docker-compose logs -f

That will restart MongoDB and drop you into the stream of logging from all the containers (including the rocket.chat container). It'll also start the "mongo-init-replica" container.  That container should run briefly and then exit cleanly having set up the local replication that you'll need for subsequent upgrades to MongoDB!

Check for any errors in the output... there might be a couple if it takes your MongoDB a bit of time to accept connections... as long as it eventually stops showing errors, you should be ok!

 

Upgrading Rocket.Chat to 1.0.x

Now that you're fully on version 3.4, running in local replica mode, you can update your Rocket.Chat instance.   Rocket.Chat still supports Mongo 3.4 (it won't for long, thus this tutorial!), so you can now upgrade the Rocket.Chat container as well as make sure your Mongo 3.4 is the latest version (should be 3.4.20 at the time of this writing).

Note that the latest version of the Rocket.Chat docker container could be quite a lot higher when you read this... if it's beyond, say, 1.1 it might be unsafe to use the approach I'm describing. You can check the current version release status. To protect yourself, you can alter the rocket.chat image line in your docker-compose.yml file to explicitly tell it to use the 1.0.x series for which these instructions should continue to apply... pick the highest 1.0.x version you can find in the releases and alter the line in docker-compose.yml to specify that version:

    image: rocketchat/rocket.chat:1.0.1

or whatever the latest 1.0.x version is. Then you can run:

docker-compose pull rocketchat

which will update your Rocket.Chat from the current version to the one specified.

Then restart your Rocket.Chat instance:

docker-compose up -d && docker-compose logs -f

That should restart both MongoDB and Rocket.Chat, and drop you into the stream of logging from both containers. It'll also start the "mongo-init-replica" container again, but having done its job it should exit happily again.

Check for any errors in the output... there might be a couple if it takes your MongoDB a bit of time to accept connections... as long as it eventually stops showing errors, you should be ok! Eventually, you should see something similar to (with version details updated appropriately):

 

+----------------------------------------------+
|                SERVER RUNNING                |
+----------------------------------------------+
|                                              |
|  Rocket.Chat Version: 1.0.1                  |
|       NodeJS Version: 8.11.4 - x64           |
|      MongoDB Version: 3.4.20                 |
|       MongoDB Engine: wiredTiger             |
|             Platform: linux                  |
|         Process Port: 3000                   |
|             Site URL: https://chat.oeru.org  |
|     ReplicaSet OpLog: Enabled                |
|          Commit Hash: 60f1a4afd6             |
|        Commit Branch: HEAD                   |
|                                              |
+----------------------------------------------+

Your instance is now running the right version! Time to tidy things up by upgrading Mongo the rest of the way to 4.0!

 

Upgrading to MongoDB 3.6

Now you can upgrade Mongo to 3.6. First, adjust your docker-compose.yml file.  Update both occurances of this line:

image: mongo:3.4

to

image: mongo:3.6

Then you can do another

docker-compose pull mongo

which will download the newer Mongo 3.6 docker container. Then you can again run

docker-compose up -d && docker-compose logs -f

Again check for errors. If there are none (other than perhaps a brief set of "mongo is not accepting connections" errors), you should be fine to update the "compatibility version" from 3.4 to 3.6... Get a session on your Mongo container via

docker-compose exec mongo bash

and then (as above) run this:

mongo --eval "db.adminCommand( { setFeatureCompatibilityVersion: '3.6' } )"

which should give you a more complicated response than that for the 3.4 transition, but it should still more or less say "ok"... To make sure everything's happy with the change, it's wise to run

docker-compose up -d && docker-compose logs -f

again and make sure there're no obvious errors. If not (after making another database backup for safety!!) we can proceed to Mongo 4.0!

Final push to MongoDB 4.0

Finally, you can again edit your docker-compose.yml and change both occurrences of

 

image: mongo:3.6

to

image: mongo:4.0

Then you can do a final

docker-compose pull mongo

which will download the newer Mongo 4.0 docker container. Then you can again run

docker-compose up -d && docker-compose logs -f

And, assuming you don't see any errors, you can push the feature compatibility to 4.0:

docker-compose exec mongo bash

and then run:

mongo --eval "db.adminCommand( { setFeatureCompatibilityVersion: '4.0' } )"

followed by a final

docker-compose up -d && docker-compose logs -f

And, again, if you don't see any errors... you should get something a bit like this:

+----------------------------------------------+
|                SERVER RUNNING                |
+----------------------------------------------+
|                                              |
|  Rocket.Chat Version: 1.0.1                  |
|       NodeJS Version: 8.11.4 - x64           |
|      MongoDB Version: 4.0.9                  |
|       MongoDB Engine: wiredTiger             |
|             Platform: linux                  |
|         Process Port: 3000                   |
|             Site URL: https://chat.oeru.org  |
|     ReplicaSet OpLog: Enabled                |
|          Commit Hash: 60f1a4afd6             |
|        Commit Branch: HEAD                   |
|                                              |
+----------------------------------------------+

you're done and future proofed!

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA
2 + 3 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
Are you the real deal?