Skip to content

Commit 76233d0

Browse files
author
Anandkumar Patel
committed
update proxy for navi
1 parent f38651b commit 76233d0

5 files changed

Lines changed: 28 additions & 28 deletions

File tree

ansible/group_vars/alpha-navi.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: navi
33
container_image: registry.runnable.com/runnable/{{ name }}
44
container_tag: "{{ git_branch }}"
55
repo: git@github.com:CodeNow/{{ name }}.git
6-
hosted_ports: [ "{{ navi_http_port }}", "{{ navi_https_port }}" ]
6+
hosted_ports: [ "{{ navi_http_port }}" ]
77
node_version: "4.2.4"
88
npm_version: "2.8.3"
99

@@ -21,7 +21,6 @@ container_envs: >
2121
-e ENABLE_LRU_CACHE=1
2222
-e ERROR_URL=http://{{ detention_host_address }}:{{ detention_port }}
2323
-e HTTP_PORT={{ hosted_ports[0] }}
24-
-e HTTPS_PORT={{ hosted_ports[1] }}
2524
-e LOG_LEVEL_STDOUT=trace
2625
-e MONGO=mongodb://{{ navi_mongo_host_address }}:{{ navi_mongo_port }}/{{ navi_mongo_database }}
2726
-e NODE_ENV={{ node_env }}
@@ -32,7 +31,6 @@ container_envs: >
3231
-e REDIS_CACERT={{ redis_ca_cert_path }}
3332
-e REDIS_IPADDRESS={{ redis_host_address }}
3433
-e REDIS_PORT={{ redis_tls_port }}
35-
-e USERLAND_IP={{ userland_host_address }}
3634
{% if navi_intercom_api_key is defined %} -e INTERCOM_API_KEY={{ navi_intercom_api_key }} {% endif %}
3735
{% if navi_intercom_app_id is defined %} -e INTERCOM_APP_ID={{ navi_intercom_app_id }} {% endif %}
3836
{% if navi_new_relic_app_name is defined %} -e NEW_RELIC_APP_NAME={{ navi_new_relic_app_name }} {% endif %}
@@ -43,8 +41,7 @@ container_envs: >
4341
container_run_opts: >
4442
-h {{ name }}
4543
-d
46-
-p {{ hosted_ports[0] }}:{{ hosted_ports[0] }}
47-
-p {{ hosted_ports[1] }}:{{ hosted_ports[1] }}
44+
-P
4845
-v {{ redis_ca_cert_path }}:{{ redis_ca_cert_path }}
4946
-v {{ content_domain_certs }}:{{ content_domain_certs }}
5047
{{ container_envs }}

ansible/navi.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@
1616
- { role: builder, tags: [ build ] }
1717
- { role: content-domain-certs }
1818
- { role: tls-server-ca, ca_dest: "{{ redis_ca_cert_path }}" }
19-
- { role: container_kill_start }
19+
- { role: container_start, number_of_containers: 2 }
20+
- role: nginx-proxied-service
21+
nginx_host: "{{ groups['userland'][0] }}"
22+
target_ip_address: "{{ hostvars[groups['navi'][0]]['ansible_default_ipv4']['address'] }}"
23+
templates: [ 01-navi.conf ]
24+
nginx_config: proxy

ansible/roles/nginx-proxied-service/tasks/main.yml

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
11
---
22
# these are pretty hacky, but it should work
33
# Get port information from the hosted service
4-
- name: get eru ports
5-
when: name == "eru"
6-
tags: [ configure_proxy, deploy ]
7-
become: true
8-
shell: |
9-
for c in $(docker ps | awk '/eru/{ print $1 }'); do
10-
docker port $c 5501 | cut -d ':' -f 2
11-
docker port $c 5502 | cut -d ':' -f 2
12-
done
13-
args:
14-
executable: /bin/bash
15-
register: eru_target_ports
16-
174
- name: get socket server ports
18-
when: name == "api-socket-server"
195
tags: [ configure_proxy, deploy ]
206
become: true
217
shell: |
22-
for c in $(docker ps | awk '/api-socket-server/{ print $1 }'); do
23-
docker port $c 80 | cut -d ':' -f 2
8+
for c in $(docker ps | awk '/{{ name }}/{ print $1 }'); do
9+
{% if hosted_ports is defined %}
10+
{% for hosted_port in hosted_ports %}
11+
docker port $c {{ hosted_port }} | cut -d ':' -f 2
12+
{% endfor %}
13+
{% endif %}
2414
done
2515
args:
2616
executable: /bin/bash
27-
register: socket_target_ports
17+
register: proxy_target_ports
2818

2919
# everything from this point on is deligated to the nginx host
3020

@@ -33,8 +23,7 @@
3323
tags: [ configure_proxy, deploy ]
3424
debug:
3525
msg: |
36-
eru ports -- {{ eru_target_ports }}
37-
socket ports -- {{ socket_target_ports }}
26+
proxy target ports -- {{ proxy_target_ports }}
3827
3928
- name: print target IP address
4029
delegate_to: "{{ nginx_host }}"
@@ -66,6 +55,15 @@
6655
state: directory
6756
dest: /etc/nginx/sites-enable
6857

58+
- name: put nginx configuration in place
59+
when: nginx_config is defined and nginx_config == "proxy"
60+
delegate_to: "{{ nginx_host }}"
61+
tags: [ configure_proxy, deploy ]
62+
become: yes
63+
template:
64+
src: "{{ nginx_config }}-nginx.conf"
65+
dest: /etc/nginx/nginx.conf
66+
6967
- name: put configuration in place
7068
delegate_to: "{{ nginx_host }}"
7169
tags: [ configure_proxy, deploy ]

ansible/roles/nginx-proxied-service/templates/01-socket-server.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ map $http_upgrade $connection_upgrade {
55

66
upstream socketserver {
77
sticky;
8-
{% for port in socket_target_ports.stdout_lines -%}
8+
{% for port in proxy_target_ports.stdout_lines -%}
99
server {{ target_ip_address }}:{{ port }};
1010
{% endfor %}
1111
}

ansible/roles/nginx-proxied-service/templates/11-eru-server.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ server {
3939

4040
location / {
4141
expires 300;
42-
proxy_pass http://{{ target_ip_address }}:{{ eru_target_ports.stdout_lines[0] | trim }};
42+
proxy_pass http://{{ target_ip_address }}:{{ proxy_target_ports.stdout_lines[0] | trim }};
4343
proxy_set_header Host $host;
4444
proxy_set_header x-real-ip $remote_addr;
4545
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
@@ -48,7 +48,7 @@ server {
4848
}
4949

5050
location /graphql {
51-
proxy_pass http://{{ target_ip_address }}:{{ eru_target_ports.stdout_lines[1] | trim }};
51+
proxy_pass http://{{ target_ip_address }}:{{ proxy_target_ports.stdout_lines[1] | trim }};
5252
proxy_set_header Host $host;
5353
proxy_set_header x-real-ip $remote_addr;
5454
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;

0 commit comments

Comments
 (0)