How to use MongoDB on travis-ci

Using continuous integration for rainbrurph, I need the mongodb database and C libraries. Unfortunately, I had issue using it on Ubuntu Precise 12.04 LTS, the distribution used on travis-ci.

To make it work, we'll have to :
  1. install database components from the official MongoDB repositories;
  2. manually build the latest release of the official C libraries;
  3. add /usr/local/ to ld.conf to make your build system discover the newly installed library.


Note: I use the \ character to split long lines here, please concatenate splitted lines.
The travis.yml file at github

Install the database

We have to install the official package from the mongodb.org servers :

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 \
  --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.2 \
  multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org

Build the driver library

To be able to use mongodb in C programming language, we need a C library. We'll use the 1.4.0 version :

git clone https://github.com/mongodb/mongo-c-driver.git
cd mongo-c-driver
git checkout 1.4.0
./autogen.sh
make
sudo make install

Handle ld.conf

And to handle mongodb library linking, we must update ldconfig:
grep local /etc/ld.so.conf || (sudo echo "/usr/local/lib" >> \
  /etc/ld.so.conf && sudo ldconfig)

Conclusion

Finally, here is the .travis.yml file:
sudo: required
os:
- linux
branches:
  only:
    - master
    - mongodb-script


before_install: ./CI/before_install.sh
The CI/before_install.sh file will look like this:
#!/bin/sh

# Install the mongodb components and the C client library

## Install the mongo Database
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 \
  --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.2 \
  multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org

## Install the C library
git clone https://github.com/mongodb/mongo-c-driver.git
cd mongo-c-driver
git checkout 1.4.0
./autogen.sh
make
sudo make install

## Handle linking from /usr/local
sudo echo "/usr/local/lib" > /etc/ld.so.conf.d/mongodb.conf
sudo ldconfig

Comments

  1. CI and CD are two acronyms that are regularly made reference to when individuals discuss present day advancement hones. CI is clear and stands for persistent combination, I find a very good website for the Travis CI Build Monitoring , If you want you can visit this site.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to make a map of variant in C++