From b33294eec39f4a25f67043f36f17fbd7d05803f4 Mon Sep 17 00:00:00 2001 From: Victor Denisov Date: Sun, 9 Apr 2017 10:39:31 -0700 Subject: [PATCH] Add docker-compose file for dev environment --- README.md | 65 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 14 ++++++++++ reattach.sh | 3 +++ 3 files changed, 82 insertions(+) create mode 100644 docker-compose.yml create mode 100755 reattach.sh diff --git a/README.md b/README.md index 7bf8fcd..14857fe 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,68 @@ This is the Haskell MongoDB driver (client). [MongoDB](http://www.mongodb.org) i * [MapReduce example](http://github.com/mongodb-haskell/mongodb/blob/master/doc/map-reduce-example.md) * [Driver design](https://github.com/mongodb-haskell/mongodb/blob/master/doc/Article1.md) * [MongoDB DBMS](http://www.mongodb.org) + +### Dev Environment + +It's important for this library to be tested with various versions of mongodb +server and with different ghc versions. In order to achieve this we use docker +containers and docker-compose. This repository contains two files: docker-compose.yml +and reattach.sh. + +Docker compose file describes two containers. + +One container is for running mongodb server. If you want a different version of +mongodb server you need to change the tag of mongo image in the +docker-compose.yml. In order to start your mongodb server you need to run: + +``` +docker-compose up -d mongodb +``` + +In order to stop your containers without loosing the data inside of it: + +``` +docker-compose stop mongodb +``` + +Restart: + +``` +docker-compose start mongodb +``` + +If you want to remove the mongodb container and start from scratch then: + +``` +docker-compose stop mongodb +docker-compose rm mongodb +docker-compose up -d mongodb +``` + +The other container is for compiling your code. By specifying the tag of the image +you can change the version of ghc you will be using. If you never started this +container then you need: + +``` +docker-compose run mongodb-haskell +``` + +It will start the container and mount your working directory to +`/opt/mongodb-haskell` If you exit the bash cli then the conainer will stop. +In order to reattach to an old stopped container you need to run script +`reattach.sh`. If you run `docker-compose run` again it will create another +container and all work made by cabal will be lost. `reattach.sh` is a +workaround for docker-compose's inability to pick up containers that exited. + +When you are done with testing you need to run: +``` +docker-compose stop mongodb +``` + +Next time you will need to do: +``` +docker-compose start mongodb +reattach.sh +``` +It will start your stopped container with mongodb server and pick up the stopped +container with haskell. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1f0dffd --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3' +services: + mongodb: + image: mongo:3.4.3 + mongodb-haskell: + image: phadej/ghc:8.0.2 + environment: + - HASKELL_MONGODB_TEST_HOST=mongodb + entrypoint: + - /bin/bash + volumes: + - ./:/opt/mongodb-haskell + +# vim: ts=2 et sw=2 ai diff --git a/reattach.sh b/reattach.sh new file mode 100755 index 0000000..02b3d7b --- /dev/null +++ b/reattach.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker start -ai mongodb_mongodb-haskell_run_1