Skip to content

Commit

Permalink
Update default config file to YAML format
Browse files Browse the repository at this point in the history
Resolves: #197

Fix tests to test the new config file format.

MongoDB 2.6 does not support modular storage engines.

Have MONGODB_NOPREALLOC only for backward compatibility.

Update tests to also use deprecated MONGODB_NOPREALLOC.

Use user management functions introduced in 2.6 (already used in common.sh scripts)
  • Loading branch information
Marek Skalický authored and omron93 committed Mar 21, 2017
1 parent c8af6e9 commit 12a0b41
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 78 deletions.
2 changes: 1 addition & 1 deletion 2.6/root/usr/bin/run-mongod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function usage() {
echo " MONGODB_DATABASE"
echo " MONGODB_ADMIN_PASSWORD"
echo "MongoDB settings:"
echo " MONGODB_NOPREALLOC (default: true)"
echo " MONGODB_PREALLOC (default: false)"
echo " MONGODB_SMALLFILES (default: true)"
echo " MONGODB_QUIET (default: true)"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion 2.6/root/usr/bin/run-mongod-replication
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function usage() {
echo "Optional variables:"
echo " MONGODB_SERVICE_NAME (default: mongodb)"
echo "MongoDB settings:"
echo " MONGODB_NOPREALLOC (default: true)"
echo " MONGODB_PREALLOC (default: false)"
echo " MONGODB_SMALLFILES (default: true)"
echo " MONGODB_QUIET (default: true)"
exit 1
Expand Down
3 changes: 2 additions & 1 deletion 2.6/root/usr/share/container-scripts/mongodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ The following environment variables influence the MongoDB configuration file. Th

| Variable name | Description | Default
| :-------------------- | ------------------------------------------------------------------------- | ----------------
| `MONGODB_NOPREALLOC` | Disable data file preallocation. | true
| `MONGODB_PREALLOC` | Enable data file preallocation. | false
| `MONGODB_NOPREALLOC` | DEPRECATED - use `MONGODB_PREALLOC` instead. Disable data file preallocation. |
| `MONGODB_SMALLFILES` | Set MongoDB to use a smaller default data file size. | true
| `MONGODB_QUIET` | Runs MongoDB in a quiet mode that attempts to limit the amount of output. | true

Expand Down
6 changes: 5 additions & 1 deletion 2.6/root/usr/share/container-scripts/mongodb/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ set -o pipefail
export MONGODB_DATADIR=/var/lib/mongodb/data
export CONTAINER_PORT=27017
# Configuration settings.
export MONGODB_NOPREALLOC=${MONGODB_NOPREALLOC:-true}
if [[ "${MONGODB_NOPREALLOC:-}" == "false" ]]; then
export MONGODB_PREALLOC=${MONGODB_PREALLOC:-true}
else
export MONGODB_PREALLOC=${MONGODB_PREALLOC:-false}
fi
export MONGODB_SMALLFILES=${MONGODB_SMALLFILES:-true}
export MONGODB_QUIET=${MONGODB_QUIET:-true}

Expand Down
43 changes: 27 additions & 16 deletions 2.6/root/usr/share/container-scripts/mongodb/mongodb.conf.template
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
# mongodb.conf
##
## For list of options visit:
## https://docs.mongodb.org/manual/reference/configuration-options/
##

port = ${CONTAINER_PORT}
# systemLog Options - How to do logging
systemLog:
# Runs the mongod in a quiet mode that attempts to limit the amount of output
quiet: ${MONGODB_QUIET}

# Set this value to designate a directory for the mongod instance to store its data.
# Default: /var/lib/mongodb/data
dbpath = ${MONGODB_DATADIR}

# Disable data file preallocation. Default: true
noprealloc = ${MONGODB_NOPREALLOC}
# net Options - Network interfaces settings
net:
# Specify port number (27017 by default)
port: ${CONTAINER_PORT}

# Set MongoDB to use a smaller default data file size. Default: true
smallfiles = ${MONGODB_SMALLFILES}

# Runs MongoDB in a quiet mode that attempts to limit the amount of output.
# Default: true
quiet = ${MONGODB_QUIET}
# storage Options - How and Where to store data
storage:
# Directory for datafiles (defaults to /data/db/)
dbPath: ${MONGODB_DATADIR}

# Disable the HTTP interface (Defaults to localhost:28017).
nohttpinterface = true
# Enable or disable the preallocation of data files (true by default)
preallocDataFiles: ${MONGODB_PREALLOC}

# Size to use (in MB) for replication op log (default 5% of disk space)
oplogSize = 64
# Use a smaller default file size (false by default)
smallFiles: ${MONGODB_SMALLFILES}


# replication Options - Configures replication
replication:
# Specifies a maximum size in megabytes for the replication operation log (i.e. the oplog,
# 5% of disk space by default)
oplogSizeMB: 64
23 changes: 12 additions & 11 deletions 2.6/test/run
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ function test_mongo() {
echo " Testing MongoDB"
if [ -v ADMIN_PASS ]; then
echo " Testing Admin user privileges"
mongo_admin_cmd "db=db.getSiblingDB('${DB}');db.removeUser('${USER}');"
mongo_admin_cmd "db=db.getSiblingDB('${DB}');db.addUser({user:'${USER}',pwd:'${PASS}',roles:['readWrite','userAdmin','dbAdmin']});"
mongo_admin_cmd "db=db.getSiblingDB('${DB}');db.dropUser('${USER}');"
mongo_admin_cmd "db=db.getSiblingDB('${DB}');db.createUser({user:'${USER}',pwd:'${PASS}',roles:['readWrite','userAdmin','dbAdmin']});"
mongo_admin_cmd "db=db.getSiblingDB('${DB}');db.testData.insert({x:0});"
mongo_cmd "db.addUser({user:'test_user2',pwd:'test_password2',roles:['readWrite']});"
mongo_cmd "db.createUser({user:'test_user2',pwd:'test_password2',roles:['readWrite']});"
fi
echo " Testing user privileges"
mongo_cmd "db.testData.insert({ y : 1 });"
Expand All @@ -112,18 +112,18 @@ function test_mongo() {

function test_config_option() {
local env_var=$1 ; shift
local setting=$1 ; shift
local value=$1 ; shift
local env_val=$1 ; shift
local config_part=$1 ; shift

local name="configuration_${setting}"
local name="configuration_${env_var}"

# If $value is a string, it needs to be in simple quotes ''.
DOCKER_ARGS="
-e MONGODB_DATABASE=db
-e MONGODB_USER=user
-e MONGODB_PASSWORD=password
-e MONGODB_ADMIN_PASSWORD=adminPassword
-e $env_var=${value//\'/}
-e $env_var=${env_val}
"
create_container ${name} ${DOCKER_ARGS}

Expand All @@ -135,16 +135,17 @@ function test_config_option() {
test_connection ${name}

# If nothing is found, grep returns 1 and test fails.
docker exec $(get_cid $name) bash -c "cat /etc/mongod.conf" | grep -q "$setting = $value"
docker exec $(get_cid $name) bash -c "cat /etc/mongod.conf" | grep -q "${config_part}"

docker stop $(get_cid ${name})
}

function run_configuration_tests() {
echo " Testing image configuration settings"
test_config_option MONGODB_NOPREALLOC noprealloc true
test_config_option MONGODB_SMALLFILES smallfiles true
test_config_option MONGODB_QUIET quiet true
test_config_option MONGODB_PREALLOC false "preallocDataFiles: false"
test_config_option MONGODB_NOPREALLOC true "preallocDataFiles: false"
test_config_option MONGODB_SMALLFILES true "smallFiles: true"
test_config_option MONGODB_QUIET true "quiet: true"
echo " Success!"
}

Expand Down
2 changes: 1 addition & 1 deletion 3.0-upg/root/usr/bin/run-mongod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function usage() {
echo " MONGODB_DATABASE"
echo " MONGODB_ADMIN_PASSWORD"
echo "MongoDB settings:"
echo " MONGODB_NOPREALLOC (default: true)"
echo " MONGODB_PREALLOC (default: false)"
echo " MONGODB_SMALLFILES (default: true)"
echo " MONGODB_QUIET (default: true)"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion 3.0-upg/root/usr/bin/run-mongod-replication
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function usage() {
echo "Optional variables:"
echo " MONGODB_SERVICE_NAME (default: mongodb)"
echo "MongoDB settings:"
echo " MONGODB_NOPREALLOC (default: true)"
echo " MONGODB_PREALLOC (default: false)"
echo " MONGODB_SMALLFILES (default: true)"
echo " MONGODB_QUIET (default: true)"
exit 1
Expand Down
3 changes: 2 additions & 1 deletion 3.0-upg/root/usr/share/container-scripts/mongodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ The following environment variables influence the MongoDB configuration file. Th

| Variable name | Description | Default
| :-------------------- | ------------------------------------------------------------------------- | ----------------
| `MONGODB_NOPREALLOC` | Disable data file preallocation. | true
| `MONGODB_PREALLOC` | Enable data file preallocation. | false
| `MONGODB_NOPREALLOC` | DEPRECATED - use `MONGODB_PREALLOC` instead. Disable data file preallocation. |
| `MONGODB_SMALLFILES` | Set MongoDB to use a smaller default data file size. | true
| `MONGODB_QUIET` | Runs MongoDB in a quiet mode that attempts to limit the amount of output. | true

Expand Down
6 changes: 5 additions & 1 deletion 3.0-upg/root/usr/share/container-scripts/mongodb/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ set -o pipefail
export MONGODB_DATADIR=/var/lib/mongodb/data
export CONTAINER_PORT=27017
# Configuration settings.
export MONGODB_NOPREALLOC=${MONGODB_NOPREALLOC:-true}
if [[ "${MONGODB_NOPREALLOC:-}" == "false" ]]; then
export MONGODB_PREALLOC=${MONGODB_PREALLOC:-true}
else
export MONGODB_PREALLOC=${MONGODB_PREALLOC:-false}
fi
export MONGODB_SMALLFILES=${MONGODB_SMALLFILES:-true}
export MONGODB_QUIET=${MONGODB_QUIET:-true}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
# mongodb.conf
##
## For list of options visit:
## https://docs.mongodb.org/manual/reference/configuration-options/
##

port = ${CONTAINER_PORT}
# systemLog Options - How to do logging
systemLog:
# Runs the mongod in a quiet mode that attempts to limit the amount of output
quiet: ${MONGODB_QUIET}

# Set this value to designate a directory for the mongod instance to store its data.
# Default: /var/lib/mongodb/data
dbpath = ${MONGODB_DATADIR}

# Disable data file preallocation. Default: true
noprealloc = ${MONGODB_NOPREALLOC}
# net Options - Network interfaces settings
net:
# Specify port number (27017 by default)
port: ${CONTAINER_PORT}

# Set MongoDB to use a smaller default data file size. Default: true
smallfiles = ${MONGODB_SMALLFILES}

# Runs MongoDB in a quiet mode that attempts to limit the amount of output.
# Default: true
quiet = ${MONGODB_QUIET}
# storage Options - How and Where to store data
storage:
# Directory for datafiles (defaults to /data/db/)
dbPath: ${MONGODB_DATADIR}

# Disable the HTTP interface (Defaults to localhost:28017).
nohttpinterface = true
mmapv1:
# Enable or disable the preallocation of data files (true by default)
preallocDataFiles: ${MONGODB_PREALLOC}

# Size to use (in MB) for replication op log (default 5% of disk space)
oplogSize = 64
# Use a smaller default file size (false by default)
smallFiles: ${MONGODB_SMALLFILES}


# replication Options - Configures replication
replication:
# Specifies a maximum size in megabytes for the replication operation log (i.e. the oplog,
# 5% of disk space by default)
oplogSizeMB: 64
19 changes: 10 additions & 9 deletions 3.0-upg/test/run
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function test_mongo() {
echo " Testing MongoDB"
if [ -v ADMIN_PASS ]; then
echo " Testing Admin user privileges"
mongo_admin_cmd "db=db.getSiblingDB('${DB}');db.removeUser('${USER}');"
mongo_admin_cmd "db=db.getSiblingDB('${DB}');db.dropUser('${USER}');"
mongo_admin_cmd "db=db.getSiblingDB('${DB}');db.createUser({user:'${USER}',pwd:'${PASS}',roles:['readWrite','userAdmin','dbAdmin']});"
mongo_admin_cmd "db=db.getSiblingDB('${DB}');db.testData.insert({x:0});"
mongo_cmd "db.createUser({user:'test_user2',pwd:'test_password2',roles:['readWrite']});"
Expand All @@ -112,18 +112,18 @@ function test_mongo() {

function test_config_option() {
local env_var=$1 ; shift
local setting=$1 ; shift
local value=$1 ; shift
local env_val=$1 ; shift
local config_part=$1 ; shift

local name="configuration_${setting}"
local name="configuration_${env_var}"

# If $value is a string, it needs to be in simple quotes ''.
DOCKER_ARGS="
-e MONGODB_DATABASE=db
-e MONGODB_USER=user
-e MONGODB_PASSWORD=password
-e MONGODB_ADMIN_PASSWORD=adminPassword
-e $env_var=${value//\'/}
-e $env_var=${env_val}
"
create_container ${name} ${DOCKER_ARGS}

Expand All @@ -135,16 +135,17 @@ function test_config_option() {
test_connection ${name}

# If nothing is found, grep returns 1 and test fails.
docker exec $(get_cid $name) bash -c "cat /etc/mongod.conf" | grep -q "$setting = $value"
docker exec $(get_cid $name) bash -c "cat /etc/mongod.conf" | grep -q "${config_part}"

docker stop $(get_cid ${name})
}

function run_configuration_tests() {
echo " Testing image configuration settings"
test_config_option MONGODB_NOPREALLOC noprealloc true
test_config_option MONGODB_SMALLFILES smallfiles true
test_config_option MONGODB_QUIET quiet true
test_config_option MONGODB_PREALLOC false "preallocDataFiles: false"
test_config_option MONGODB_NOPREALLOC true "preallocDataFiles: false"
test_config_option MONGODB_SMALLFILES true "smallFiles: true"
test_config_option MONGODB_QUIET true "quiet: true"
echo " Success!"
}

Expand Down
35 changes: 23 additions & 12 deletions 3.2/root/usr/share/container-scripts/mongodb/mongodb.conf.template
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
# mongodb.conf
##
## For list of options visit:
## https://docs.mongodb.org/manual/reference/configuration-options/
##

port = ${CONTAINER_PORT}
# systemLog Options - How to do logging
systemLog:
# Runs the mongod in a quiet mode that attempts to limit the amount of output
quiet: ${MONGODB_QUIET}

# Set this value to designate a directory for the mongod instance to store its data.
# Default: /var/lib/mongodb/data
dbpath = ${MONGODB_DATADIR}

# Runs MongoDB in a quiet mode that attempts to limit the amount of output.
# Default: true
quiet = ${MONGODB_QUIET}
# net Options - Network interfaces settings
net:
# Specify port number (27017 by default)
port: ${CONTAINER_PORT}

# Disable the HTTP interface (Defaults to localhost:28017).
nohttpinterface = true

# Size to use (in MB) for replication op log (default 5% of disk space)
oplogSize = 64
# storage Options - How and Where to store data
storage:
# Directory for datafiles (defaults to /data/db/)
dbPath: ${MONGODB_DATADIR}


# replication Options - Configures replication
replication:
# Specifies a maximum size in megabytes for the replication operation log (i.e. the oplog,
# 5% of disk space by default)
oplogSizeMB: 64
12 changes: 6 additions & 6 deletions 3.2/test/run
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,18 @@ function test_mongo() {

function test_config_option() {
local env_var=$1 ; shift
local setting=$1 ; shift
local value=$1 ; shift
local env_val=$1 ; shift
local config_part=$1 ; shift

local name="configuration_${setting}"
local name="configuration_${env_var}"

# If $value is a string, it needs to be in simple quotes ''.
DOCKER_ARGS="
-e MONGODB_DATABASE=db
-e MONGODB_USER=user
-e MONGODB_PASSWORD=password
-e MONGODB_ADMIN_PASSWORD=adminPassword
-e $env_var=${value//\'/}
-e $env_var=${env_val}
"
create_container ${name} ${DOCKER_ARGS}

Expand All @@ -135,14 +135,14 @@ function test_config_option() {
test_connection ${name}

# If nothing is found, grep returns 1 and test fails.
docker exec $(get_cid $name) bash -c "cat /etc/mongod.conf" | grep -q "$setting = $value"
docker exec $(get_cid $name) bash -c "cat /etc/mongod.conf" | grep -q "${config_part}"

docker stop $(get_cid ${name})
}

function run_configuration_tests() {
echo " Testing image configuration settings"
test_config_option MONGODB_QUIET quiet true
test_config_option MONGODB_QUIET true "quiet: true"
echo " Success!"
}

Expand Down

0 comments on commit 12a0b41

Please sign in to comment.