Add more stable reverse proxy updating
This commit is contained in:
parent
95832941c0
commit
03a0b0ce00
5 changed files with 71 additions and 30 deletions
|
|
@ -1,3 +1,5 @@
|
|||
---
|
||||
|
||||
whoami_version: latest
|
||||
|
||||
whoami_upstream_file_dir: "{{ docker_stack_files_dir }}/whoami"
|
||||
|
|
|
|||
32
roles/whoami/handlers/main.yml
Normal file
32
roles/whoami/handlers/main.yml
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
## Register reverse proxy
|
||||
|
||||
# figure out if upstream id exists
|
||||
- name: check whoami upstream
|
||||
community.docker.docker_container_exec:
|
||||
container: "{{ caddy_container_id }}"
|
||||
command: >
|
||||
curl localhost:2019/id/{{ stack.name }}_upstream/
|
||||
changed_when: False
|
||||
register: result
|
||||
become: yes
|
||||
listen: "handle upstream"
|
||||
|
||||
# upstream has to be created
|
||||
- name: add whoami upstream
|
||||
community.docker.docker_container_exec:
|
||||
container: "{{ caddy_container_id }}"
|
||||
command: >
|
||||
curl -X POST -H "Content-Type: application/json" -d @/stacks/{{ stack.name }}/upstream.json localhost:2019/config/apps/http/servers/srv0/routes/0/
|
||||
become: yes
|
||||
when: (result.stdout | from_json)['error'] is defined
|
||||
listen: "handle upstream"
|
||||
|
||||
# upstream already exists, patch it
|
||||
- name: patch whoami upstream
|
||||
community.docker.docker_container_exec:
|
||||
container: "{{ caddy_container_id }}"
|
||||
command: >
|
||||
curl -X PATCH -H "Content-Type: application/json" -d @/stacks/{{ stack.name }}/upstream.json localhost:2019/id/{{ stack.name }}_upstream/
|
||||
become: yes
|
||||
when: (result.stdout | from_json)['error'] is not defined
|
||||
listen: "handle upstream"
|
||||
|
|
@ -1,35 +1,32 @@
|
|||
---
|
||||
# install whoami container
|
||||
- name: Ensure upstream directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ whoami_upstream_file_dir }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
become: true
|
||||
tags:
|
||||
- fs
|
||||
|
||||
- name: Update upstream template
|
||||
ansible.builtin.template:
|
||||
src: whoami_upstream.json.j2
|
||||
dest: "{{ whoami_upstream_file_dir }}/upstream.json"
|
||||
become: true
|
||||
tags:
|
||||
- fs
|
||||
notify: "handle upstream"
|
||||
|
||||
- name: Deploy whoami to swarm
|
||||
community.general.docker_stack:
|
||||
name: "{{ item.name }}"
|
||||
name: "{{ stack.name }}"
|
||||
state: present
|
||||
prune: yes
|
||||
compose:
|
||||
- "{{ item.compose }}"
|
||||
with_items: "{{ whoami_stack }}"
|
||||
when: whoami_stack is defined
|
||||
- "{{ stack.compose }}"
|
||||
when: stack is defined
|
||||
become: yes
|
||||
tags:
|
||||
- docker-swarm
|
||||
|
||||
- name: Get caddy container id
|
||||
ansible.builtin.command:
|
||||
cmd: docker ps -q -f name=caddy_app
|
||||
register: caddy_container_id
|
||||
become: yes
|
||||
|
||||
- name: Ensure caddy curl available
|
||||
community.docker.docker_container_exec:
|
||||
container: "{{ caddy_container_id.stdout }}"
|
||||
command: >
|
||||
apk add curl
|
||||
become: yes
|
||||
|
||||
- name: Add caddy reverse proxy
|
||||
community.docker.docker_container_exec:
|
||||
container: "{{ caddy_container_id.stdout }}"
|
||||
command: >
|
||||
curl localhost:2019/config/apps/http/servers/srv0/routes/0 -X POST -H "Content-Type: application/json" -d {{ whoami_upstream }}
|
||||
become: yes
|
||||
notify: "handle upstream"
|
||||
|
|
|
|||
13
roles/whoami/templates/whoami_upstream.json.j2
Normal file
13
roles/whoami/templates/whoami_upstream.json.j2
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"@id": "{{ stack.name }}_upstream",
|
||||
"handle": [
|
||||
{
|
||||
"handler": "reverse_proxy",
|
||||
"upstreams": [
|
||||
{
|
||||
"dial": "{{ stack.name }}_app:80"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,9 +1,6 @@
|
|||
---
|
||||
|
||||
whoami_stack:
|
||||
- name: whoami
|
||||
compose: "{{ lookup('template', 'docker-stack.yml.j2') | from_yaml }}"
|
||||
|
||||
whoami_upstream: >-
|
||||
'{ "@id": "whoami_upstream", "handle": [{ "handler": "reverse_proxy", "upstreams": [{ "dial": "whoami_app:80"}]}] }'
|
||||
stack:
|
||||
name: whoami
|
||||
compose: "{{ lookup('template', 'docker-stack.yml.j2') | from_yaml }}"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue