MongoDB Docker Compose setup with initial dump import

A while ago started making use of the practicality of docker composes for setting up environments for servers and clusters. One of the biggest advantages things I found in such a setup, is the reproducibility of an environment for production, staging or development systems without much effort, together  with the easy automation of build and deployment processes without a lot of script writing.

One case we didn’t know how to address properly was the way to provide initial data dumps for the environments without exposing the mongo port to the outside world and/or a lot of manual intervention. Lately we found an easy solution we like to share.


version: '2'

services:

    mongo-db:
        image: mongo:3.2
        entrypoint: [ "/usr/bin/mongod", "--journal", "--smallfiles", "--rest" ]
        restart: always
        networks:
            - mongo

    mongosetup:
        image: mongo:3.2
        volumes:
            - ./dump:/dump
        entrypoint: ["mongorestore", "--host", "mongo-db", "/dump"]
        networks:
            - mongo

networks:
    mongo:

The easy setup utilises the ability of docker-compose to overwrite the default entry point of a container. Thus all the data in the mounted dump directory will be imported to the mongodb container on startup.

This approach can be taken further if a script is placed in another mounted directory and started instead. This could be used to e.g. delete the dump afterwards to prevent a reimport attempt if you don’t want to restart the service all the time or trigger some other actions after the dump is imported.

Maven Tycho Plugin Tests and slf4j

If your eclipse-test-plugin tests break in a maven Tycho build, you have to check the target/work/configuration folder for the log files.

Mybe you will find something like this:

!ENTRY de.dim.search.index.tests 2 0 2016-11-03 10:37:31.137
!MESSAGE Could not resolve module: de.dim.search.index.tests [13]
  Unresolved requirement: Require-Bundle: de.dim.search.index.core
    -> Bundle-SymbolicName: de.dim.search.index.core; bundle-version="1.2.0.201611030937"
       de.dim.search.index.core [9]
         Unresolved requirement: Import-Package: org.slf4j
           -> Export-Package: org.slf4j; bundle-symbolic-name="org.slf4j.api"; bundle-version="1.7.5.v20150828-1500"; version="1.7.5"; uses:="org.slf4j.spi"
              org.slf4j.api [11]
                Unresolved requirement: Import-Package: org.slf4j.impl; version="[1.6.0,1.7.6)"; resolution:="optional"
                Unresolved requirement: Require-Capability: org.slf4j.impl; filter:="(&(version>=1.6.0)(!(version>=1.7.6)))"
  Unresolved requirement: Fragment-Host: de.dim.search.index.core; bundle-version="1.2.0"
    -> Bundle-SymbolicName: de.dim.search.index.core; bundle-version="1.2.0.201611030937"


!ENTRY de.dim.search.index.core 2 0 2016-11-03 10:37:31.138
!MESSAGE Could not resolve module: de.dim.search.index.core [9]
  Unresolved requirement: Import-Package: org.slf4j
    -> Export-Package: org.slf4j; bundle-symbolic-name="org.slf4j.api"; bundle-version="1.7.5.v20150828-1500"; version="1.7.5"; uses:="org.slf4j.spi"
       org.slf4j.api [11]
         Unresolved requirement: Import-Package: org.slf4j.impl; version="[1.6.0,1.7.6)"; resolution:="optional"
         Unresolved requirement: Require-Capability: org.slf4j.impl; filter:="(&(version>=1.6.0)(!(version>=1.7.6)))"


!ENTRY org.slf4j.api 2 0 2016-11-03 10:37:31.138
!MESSAGE Could not resolve module: org.slf4j.api [11]
  Unresolved requirement: Import-Package: org.slf4j.impl; version="[1.6.0,1.7.6)"; resolution:="optional"
  Unresolved requirement: Require-Capability: org.slf4j.impl; filter:="(&(version>=1.6.0)(!(version>=1.7.6)))"

The resolution is to add the fragment ch.qos.logback.slf4j to the manifest and mark it as optional debendency.

Ensure that slf4j and logback is in you target platform. You will find it int the Eclipse Orbit.

Using P2 Repositories with Bndtools

Bndtools support multiple types of repositories to grep artifacts from. For a while now P2 Repositories are supported as well, but information on how to add them are sparse and it is not obvious if you are new to bnd.

What to do:

Open the build.bnd in the cnf Project and switch to the source view. To add a repository add an entry like this:

-plugin.3.mars: \
 aQute.bnd.repository.p2.provider.P2Repository; \
 url = http://download.eclipse.org/releases/mars; \
 name = mars

My colleague urged me to give the following WARNING after he tried it himself: This example will cause bndtools do download the whole repository with all the content. Thus this may take a while!

We hope this might be helpful to you as well.

Eclipse RCP product icons and Maven Tycho

Last time I encountered some problems with application launcher icons when building my RCP application with Maven Tycho.

I got a FileNotFound Exception during product build for the Linux XPM-icon file. For a windows build I got a build-warning: “Error – 7 icon not replaced in …”.

Stackoverflow led me to a post that says something about the icons sizes for Windows launchers [1]. According to this, the following sizes are expected:

For Eclipse 3.7.2:

  • 48×48 8 bit (256 colors)
  • 32×32 8 bit
  • 24×24 8 bit
  • 16×16 8 bit
  • 48×48 32 bit (RGB + Alpha)
  • 32×32 32 bit
  • 16×16 32 bit

For Eclipse 4.2:

  • 256×256, 32 bit (RGB / Alpha Channel)
  • 48×48, 32 bit (RGB / Alpha Channel)
  • 32×32, 32 bit (RGB / Alpha Channel)
  • 16×16, 32 bit (RGB / Alpha Channel)
  • 48×48, 8 bit (256 colors)
  • 32×32, 8 bit (256 colors)
  • 16×16, 8 bit (256 colors)

I use The Gimp to create the ico files. But it is also possible to do an automatic conversion under Linux using ImageMagick and icotools. For this there is a tutorial here [2].

Furthermore you have to take care about the launcher file path in the product definition file. It mustn’t start with a slash, otherwise you will get a FileNotFound Exception during product build for the Linux XPM-icon file.

[1] http://stackoverflow.com/questions/10999323/error-in-tycho-while-replacing-the-product-ico-files

[2] http://tomsondev.bestsolution.at/2007/06/26/branding-for-windows-how-to-create-ico-files-automatically/

Hallo World!

Welcome to the Data In Motion Tech Blog. Here we will present code snippets and tricks regarding the topics Eclipse, OSGi, Gyrex, E4 and Java that hopefully will be interesting to you, too.

Through our daily work, we stumble upon a lot of interesting technologies and develop heaps of code worth sharing. Thus we have decided to spread our wisdom, in the hope to find other interested souls.

Happy reading,

your Data In Motion Development Team.