Skip to content

Commit 16e7ae5

Browse files
author
Anandkumar Patel
committed
update nginx to use consul-template-updater; add registrator
1 parent 510d6db commit 16e7ae5

10 files changed

Lines changed: 86 additions & 13 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- hosts: consul
3+
4+
- hosts: userland
5+
vars_files:
6+
- "group_vars/{{ var_file }}.yml"
7+
- "group_vars/alpha-consul-template-updater.yml"
8+
roles:
9+
- { role: notify, tags: "notify" }
10+
- { role: container_kill_start }
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: consul-template-updater
2+
3+
# container_kill_start settings
4+
container_image: avthart/consul-template
5+
container_tag: latest
6+
7+
container_run_opts: >
8+
-d
9+
--name {{ name }}
10+
-v /var/run/docker.sock:/tmp/docker.sock
11+
-v {{ template_path }}:/tmp/template
12+
-e CONSUL_TEMPLATE_LOG=debug
13+
--volumes-from {{ target_container_name }}
14+
15+
container_run_args: >
16+
-consul={{ consul_host_address }}:{{ consul_api_port }}
17+
-wait=1s
18+
-template="/tmp/template:{{ dest_path }}/{{ out_file }}:{{ template_command }}"
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
---
22
name: nginx
33

4+
# used by consul template updater
5+
target_container_name: nginx
6+
dest_path: /etc/nginx/sites-enabled
7+
template_path: /etc/nginx/template/navi.tmpl
8+
template_command: "/bin/docker kill -s HUP {{ target_container_name }}"
9+
out_file: 'navi.conf'
10+
11+
# used by container_kill_start
412
container_image: "{{ name }}"
513
container_tag: "1.10"
614

715
container_run_opts: >
816
-d
9-
-h {{ name }}
17+
--net=host
18+
--name {{ name }}
1019
-p 0.0.0.0:443:443
1120
-p 0.0.0.0:80:80
1221
-v /etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
13-
-v /etc/nginx/sites-enabled/:/etc/nginx/sites-enabled/:ro
22+
-v {{ dest_path }}
1423
-v /etc/ssl/certs/{{ user_content_domain }}:/etc/ssl/certs/{{ user_content_domain }}:ro
1524
-v /var/log/nginx:/var/log/nginx

ansible/group_vars/alpha-navi.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ hosted_ports: [ "{{ navi_http_port }}" ]
77
node_version: "4.2.4"
88
npm_version: "2.8.3"
99

10+
restart_policy: "always"
11+
1012
redis_ca_cert_path: /opt/ssl/{{ name }}/redis/ca.pem
1113
content_domain_certs: /opt/ssl/{{ user_content_domain }}
1214

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: "registrator"
2+
3+
# container_kill_start settings
4+
container_image: gliderlabs/registrator
5+
container_tag: v7
6+
7+
container_run_opts: >
8+
-d
9+
--name={{ name }}
10+
--net=host
11+
--volume=/var/run/docker.sock:/tmp/docker.sock
12+
13+
container_run_args: >
14+
-ip {{ ansible_default_ipv4.address }}
15+
consul://{{ consul_host_address }}:{{ consul_api_port }}

ansible/navi-proxy.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
- role: content-domain-proxy
1010

1111
- role: container_kill_start
12+
13+
- include: consul-template-updater.yml
14+
vars:
15+
var_file: "alpha-navi-proxy"

ansible/navi.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,3 @@
2121

2222
- role: container_start
2323
number_of_containers: "{{ ansible_processor_cores }}"
24-
25-
- role: nginx-proxied-service
26-
nginx_host: "{{ groups['userland'][0] }}"
27-
target_ip_address: "{{ hostvars[groups['navi'][0]]['ansible_default_ipv4']['address'] }}"
28-
templates: [ 69-navi.conf ]
29-
nginx_config: proxy

ansible/registrator.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- hosts: consul
3+
4+
- hosts: navi
5+
vars_files:
6+
- "group_vars/alpha-registrator.yml"
7+
roles:
8+
- { role: notify, tags: "notify" }
9+
- { role: container_kill_start }

ansible/roles/content-domain-proxy/tasks/main.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
dest: /etc/nginx
4545
state: directory
4646

47-
4847
- name: assert nginx sites-enabled directory
4948
tags: [ configure_proxy ]
5049
become: yes
@@ -57,4 +56,18 @@
5756
become: yes
5857
template:
5958
src: proxy-nginx.conf
60-
dest: /etc/nginx/nginx.conf
59+
dest: /etc/nginx/nginx.conf
60+
61+
- name: assert nginx template directory
62+
tags: [ configure_proxy ]
63+
become: yes
64+
file:
65+
state: directory
66+
dest: /etc/nginx/template
67+
68+
- name: put navi template in place
69+
tags: [ configure_proxy ]
70+
become: yes
71+
template:
72+
src: navi.tmpl
73+
dest: /etc/nginx/template

ansible/roles/nginx-proxied-service/templates/69-navi.conf renamed to ansible/roles/content-domain-proxy/templates/navi.tmpl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ map $http_upgrade $connection_upgrade {
44
}
55

66
upstream {{ name }} {
7-
{% for port in proxy_target_ports.stdout_lines -%}
8-
server {{ target_ip_address }}:{{ port }} max_fails=0 fail_timeout=1s;
9-
{% endfor %}
7+
{{ '{{' }}range service "{{ name }}"{{ '}}' }} server {{ '{{' }}.Address{{ '}}' }}:{{ '{{' }}.Port{{ '}}' }} max_fails=0 fail_timeout=1s;
8+
{{ '{{' }}end{{ '}}' }}
109
}
1110

1211
server {

0 commit comments

Comments
 (0)