Skip to content

Commit

Permalink
OLMIS-982: Change nginx image, introduce consul-template to query con…
Browse files Browse the repository at this point in the history
…sul over time
  • Loading branch information
pnaw94 committed Nov 18, 2016
1 parent 3a883f5 commit 2b0dcb0
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 256 deletions.
Binary file added consul-template
Binary file not shown.
76 changes: 45 additions & 31 deletions docker-compose.yml
@@ -1,6 +1,7 @@
version: "2"
services:

# Basic environment
consul:
command: -server -bootstrap
image: gliderlabs/consul-server
Expand All @@ -9,6 +10,8 @@ services:
- "8400"
- "8500:8500"
- "53"
environment:
SERVICE_IGNORE: "true"

This comment has been minimized.

Copy link
@pnaw94

pnaw94 Nov 18, 2016

Author

Those variables are used by Registrator (tracking this service isn't necessary, as consul always has itself included in service list, so this would be a duplicate record).


registrator:
image: gliderlabs/registrator
Expand All @@ -17,71 +20,82 @@ services:
- /var/run/docker.sock:/tmp/docker.sock
depends_on: [consul]

requisition-refui:
image: openlmis/requisition-refui:3.0.0-SNAPSHOT
nginx:
image: nginx
ports:
- "80:80"
env_file: .env
environment:
# Changing the virtual location affects loading of the assets on UI. Handle with care.
- VIRTUAL_LOCATION=public
command:
- /home/run.sh
volumes:
- ./consul-template:/usr/bin/consul-template
- ./nginx.conf:/etc/consul-template/conf/nginx.conf
- ./run.sh:/home/run.sh
depends_on: [consul]

# OpenLMIS services
db:
image: openlmis/postgres
env_file: .env
depends_on: [consul]

log:
image: openlmis/rsyslog
volumes:
- '../logs/requisition:/var/log'
depends_on: [consul]

requisition:
image: openlmis/requisition:3.0.0-SNAPSHOT
env_file: .env
environment:
VIRTUAL_LOCATION: requisition
SERVICE_NAME: requisition
SERVICE_TAGS: openlmis-service
JAVA_OPTS: '-Dlogging.config=/logback.xml -Dspring.jpa.properties.hibernate.hbm2ddl.import_files=/bootstrap.sql,file:///demo-data/data.sql'
volumes:
- './logback.xml:/logback.xml'
depends_on: [log]
depends_on: [db, log]

referencedata:
image: openlmis/referencedata:3.0.0-SNAPSHOT
env_file: .env
environment:
VIRTUAL_LOCATION: referencedata
SERVICE_NAME: referencedata
SERVICE_TAGS: openlmis-service
JAVA_OPTS: '-Dlogging.config=/logback.xml -Dspring.jpa.properties.hibernate.hbm2ddl.import_files=/bootstrap.sql,file:///demo-data/data.sql'
volumes:
- './logback.xml:/logback.xml'
depends_on: [log]
depends_on: [db, log]

auth:
image: openlmis/auth:3.0.0-SNAPSHOT
env_file: .env
environment:
VIRTUAL_LOCATION: auth
SERVICE_NAME: auth
SERVICE_TAGS: openlmis-service
JAVA_OPTS: '-Dlogging.config=/logback.xml -Dspring.jpa.properties.hibernate.hbm2ddl.import_files=/bootstrap.sql,file:///demo-data/data.sql'
volumes:
- './logback.xml:/logback.xml'
depends_on: [log]
depends_on: [db, log]

notification:
image: openlmis/notification:3.0.0-SNAPSHOT
env_file: .env
environment:
VIRTUAL_LOCATION: notification
SERVICE_NAME: notification
SERVICE_TAGS: openlmis-service
JAVA_OPTS: '-Dlogging.config=/logback.xml'
volumes:
- './logback.xml:/logback.xml'
depends_on: [log]
depends_on: [db, log]

db:
image: openlmis/postgres
requisition-refui:
image: openlmis/requisition-refui:3.0.0-SNAPSHOT
env_file: .env
depends_on: [consul]

log:
image: openlmis/rsyslog
volumes:
- '../logs/requisition:/var/log'
depends_on: [consul]
environment:
# Changing the virtual location affects loading of the assets on UI. Handle with care.
SERVICE_80_NAME: public
SERVICE_443_NAME: secured
SERVICE_TAGS: openlmis-service
depends_on: [requisition]

nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./nginx.tmpl:/app/nginx.tmpl:ro
depends_on: [consul]
25 changes: 25 additions & 0 deletions nginx.conf
@@ -0,0 +1,25 @@
{{- $loaded_services := services -}}

{{ range $loaded_services -}}
{{ if in .Tags "openlmis-service" }}
upstream {{ .Name }} {
least_conn;
{{ range service .Name }}server {{ .Address }}:{{ .Port }};
{{ end }}
}
{{ end }}
{{- end }}

server {
listen 80;
server_name {{ env "VIRTUAL_HOST" }};
{{ range $loaded_services -}}
{{ if in .Tags "openlmis-service" }}
{{ $location := .Name }}
location /{{ $location }}/ {
rewrite /{{ $location }}(.*)$ $1 break;
proxy_pass http://{{ $location }};
}
{{ end }}
{{- end }}
}
225 changes: 0 additions & 225 deletions nginx.tmpl

This file was deleted.

14 changes: 14 additions & 0 deletions run.sh
@@ -0,0 +1,14 @@
#!/bin/sh

# Run consul-template in background
INPUT_FILE="/etc/consul-template/conf/nginx.conf"
OUTPUT_FILE="/etc/nginx/conf.d/default.conf"
CALLBACK="/etc/init.d/nginx reload"

consul-template \
-consul "${CONSUL_HOST:=consul}:8500" \
-template "$INPUT_FILE:$OUTPUT_FILE:$CALLBACK" &

# Run nginx
nginx -g 'daemon off;'

0 comments on commit 2b0dcb0

Please sign in to comment.