Skip to content

Commit f41c29f

Browse files
Merge pull request #493 from CodeNow/SAN-4398-add-dynamic-nginx
update nginx to use consul-template-updater; add registrator
2 parents 3705fe0 + eb2e109 commit f41c29f

10 files changed

Lines changed: 94 additions & 18 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
- hosts: consul
3+
4+
- hosts: userland
5+
vars_files:
6+
- group_vars/{{ var_file }}
7+
- group_vars/alpha-consul-template-updater.yml
8+
roles:
9+
- role: notify
10+
tags: notify
11+
12+
- role: container_kill_start
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
--volumes-from {{ target_container_name }}
13+
14+
container_run_args: >
15+
-consul={{ consul_host_address }}:{{ consul_api_port }}
16+
-wait=1s
17+
-template="/tmp/template:{{ target_updater_file_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+
target_updater_file_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 {{ target_updater_file_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+
--hostname={{ ansible_hostname }}
10+
--name={{ name }}
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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
---
22
- hosts: userland
33
vars_files:
4-
- group_vars/alpha-navi-proxy.yml
4+
- group_vars/alpha-navi-proxy.yml
55
roles:
6-
- role: datadog
7-
has_dd_integration: yes
6+
- role: datadog
7+
has_dd_integration: yes
88

9-
- role: content-domain-proxy
9+
- role: content-domain-proxy
1010

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

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
- hosts: consul
3+
4+
- hosts: navi
5+
vars_files:
6+
- group_vars/alpha-registrator.yml
7+
roles:
8+
- role: notify
9+
tags: notify
10+
11+
- 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)