Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions ansible/eru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- hosts: consul
- hosts: mongodb
- hosts: redis
- hosts: socket-server-proxy

- hosts: eru
vars_files:
Expand All @@ -10,9 +11,7 @@
- { role: notify, tags: [ notify ] }
- { role: builder, tags: [ build ] }
- role: container_start

- hosts: socket-server-proxy
vars_files:
- group_vars/alpha-eru.yml
roles:
- role: eru
- role: nginx-proxied-service
nginx_host: "{{ groups['socket-server-proxy'][0] }}"
target_ip_address: "{{ hostvars[groups['eru'][0]]['ansible_default_ipv4']['address'] }}"
templates: [ 11-eru-server.conf ]
49 changes: 0 additions & 49 deletions ansible/roles/eru/tasks/main.yml

This file was deleted.

97 changes: 97 additions & 0 deletions ansible/roles/nginx-proxied-service/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
# these are pretty hacky, but it should work
# Get port information from the hosted service
- name: get eru ports
when: name == "eru"
tags: [ configure_proxy, deploy ]
become: true
shell: |
for c in $(docker ps | awk '/eru/{ print $1 }'); do
docker port $c 5501 | cut -d ':' -f 2
docker port $c 5502 | cut -d ':' -f 2
done
args:
executable: /bin/bash
register: eru_target_ports
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename eru?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, this and the next task, they both are the implementation of "how to get the ports for a service". I don't quite like how it's done, but I don't know that I can get around it. I'll see...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, this and the next task, they both are the implementation of "how to get the ports for a service". I don't quite like how it's done, but I don't know that I can get around it. I'll see...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's right - basically I'd have to modify container start or kill/start to always get the ports the same way at the end, but then templates can use them differently. I'm up for more ideas, but I'm not sure what to do


- name: get socket server ports
when: name == "api-socket-server"
tags: [ configure_proxy, deploy ]
become: true
shell: |
for c in $(docker ps | awk '/api-socket-server/{ print $1 }'); do
docker port $c 80 | cut -d ':' -f 2
done
args:
executable: /bin/bash
register: socket_target_ports

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

- name: print target ports
delegate_to: "{{ nginx_host }}"
tags: [ configure_proxy, deploy ]
debug:
msg: |
eru ports -- {{ eru_target_ports }}
socket ports -- {{ socket_target_ports }}

- name: print target IP address
delegate_to: "{{ nginx_host }}"
tags: [ configure_proxy, deploy ]
debug:
msg: ip -- {{ target_ip_address }}

- name: assert nginx config directory
delegate_to: "{{ nginx_host }}"
tags: [ configure_proxy, deploy ]
become: yes
file:
state: directory
dest: /etc/nginx

- name: assert nginx sites-available directory
delegate_to: "{{ nginx_host }}"
tags: [ configure_proxy, deploy ]
become: yes
file:
state: directory
dest: /etc/nginx/sites-available

- name: assert nginx sites-enable directory
delegate_to: "{{ nginx_host }}"
tags: [ configure_proxy, deploy ]
become: yes
file:
state: directory
dest: /etc/nginx/sites-enable

- name: put configuration in place
delegate_to: "{{ nginx_host }}"
tags: [ configure_proxy, deploy ]
become: yes
template:
src: "{{ item }}"
dest: /etc/nginx/sites-available/{{ item }}
with_items: "{{ templates }}"

- name: link configuration to enable
delegate_to: "{{ nginx_host }}"
tags: [ configure_proxy, deploy ]
become: yes
file:
state: link
dest: /etc/nginx/sites-enabled/{{ item }}
src: /etc/nginx/sites-available/{{ item }}
with_items: "{{ templates }}"

- name: reload nginx
delegate_to: "{{ nginx_host }}"
tags: [ configure_proxy, deploy ]
become: yes
shell: >
docker ps |
awk '/nginx/{ print $1 }' |
xargs -n 1 docker kill --signal SIGHUP
args:
executable: /bin/bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ map $http_upgrade $connection_upgrade {

upstream socketserver {
sticky;
{% for port in ports.stdout_lines -%}
server {{ socket_server_hostname }}:{{ port }};
{% for port in socket_target_ports.stdout_lines -%}
server {{ target_ip_address }}:{{ port }};
{% endfor %}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ server {

location / {
expires 300;
proxy_pass http://{{ eru_server_hostname }}:{{ ports.stdout_lines[0] | trim }};
proxy_pass http://{{ target_ip_address }}:{{ eru_target_ports.stdout_lines[0] | trim }};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename file to not have eru if this is generic?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file isn't generic. the templates live in the nginx-proxied-service role and the playbooks using this role have to tell it which templates to use

proxy_set_header Host $host;
proxy_set_header x-real-ip $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
Expand All @@ -44,7 +44,7 @@ server {
}

location /graphql {
proxy_pass http://{{ eru_server_hostname }}:{{ ports.stdout_lines[1] | trim }};
proxy_pass http://{{ target_ip_address }}:{{ eru_target_ports.stdout_lines[1] | trim }};
proxy_set_header Host $host;
proxy_set_header x-real-ip $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
Expand Down
74 changes: 0 additions & 74 deletions ansible/roles/socket-proxy/files/nginx.conf

This file was deleted.

7 changes: 0 additions & 7 deletions ansible/roles/socket-proxy/handlers/main.yml

This file was deleted.

50 changes: 0 additions & 50 deletions ansible/roles/socket-proxy/tasks/main.yml

This file was deleted.

12 changes: 5 additions & 7 deletions ansible/socket-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- hosts: redis
- hosts: swarm-manager
- hosts: consul
- hosts: socket-server-proxy

- hosts: socket-server
vars_files:
Expand All @@ -22,10 +23,7 @@
- { role: tls-client, tls_service: mongodb, tags: [ tls ] }
- { role: datadog, tags: [ datadog ] }
- { role: container_start, number_of_containers: 8 }

- hosts: socket-server-proxy
vars_files:
- group_vars/alpha-proxy-socket-server.yml
roles:
- role: socket-proxy
- role: container_restart
- role: nginx-proxied-service
nginx_host: "{{ groups['socket-server-proxy'][0] }}"
target_ip_address: "{{ hostvars[groups['socket-server'][0]]['ansible_default_ipv4']['address'] }}"
templates: [ 01-socket-server.conf ]