Skip to content

Instantly share code, notes, and snippets.

@dblandin
Last active April 3, 2017 01:44
Show Gist options
  • Save dblandin/8317726a5bcccd6f898e5332ed2d9bcd to your computer and use it in GitHub Desktop.
Save dblandin/8317726a5bcccd6f898e5332ed2d9bcd to your computer and use it in GitHub Desktop.
Code Climate's Harness (bootstrapping a local dev environment)

Harness

Run and manage a complete local instance of Example.

Getting Started

  1. Have all projects cloned as sibling directories:
~/code/example/
  api/
  app/
  service1/
  service2/
  service3/
  1. Run bin/setup

Usage

docker-compose up -d
docker-compose ps
docker-compose logs -f

$BROWSER http://localhost:3000

How Do I...

Get reasonable performance on OS X

Docker for Mac suffers from very poor performance with mounted OS X filesystems, so we provide a configuration for docker-sync we suggest using.

To install dependencies:

gem install docker-sync
brew install fswatch

To run:

  1. Run docker-sync start to start sync volume.
  2. Use docker-compose --file docker-compose.yml --file docker-compose.docker-sync.yml up -d when bringing up services. (You may want to create a local alias for docker-compose --file docker-compose.yml --file docker-compose.docker-sync.yml to simplify frequent commands.)
# This is an "abstract" app service definition. It should not be run directly,
# but is extended into the various app services in the main docker-compose.yml
version: "2"
services:
app:
image: example/app-development
build:
context: ../app
dockerfile: Dockerfile.development
volumes:
- ../app:/app
environment:
APP_API_URL: http://api:4000/v1/
APP_ASSET_HOST: http://localhost:3000
APP_CANONICAL_URL: http://localhost:3000
APP_KAFKA_BROKERS: kafka:9092
APP_MONGODB_URL: mongodb://mongodb/example_development
APP_REDIS_URL: redis://redis:6379/0
version: "2"
services:
app:
volumes:
- app-rsync-sync:/app:rw
volumes:
app-rsync-sync:
external: true
version: "2"
volumes:
kafka:
mongodb:
redis:
zookeeper:
services:
app:
extends:
file: app.yml
service: app
command:
- nginx
ports:
- 3000:80
depends_on:
- memcached
- mongodb
- redis
links:
- api
app-resque:
extends:
file: app.yml
service: app
command:
- bundle
- exec
- rake
- environment
- resque:work
depends_on:
- memcached
- mongodb
- redis
api:
image: example/api
build: ../api
command:
- passenger
- start
- --port=4000
ports:
- 4000:4000
depends_on:
- mongodb
- redis
environment:
API_APP_REDIS_URL: redis://redis:6379/0
API_CANONICAL_URL: http://localhost:4000
API_KAFKA_BROKERS: kafka:9092
API_MEMCACHE_URL: memcached://memcached:11211
API_MONGODB_URL: mongodb://mongodb/example_development
API_WEB_HOST: http://localhost:3000
service1:
image: example/service1
build: ../scheduler
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
SERVICE1_DEBUG: 1
SERVICE1_DOCKER_URL: unix:///var/run/docker.sock
SERVICE1_KAFKA_BROKERS: kafka:9092
SERVICE1_MONGODB_URL: mongodb://mongodb/example_development
SERVICE1_REDIS_URL: redis://redis:6379/0
depends_on:
- kafka
- mongodb
- redis
service2:
image: example/service2
build: ../service2
environment:
SERVICE2_DEBUG: 1
SERVICE2_KAFKA_BROKERS: kafka:9092
SERVICE2_MONGODB_URL: mongodb://mongodb/example_development
SERVICE2_REDIS_URL: redis://redis:6379/0
depends_on:
- kafka
- mongodb
service3:
image: example/service3
build: ../service3
environment:
SERVICE3_APP_REDIS_URL: redis://redis:6379/0
SERVICE3_DEBUG: 1
SERVICE3_KAFKA_BROKERS: kafka:9092
SERVICE3_KAFKA_PARTITION: 0
SERVICE3_KAFKA_TOPIC: some-topic
SERVICE3_MONGODB_URL: mongodb://mongodb/example_development
depends_on:
- kafka
- mongodb
redis:
image: redis:2.8
command:
- redis-server
- --appendonly
- "yes"
volumes:
- redis:/data
memcached:
image: memcached
mongodb:
image: percona/percona-server-mongodb:3.2
command:
- --smallfiles
- --storageEngine=wiredTiger
volumes:
- mongodb:/data/db
kafka:
image: wurstmeister/kafka:0.9.0.1
volumes:
- kafka:/kafka
environment:
KAFKA_ADVERTISED_HOST_NAME: kafka
KAFKA_ADVERTISED_PORT: 9092
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "false"
KAFKA_BROKER_ID: 100
KAFKA_CREATE_TOPICS: some-topic:1:1
KAFKA_LOG_DIRS: /kafka/kafka-logs-100
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
depends_on:
- zookeeper
zookeeper:
image: jplock/zookeeper:3.4.6
volumes:
- zookeeper:/tmp/zookeeper
version: 2
syncs:
app-rsync-sync:
src: ../app
dest: /app
sync_host_port: 10872
sync_excludes:
- .git
- tmp
- log
options:
compose-dev-file-path: 'docker-compose.docker-sync.yml'
#!/bin/sh
set -e
echo "*===============================*"
echo "* Cloning projects if needed... *"
echo "*===============================*"
for project in api app service1 service2 service3; do
if [ ! -e ../"$project" ]; then
git clone git@github.com:example/"$project" ../"$project"
fi
done
echo "*============================*"
echo "* Building project images... *"
echo "*============================*"
docker-compose build
echo "*==============================*"
echo "* Initializing the database... *"
echo "*==============================*"
docker-compose run --rm app \
bundle exec rake db:indexes:load db:seed db:migrate
echo "*=================================================*"
echo "* Setup complete *"
echo "* Some services were started already, *"
echo "* start the rest in the way you normally would. *"
echo "*=================================================*"
docker-compose ps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment