Skip to content

Instantly share code, notes, and snippets.

@anfernee
Last active January 28, 2016 17:28
Show Gist options
  • Select an option

  • Save anfernee/e9cb1e4b6f647cdddad9 to your computer and use it in GitHub Desktop.

Select an option

Save anfernee/e9cb1e4b6f647cdddad9 to your computer and use it in GitHub Desktop.
cell "mongodb" {
name = "MongoDB Cell"
version = "1.0"
# Shameless borrow the term from hashicorp team. Or we use process group.
molecule "mongos" {
name = "MongoDB sharding"
scalable = true # Means user is able to scale the molecule up/down
requires = ["config"] # Define the molecule has be provisioned before this been provisioned
var {
# Default variable, when user doesn't specify port
port = 11111
}
provision {
driver = "docker" # Or ansible, join/exec
# Docker image
image = "mongo"
version = "3.2.1"
# Support jinja2 template
args = "mongos --configdb configReplSet/{{ config.endpoints|join(',') }}"
env {
PORT = "{{ this.port }}"
}
}
}
molecule "config" {
name = "MongoDB config server"
scalable = true
vm-affinity = anti # or affinity, tell the scheduler to put the same instance of molecues on the same vm or not.
volume-affinity = unique # unique means Use a volume exclusively
var {
# Default variable, when user doesn't specify port
port = 27017
}
provision {
driver = "docker"
# Docker image
image = "mongo"
version = "3.2.1"
args = "mongod --configsvr --replSet configReplSet --port {{ this.port }} --dbpath {{ this.volume }}"
env {
}
# Post config runs inside of the docker task as 'docker exec'
post_interval = "10s" # Wait 10s to run post config command
post_provision = <<-EOF
mongo localhost --eval '
rs.initiate( {
_id: "configReplSet",
configsvr: true,
members: [
<% for endpoint in this.endpoints %}
{ _id: id, host: "{{{ endpoint }}}" },
<% endfor %>
]
})
'
EOF
}
}
molecule "shard" {
name = "MongoDB replica_set as a shard"
var {
# Default variable, when user doesn't specify port
port = 27017
}
config {
driver = "docker"
# Cell name
image = "mongo"
version = "3.2.1"
args = "mongod --replSet rs0"
env {
}
# Post config runs inside of the docker task as 'docker exec'
post_interval = "10s" # Wait 10s to run post config command
post_config = <<-EOF
mongo localhost --eval '
rs.initiate();
rs.add( {{ this.host }} );
'
EOF
}
}
}
{
"cell": "mongodb",
"version": "1.0",
"molecules": {
"mongos": {
"count": 3
},
"shard": {
"count": 3,
"spec": {
"replica": 3,
"subnet": "xx"
}
},
"config": {
"count": 3
}
},
"provider": {
"_comment": "What's the volume and network story? Allow user to specify?",
"driver": "aws",
"spec": {
"region": "us",
"datacentor": ["us-west-1"],
"type": "m2.xlarge"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment