From 067568ade262b00c18938b1ed0fb47b9d876132e Mon Sep 17 00:00:00 2001 From: Robert Dickinson Date: Sun, 5 Feb 2017 02:23:00 -0800 Subject: [PATCH] New deployment mechanism for Triton --- .env | 2 +- Makefile | 26 +++++++++- common-services.yml | 68 +++++++++++++++++++++++++ docker-compose.yml | 119 ++++++++++++++------------------------------ setup.sh | 16 ++++-- triton-compose.yml | 67 +++++++++++++++++++++++++ 6 files changed, 208 insertions(+), 90 deletions(-) create mode 100644 common-services.yml mode change 100644 => 100755 setup.sh create mode 100644 triton-compose.yml diff --git a/.env b/.env index cb86b19..b6e519b 100644 --- a/.env +++ b/.env @@ -4,4 +4,4 @@ # # See: https://docs.docker.com/compose/env-file/ # -CONSUL=consul +COMPOSE_PROJECT_NAME=synchro diff --git a/Makefile b/Makefile index 9117b57..7d5352f 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,29 @@ +MAKEFLAGS += --warn-undefined-variables +SHELL := /bin/bash +.SHELLFLAGS := -eu -o pipefail +.DEFAULT_GOAL := build + # Build the docker images # -build: +build: build-nginx build-synchro build-stashbox build-redis + +build-nginx: docker build -t synchro/synchro_nginx_ap nginx + +build-synchro: docker build -t synchro/synchro_ap synchro + +build-stashbox: + docker build -t synchro/stashbox_ap stashbox + +build-redis: + docker build -t synchro/synchro_redis_ap redis + +triton.env: + ./setup.sh + +# Start the composition on Triton +runtriton: triton.env + $(eval include triton.env) + $(eval export $(shell sed 's/=.*//' triton.env)) + docker-compose -f triton-compose.yml up diff --git a/common-services.yml b/common-services.yml new file mode 100644 index 0000000..1793bab --- /dev/null +++ b/common-services.yml @@ -0,0 +1,68 @@ +# Nginx as a load-balancing tier and reverse proxy, with caching and optional SSL termination +nginx: + image: synchro/synchro_nginx_ap:1.0.2 + mem_limit: 128m + command: > + /bin/containerpilot + -config file:///etc/containerpilot/containerpilot.json + nginx -g "daemon off;" + restart: always + ports: + - 80 + - 443 + expose: + - 9090 + +# The Synchro microservice +synchro: + image: synchro/synchro_ap:1.5.14 + mem_limit: 512m + restart: always + expose: + - 80 + - 9090 + environment: + - SYNCHRO_CONFIG_URL=stashbox/config/config.json + - SYNCHRO__PORT=80 + - SYNCHRO__SESSIONSTORE_PACKAGE=synchro-api + - SYNCHRO__SESSIONSTORE_SERVICE=IoRedisSessionStore + - SYNCHRO__SESSIONSTORE__sentinels=true + - SYNCHRO__SESSIONSTORE__consulRetries=5 + - SYNCHRO__SESSIONSTORE__consulDelayMs=5000 + - SYNCHRO__LOG4JS_CONFIG__levels__synchro-ioredis-session=DEBUG + +# StashBox +stashbox: + image: synchro/stashbox_ap:1.1.3 + mem_limit: 128m + expose: + - 80 + +# redis +redis: + image: synchro/synchro_redis_ap:1.0.0 + mem_limit: 128m + restart: always + expose: + - 6379 + - 26379 + +# service discovery tier +consul: + image: progrium/consul:latest + mem_limit: 128m + command: -server -bootstrap -ui-dir /ui + restart: always + expose: + - 8500 + dns: + - 127.0.0.1 + +# Prometheus is an open source performance monitoring tool +# it is included here for demo purposes and is not required +prometheus: + image: autopilotpattern/prometheus:latest + mem_limit: 1g + restart: always + ports: + - 9090 diff --git a/docker-compose.yml b/docker-compose.yml index f6e2dc0..b424472 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,106 +1,59 @@ -# By default, the value of CONSUL will come from the .env file in this directory and will direct the -# services below to use the single consul instance directly. If you want to scale consul you should -# specify CONSUL_AGENT (with a truthy value) and you will also likely want to set the value of CONSUL -# to an appropriate host (for example, when deploying on Joyent, you would want to set it to a host name -# that Joyent CNS will resolve - see setup.sh in this directory). +# docker-compose.yml - Run services on local host # # Nginx as a load-balancing tier and reverse proxy, with caching and optional SSL termination nginx: - image: synchro/synchro_nginx_ap:1.0.2 - mem_limit: 128m - command: > - /bin/containerpilot - -config file:///etc/containerpilot/containerpilot.json - nginx -g "daemon off;" - restart: always - links: - - consul - - stashbox + extends: + file: common-services.yml + service: nginx ports: - - 80 - - 443 - - 9090 - labels: - # Joyent: Setting the CNS service name (not needed unless running on Joyent and using CNS) - - triton.cns.services=synchro + - 8080:80 + links: + - consul + - stashbox environment: - - CONSUL=${CONSUL} - - CONSUL_AGENT=${CONSUL_AGENT} + - CONSUL=consul # The Synchro microservice synchro: - image: synchro/synchro_ap:1.5.14 - mem_limit: 512m - restart: always + extends: + file: common-services.yml + service: synchro links: - - redis - - consul - - stashbox - expose: - - 80 - ports: - - 9090 + - redis + - consul + - stashbox environment: - - SYNCHRO_CONFIG_URL=stashbox/config/config.json - - SYNCHRO__PORT=80 - - SYNCHRO__SESSIONSTORE_PACKAGE=synchro-api - - SYNCHRO__SESSIONSTORE_SERVICE=IoRedisSessionStore - - SYNCHRO__SESSIONSTORE__sentinels=true - - SYNCHRO__SESSIONSTORE__consulRetries=5 - - SYNCHRO__SESSIONSTORE__consulDelayMs=5000 - - SYNCHRO__LOG4JS_CONFIG__levels__synchro-ioredis-session=DEBUG - - CONSUL=${CONSUL} - - CONSUL_AGENT=${CONSUL_AGENT} + - CONSUL=consul # StashBox stashbox: - image: synchro/stashbox_ap:1.1.3 - mem_limit: 128m - expose: - - 80 + extends: + file: common-services.yml + service: stashbox # redis redis: - image: synchro/synchro_redis_ap:1.0.0 - mem_limit: 128m - restart: always + extends: + file: common-services.yml + service: redis links: - - consul - expose: - - 6379 - - 26379 - labels: - - triton.cns.services=redis + - consul environment: - - CONSUL=${CONSUL} - - CONSUL_AGENT=${CONSUL_AGENT} - -# service discovery tier -consul: - image: progrium/consul:latest - mem_limit: 128m - command: -server -bootstrap -ui-dir /ui - restart: always - expose: - - 8500 - dns: - - 127.0.0.1 - labels: - - triton.cns.services=consul + - CONSUL=consul -# Prometheus is an open source performance monitoring tool -# it is included here for demo purposes and is not required +# Prometheus performance monitoring prometheus: - image: autopilotpattern/prometheus:latest - mem_limit: 1g - restart: always + extends: + file: common-services.yml + service: prometheus links: - - consul - ports: - - 9090 - labels: - - triton.cns.services=prometheus + - consul environment: - - CONSUL=${CONSUL} - - CONSUL_AGENT=${CONSUL_AGENT} + - CONSUL=consul + +# service discovery tier +consul: + extends: + file: common-services.yml + service: consul diff --git a/setup.sh b/setup.sh old mode 100644 new mode 100755 index a0760d5..f9603cb --- a/setup.sh +++ b/setup.sh @@ -12,9 +12,8 @@ help() { echo ' -p use this name as the project prefix for docker-compose' } - # default values which can be overriden by -f or -p flags -export COMPOSE_PROJECT_NAME=nginx +export COMPOSE_PROJECT_NAME=synchro export COMPOSE_FILE= # give the docker remote api more time before timeout @@ -97,8 +96,15 @@ check() { exit 1 fi - echo CONSUL=consul.svc.${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com > .env - echo CONSUL_AGENT=1 > .env + # Create and populate docker-compose .env file (this will overwrite any existing .env file) + echo '# Environment variables for Triton' > triton.env + + echo "COMPOSE_PROJECT_NAME=${COMPOSE_PROJECT_NAME}" >> triton.env + echo "TRITON_USER=${TRITON_USER}" >> triton.env + echo "TRITON_DC=${TRITON_DC}" >> triton.env + echo "TRITON_ACCOUNT=${TRITON_ACCOUNT}" >> triton.env + + echo >> triton.env } # --------------------------------------------------- @@ -127,4 +133,4 @@ do done # default behavior -check \ No newline at end of file +check diff --git a/triton-compose.yml b/triton-compose.yml new file mode 100644 index 0000000..c62175d --- /dev/null +++ b/triton-compose.yml @@ -0,0 +1,67 @@ +# triton-compose.yml - Run services on Triton +# + +# Nginx as a load-balancing tier and reverse proxy, with caching and optional SSL termination +nginx: + extends: + file: common-services.yml + service: nginx + links: + - consul + - stashbox + labels: + - triton.cns.services=${COMPOSE_PROJECT_NAME} + environment: + - CONSUL_AGENT=1 + - CONSUL=consul-${COMPOSE_PROJECT_NAME}.svc.${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com + +# The Synchro microservice +synchro: + extends: + file: common-services.yml + service: synchro + links: + - redis + - consul + - stashbox + environment: + - CONSUL_AGENT=1 + - CONSUL=consul-${COMPOSE_PROJECT_NAME}.svc.${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com + +# StashBox +stashbox: + extends: + file: common-services.yml + service: stashbox + +# redis +redis: + extends: + file: common-services.yml + service: redis + links: + - consul + environment: + - CONSUL_AGENT=1 + - CONSUL=consul-${COMPOSE_PROJECT_NAME}.svc.${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com + +# Prometheus performance monitoring +prometheus: + extends: + file: common-services.yml + service: prometheus + links: + - consul + labels: + - triton.cns.services=prometheus-${COMPOSE_PROJECT_NAME} + environment: + - CONSUL_AGENT=1 + - CONSUL=consul-${COMPOSE_PROJECT_NAME}.svc.${TRITON_ACCOUNT}.${TRITON_DC}.cns.joyent.com + +# service discovery tier +consul: + extends: + file: common-services.yml + service: consul + labels: + - triton.cns.services=consul-${COMPOSE_PROJECT_NAME}