Skip to content

Commit a862b1d

Browse files
authored
Merge pull request #1 from autopilotpattern/wip
Initial WIP merge.
2 parents 70fee6d + 5e052fb commit a862b1d

File tree

8 files changed

+630
-2
lines changed

8 files changed

+630
-2
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
**/.DS_Store
3+
_env*

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# build outputs
2+
*.pyc
3+
4+
# credentials
5+
_env*
6+
manta
7+
manta.pub
8+
9+
# temp
10+
python-manta/
11+
12+
# macos frustration
13+
.DS_Store

Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM mongo:3.2
2+
3+
RUN apt-get update \
4+
&& apt-get install -y \
5+
python \
6+
python-dev \
7+
gcc \
8+
curl \
9+
libffi-dev \
10+
libssl-dev \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
# get Python drivers MongoDB, Consul, and Manta
14+
RUN curl -Ls -o get-pip.py https://bootstrap.pypa.io/get-pip.py && \
15+
python get-pip.py && \
16+
pip install \
17+
PyMongo==3.2.2 \
18+
python-Consul==0.4.7 \
19+
manta==2.5.0 \
20+
mock==2.0.0
21+
22+
# Add ContainerPilot and set its configuration file path
23+
ENV CONTAINERPILOT_VER 2.0.1
24+
ENV CONTAINERPILOT file:///etc/containerpilot.json
25+
RUN export CONTAINERPILOT_CHECKSUM=a4dd6bc001c82210b5c33ec2aa82d7ce83245154 \
26+
&& curl -Lso /tmp/containerpilot.tar.gz \
27+
"https://github.com/joyent/containerpilot/releases/download/${CONTAINERPILOT_VER}/containerpilot-${CONTAINERPILOT_VER}.tar.gz" \
28+
&& echo "${CONTAINERPILOT_CHECKSUM} /tmp/containerpilot.tar.gz" | sha1sum -c \
29+
&& tar zxf /tmp/containerpilot.tar.gz -C /usr/local/bin \
30+
&& rm /tmp/containerpilot.tar.gz
31+
32+
# add stopping timeouts for MongoDB
33+
ENV MONGO_SECONDARY_CATCHUP_PERIOD 8
34+
ENV MONGO_STEPDOWN_TIME 60
35+
ENV MONGO_ELECTION_TIMEOUT 30
36+
37+
# configure ContainerPilot and MySQL
38+
COPY etc/* /etc/
39+
COPY bin/* /usr/local/bin/
40+
41+
# override the parent entrypoint
42+
ENTRYPOINT []
43+
44+
CMD [ \
45+
"containerpilot", \
46+
"mongod", \
47+
"--replSet=joyent" \
48+
]
49+

README.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,44 @@
1-
# mongodb
2-
Work in progress, not stable, expect force pushes of this repo
1+
# AutoPilot Pattern MongoDB
2+
3+
*A robust and highly-scalable implementation of MongoDB in Docker using the Autopilot Pattern*
4+
5+
## Architecture
6+
7+
A running cluster includes the following components:
8+
- [ContainerPilot](https://www.joyent.com/containerpilot): included in our MongoDB containers to orchestrate bootstrap behavior and coordinate replica joining using keys and checks stored in Consul in the `health`, and `onChange` handlers
9+
- [MongoDB](https://www.mongodb.com/community): we're using MongoDB 3.2 and setting up a [replica set](https://docs.mongodb.com/manual/replication/)
10+
- [Consul](https://www.consul.io/): used to coordinate replication and failover
11+
12+
## Running the cluster
13+
14+
Starting a new cluster is easy once you have [your `_env` file set with the configuration details](#configuration)
15+
16+
- for Triton, just run `docker-compose up -d`
17+
- for non-Triton, just run `docker-compose up -f local-compose.yml -d`
18+
19+
In a few moments you'll have a running MongoDB ready for a replica set. Both the master and replicas are described as a single `docker-compose` service. During startup, [ContainerPilot](http://containerpilot.io) will ask Consul if an existing master has been created. If not, the node will initialize as a new MongoDB replica set and all future nodes will be added to the replica set by the current master. All master election is handled by [MongoDB itself](https://docs.mongodb.com/manual/core/replica-set-elections/) and the result is cached in Consul.
20+
21+
**Run `docker-compose -f local-compose.yml scale mongodb=2` to add a replica (or more than one!)**. The replicas will automatically be added to the replica set on the master and will register themselves in Consul as replicas once they're ready.
22+
23+
### Configuration
24+
25+
Pass these variables via an `_env` file.
26+
27+
- `LOG_LEVEL`: control the amount of logging from ContainerPilot
28+
- when the primary node is sent a `SIGTERM` it will [step down](https://docs.mongodb.com/manual/reference/command/replSetStepDown/) as primary; the following control those timeouts
29+
- `MONGO_SECONDARY_CATCHUP_PERIOD`: the number of seconds that the mongod will wait for an electable secondary to catch up to the primary
30+
- `MONGO_STEPDOWN_TIME`: the number of seconds to step down the primary, during which time the stepdown member is ineligible for becoming primary
31+
- `MONGO_ELECTION_TIMEOUT`: after the primary steps down, the amount a tries to check that a new primary has been elected before the node shuts down
32+
33+
Not yet implemented:
34+
- `MANTA_URL`: the full Manta endpoint URL. (ex. `https://us-east.manta.joyent.com`)
35+
- `MANTA_USER`: the Manta account name.
36+
- `MANTA_SUBUSER`: the Manta subuser account name, if any.
37+
- `MANTA_ROLE`: the Manta role name, if any.
38+
- `MANTA_KEY_ID`: the MD5-format ssh key id for the Manta account/subuser (ex. `1a:b8:30:2e:57:ce:59:1d:16:f6:19:97:f2:60:2b:3d`); the included `setup.sh` will encode this automatically
39+
- `MANTA_PRIVATE_KEY`: the private ssh key for the Manta account/subuser; the included `setup.sh` will encode this automatically
40+
- `MANTA_BUCKET`: the path on Manta where backups will be stored. (ex. `/myaccount/stor/triton-mysql`); the bucket must already exist and be writeable by the `MANTA_USER`/`MANTA_PRIVATE_KEY`
41+
42+
### Sponsors
43+
44+
Initial development of this project was sponsored by [Joyent](https://www.joyent.com).

0 commit comments

Comments
 (0)