Skip to content

Commit 32e852f

Browse files
author
Spencer Rinehart
committed
Use fig instead of dockerBuild.php.
dockerBuild.php was a hack I put together just to test out how orchestrating the separate containers would be. Turns out, this is a problem that needs more than a simple hack to solve. The root of the issue comes down to the edge cases where the state of various containers isn't being properly handled: it tries to run containers that already exist in some cases and doesn't run ones that have been stopped in others. Rather than beefing dockerBuild.php out into a larger script to handle all this (complicated!), I took a look around to see what is on offer: * [fig](http://fig.sh) - nice and simple and built to solve this exact problem * [kubernetes](https://github.com/GoogleCloudPlatform/kubernetes) - Potentially useful in a production environment, but a bit overkill for our problem. * [fleet](https://github.com/coreos/fleet) - Very interesting, but the ties to systemd and etcd make it difficult to use in all environments. * [ansible](http://docs.ansible.com/docker_module.html) - A nice chef-esque way of doing things, but requires a lot of extra configuration to manage and feels funny running against localhost. All in all, I couldn't find much out there to really compete with fig for this usecase although I'm sure some other small attempts exist. fig is a python-based command, but it is distributed as a linux binary, so python doesn't really come into play. It takes 30 seconds to setup and has a very intuitive CLI (coming from Docker) with decent documentation via `fig help <command>` and via its website. Implementing the switch is fairly straightforward. Take the primary docker run line and extract the links and volumes into the fig.yml configuration as given. Create a "build" image that is the primary build for the package. Additional services can also be added (mongo, redis, etc.) and because they are linked to the "build" image, they will be started first before the build container is run. The set-env.sh change is related to a small difference in how fig names its containers compared to how dockerBuild.php does. It takes a more convention-driven approach that allows for multiple copies of a single service and doesn't provide configuration for overriding its service names (that I can tell).
1 parent fdeff23 commit 32e852f

3 files changed

Lines changed: 11 additions & 32 deletions

File tree

dockerBuild.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

fig.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build:
2+
build: .
3+
links:
4+
- mongo
5+
volumes:
6+
- .:/code
7+
mongo:
8+
image: mongo

provisioning/set-env.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/bin/bash
2-
if test -z "${MONGO_PORT_27017_TCP_ADDR}" -o -z "${MONGO_PORT_27017_TCP_PORT}"; then
2+
if test -z "${MONGO_1_PORT_27017_TCP_ADDR}" -o -z "${MONGO_1_PORT_27017_TCP_PORT}"; then
33
echo "You must link this container with mongo first"
44
exit 1
55
fi
66

7-
export TESTING_MONGO_URL="mongodb://${MONGO_PORT_27017_TCP_ADDR}:${MONGO_PORT_27017_TCP_PORT}"
7+
export TESTING_MONGO_URL="mongodb://${MONGO_1_PORT_27017_TCP_ADDR}:${MONGO_1_PORT_27017_TCP_PORT}"
88

99
# See http://tldp.org/LDP/abs/html/devref1.html for description of this syntax.
10-
while ! exec 6<>/dev/tcp/${MONGO_PORT_27017_TCP_ADDR}/${MONGO_PORT_27017_TCP_PORT}; do
10+
while ! exec 6<>/dev/tcp/${MONGO_1_PORT_27017_TCP_ADDR}/${MONGO_1_PORT_27017_TCP_PORT}; do
1111
echo "$(date) - still trying to connect to mongo at ${TESTING_MONGO_URL}"
1212
sleep 1
1313
done

0 commit comments

Comments
 (0)