Instant Messaging using Erlang and XMPP — Part 2 — Local Dev Setup

Jul 20, 2021

Note: When I started writing this, I was using customized MongooseIM version 3.7.1, now latest updates using TOML config and such have come up as on July 2021. So, if you want to refer to the latest documentation, feel free to read it here .

Setting Up Local Development Environment for MongooseIM:

There are a couple of ways to set up local development environment, obviously, first one is to clone the official repo and getting started, which if you have to do it for multiple systems, becomes a tedious job. So, I’ve written a simple Dockerfile, based on my convenience. Feel free to use it, if you want!

In case, you want to upgrade the Erlang version, change esl-erlang={DESIRED_VERSION}

FROM ubuntu:16.04

RUN apt-get update && \
    apt-get install -y --install-recommends unixodbc-dev rsync \
    postgresql-client redis-tools wget git \
    make gcc g++ libc6-dev libncurses5-dev \
    libssl-dev libexpat1-dev libpam0g-dev \
    unixodbc-dev gnupg zlib1g-dev \
    unzip python2.7 wget && \
    wget http://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && \
    dpkg -i erlang-solutions_2.0_all.deb && \
    apt-get update && \
    apt-get install -y esl-erlang=1:22.3-1 --install-recommends && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN ln -snf python2.7 /usr/bin/python2

# This line makes sure the big tests passes multi-user chat based scenario
RUN echo "127.0.0.1   muc.localhost" >> /etc/hosts

I’ve set it up in such a way, that I have pushed the docker image to a private repo and using them in my docker-compose file.

Databases:

MongooseIM supports SQL and NoSQL Databases, as well as it can run without database too, if you prefer it that way. For one of my clients, I had to use a new Database(CockroachDB) which was not natively supported by MongooseIM. I had to make some changes to the core codebase and modify certain codec to make it work without issues.

As I was writing this post, still support for CockroachDB has not been included by MongooseIM team. Feel free to reach out to me directly, in case you want to understand more on how things were done.

Session Store:

MongooseIM uses in-built mnesia as it’s default session store, unless you want to switch to a more robust redis server.

Docker Compose:

We have got multiple components and managing them separately will become tedious and hence, I have got a docker-compose file with skeleton of services included, you can expand them as per your needs. Knowingly, I’ve left out some other services, as they too much in the beginning itself.

version: "3.8"

services:
  mim:
    container_name: mim
    build: .
    working_dir: /app
    volumes:
      - /mim-src:/app
    stdin_open: true
    tty: true
    command: sh -c "echo '127.0.0.1     muc.localhost' >> /etc/hosts && bash"
    environment:
      - PGCLIENTENCODING='utf-8'
    depends_on:
      - db
      - redis
    ports:
      - 5225:5222
    networks:
      - internal

  db:
    container_name: db
    image: postgresql:latest
    hostname: db
    ports:
      - 5432:5432
    stdin_open: true
    tty: true
    volumes:
      - ./data/db:/var/lib/postgresql/data
    networks:
      - internal

  redis:
    container_name: cache
    image: redis:6.0.9-alpine
    command: redis-server --port 6379 --bind 0.0.0.0
    ports:
      - 6379:6379
    networks:
      - internal

  s3:
    container_name: s3
    image: minio/minio:latest
    ports:
      - 9000:9000
    volumes:
      - ./data/s3:/data
    command: server /data
    environment:
      - MINIO_ACCESS_KEY=minioadmin
      - MINIO_SECRET_KEY=minioadmin
    networks:
      - internal

networks:
  internal:
    driver: bridge

MongooseIM Config File:

As I’ve already pointed out, you can use the default mongooseim.cfg or mongooseim.toml (The Latest Versions) and mount them in the appropriate directory in the docker-compose file.

Starting Dev Setup

This will start a default development server with the default config, if you have not added a mongooseim.cfg or mongooseim.toml file.

Well folks! This must have been a tedious journey. We still have a long journey ahead of us! Wrapping up the part two! Stay tuned for more.


   erlang (8) , mongooseim (4) , ejabberd (4) , xmpp (4) , instant-messaging (4) , docker (2) , docker-compose (1)