From fe5b7ffc5ce99d07ee7046072326ffe28a6d8c4c Mon Sep 17 00:00:00 2001 From: Tom Gallacher Date: Fri, 14 Oct 2016 11:57:26 +0100 Subject: [PATCH] Adding ContainerPilot skeleton. --- .gitignore | 50 +++++++++++++++++++++++++++ Makefile | 6 ++++ bin/setup.sh | 85 ++++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 20 +++++++++++ local-compose.yml | 6 ++++ 5 files changed, 167 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100755 bin/setup.sh create mode 100644 docker-compose.yml create mode 100644 local-compose.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..7f3fff9f --- /dev/null +++ b/.gitignore @@ -0,0 +1,50 @@ +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Vim files: +*.sw* + +# Mac OS dirty files +.DS_Store diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..3fb41dd0 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +SHELL := /bin/bash +.SHELLFLAGS := -eu -o pipefail +.PHONY: check + +check: + @./bin/setup.sh diff --git a/bin/setup.sh b/bin/setup.sh new file mode 100755 index 00000000..3a758055 --- /dev/null +++ b/bin/setup.sh @@ -0,0 +1,85 @@ +#! /usr/bin/env bash + +# setup.sh - Checks that all the required tools are present and that they are +# appropriately configured for deploying to Triton. +# +# Adapted from https://github.com/autopilotpattern/mysql/blob/master/setup.sh +# + +# +# Prelude +# +set -euo pipefail +IFS=$'\n\t' + +# +# Utilities +# +die() { + local msg="$@" + [[ -z "${msg}" ]] || { + echo + tput setaf 1 # red + tput bold + echo "${msg}" + tput sgr0 # reset + } + exit 1 +} + +# +# Check functions +# +ensure_command() { + local cmd="$1" + + command -v "${cmd}" > /dev/null 2>&1 || { + die "Couldn't find required command: ${cmd}" + } +} + +ensure_docker_config_matches_triton_config_and_capture_triton_details() { + local docker_user=$(docker info 2>&1 | awk -F": " '/SDCAccount:/{print $2}') + local docker_dc=$(echo $DOCKER_HOST | awk -F"/" '{print $3}' | awk -F'.' '{print $1}') + TRITON_USER=$(triton profile get | awk -F": " '/account:/{print $2}') + TRITON_DC=$(triton profile get | awk -F"/" '/url:/{print $3}' | awk -F'.' '{print $1}') + TRITON_ACCOUNT=$(triton account get | awk -F": " '/id:/{print $2}') + if [[ ! "$docker_user" = "$TRITON_USER" ]] || [[ ! "$docker_dc" = "$TRITON_DC" ]]; then + echo "Docker user: ${docker_user}" + echo "Triton user: ${TRITON_USER}" + echo "Docker data center: ${docker_dc}" + echo "Triton data center: ${TRITON_DC}" + die "Your Triton configuration does not match your Docker configuration." + fi +} + +ensure_triton_cns_is_enabled() { + local triton_cns_enabled=$(triton account get | awk -F": " '/cns/{print $2}') + [[ "$triton_cns_enabled" == "true" ]] || { + die "Triton CNS is required and not enabled." + } +} + +write_env_file() { + [[ -f .env ]] || { + echo '# Consul discovery via Triton CNS' >> .env + echo CONSUL=consul.svc.${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com >> .env + echo MONGO_URL=mongodb://mongo.svc.${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com:27017/rocketchat >> .env + echo ROOT_URL=http://rocketchat.svc.${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com:3000/ >> .env + echo >> .env + } +} + +ensure_prerequisites() { + ensure_command docker + ensure_command docker-compose + ensure_command triton +} + +# +# Main +# +ensure_prerequisites +ensure_docker_config_matches_triton_config_and_capture_triton_details +ensure_triton_cns_is_enabled +write_env_file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..61a2ecd0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +############################################################################# +# CONSUL +############################################################################# +consul: + image: progrium/consul:latest + labels: + - triton.cns.services=consul + restart: always + mem_limit: 128m + expose: + - 53 + - 8300 + - 8301 + - 8302 + - 8400 + - 8500 + env_file: .env + ports: + - 8500:8500 + command: -server -bootstrap -ui-dir /ui diff --git a/local-compose.yml b/local-compose.yml new file mode 100644 index 00000000..fd1cb89e --- /dev/null +++ b/local-compose.yml @@ -0,0 +1,6 @@ +consul: + extends: + file: docker-compose.yml + service: consul + ports: + - 8500:8500