Skip to content

Commit

Permalink
Switch to using docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
gmr committed Feb 26, 2018
1 parent e064762 commit 41a0b1f
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 6 deletions.
17 changes: 11 additions & 6 deletions .travis.yml
@@ -1,4 +1,8 @@
sudo: false
sudo: required

services:
- docker

language: python

env:
Expand All @@ -14,16 +18,15 @@ stages:
- name: deploy
if: tag IS present

before_install:
- curl -L -o /tmp/1.0.6_linux_amd64.zip https://releases.hashicorp.com/consul/1.0.6/consul_1.0.6_linux_amd64.zip
- unzip /tmp/1.0.6_linux_amd64.zip
- ./consul agent -config-file consul-test.json > /tmp/consul.log &

install:
- pip install awscli
- pip install -r requires/testing.txt
- python setup.py develop

before_script:
- ./bootstrap
- source build/test-environment

script: nosetests

after_success:
Expand All @@ -43,6 +46,7 @@ jobs:
python: 3.6
install:
- pip install awscli coverage codecov
before_script: true
script:
- mkdir coverage
- aws s3 cp --recursive s3://com-gavinroy-travis/consulate/$TRAVIS_BUILD_NUMBER/
Expand All @@ -58,6 +62,7 @@ jobs:
python: 3.6
services: []
install: true
before_script: true
script: true
after_success: true
deploy:
Expand Down
90 changes: 90 additions & 0 deletions bootstrap
@@ -0,0 +1,90 @@
#!/bin/bash
#
# NAME
# bootstrap -- initialize/update docker environment
#
# SYNOPSIS
# bootstrap
# bootstrap shellinit
#
# DESCRIPTION
# Execute this script without parameters to build the local docker
# environment. Once bootstrapped, dependent services are running
# via docker-compose and the environment variables are written to
# *build/test-environment* for future use.
#
# Running this script with the _shellinit_ command line parameter
# causes it to simply interrogate the running docker environment,
# update *build/test-environment*, and print the environment to
# the standard output stream in a shell executable manner. This
# makes the following pattern for setting environment variables
# in the current shell work.
#
# prompt% $(./bootstrap shellinit)
#
# vim: set ts=2 sts=2 sw=2 et:
set -e

get_container() {
echo $(echo "${DOCKER_COMPOSE_PREFIX}" | tr -d -- '-.')_$1_1
}

get_ipaddr() {
docker inspect --format '{{ .NetworkSettings.IPAddress }}' $1
}

get_exposed_port() {
docker-compose ${COMPOSE_ARGS} port $1 $2 | cut -d: -f2
}

report_start() {
printf "Waiting for $1 ... "
}

report_done() {
printf "${COLOR_GREEN}done${COLOR_RESET}\n"
}

# Ensure Docker is Running
if test -e /var/run/docker.sock
then
DOCKER_IP=127.0.0.1
else
echo "Docker environment not detected."
exit 1
fi

# Activate the virtual environment
if test -e env/bin/activate
then
. ./env/bin/activate
fi

mkdir -p build

# Common constants
COLOR_RESET='\033[0m'
COLOR_GREEN='\033[0;32m'
PREFIX=${PWD##*/}
DOCKER_COMPOSE_PREFIX=${PREFIX:-${DOCKER_COMPOSE_PREFIX}}
COMPOSE_ARGS="-p ${DOCKER_COMPOSE_PREFIX}"

# Stop any running instances and clean up after them, then pull images
docker-compose ${COMPOSE_ARGS} down --volumes --remove-orphans
docker-compose ${COMPOSE_ARGS} pull
docker-compose ${COMPOSE_ARGS} up -d

# Wait for Consul
CONSUL_PORT=$(get_exposed_port consul 8500)
report_start $(get_container consul)
wait-for -s 2 "http://${DOCKER_IP}:${CONSUL_PORT}/v1/status/leader"
report_done

cat > build/test-environment<<EOF
export ASYNC_TEST_TIMEOUT=20
export DOCKER_COMPOSE_PREFIX=${DOCKER_COMPOSE_PREFIX}
export CONSUL_HOST=${DOCKER_IP}
export CONSUL_PORT=$(get_exposed_port consul 8500)
EOF

printf "\nBootstrap complete\n\nDon't forget to \". build/test-environment\"\n"
8 changes: 8 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,8 @@
%YAML 1.2
---
consul:
image: consul:1.0.6
ports:
- 8500
volumes:
- ./testing:/consul/config

0 comments on commit 41a0b1f

Please sign in to comment.