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_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
|
# 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
|
- name: Deploy whoami to swarm
|
||||||
community.general.docker_stack:
|
community.general.docker_stack:
|
||||||
name: "{{ item.name }}"
|
name: "{{ stack.name }}"
|
||||||
state: present
|
state: present
|
||||||
prune: yes
|
prune: yes
|
||||||
compose:
|
compose:
|
||||||
- "{{ item.compose }}"
|
- "{{ stack.compose }}"
|
||||||
with_items: "{{ whoami_stack }}"
|
when: stack is defined
|
||||||
when: whoami_stack is defined
|
|
||||||
become: yes
|
become: yes
|
||||||
tags:
|
tags:
|
||||||
- docker-swarm
|
- docker-swarm
|
||||||
|
notify: "handle upstream"
|
||||||
- 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
|
|
||||||
|
|
|
||||||
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:
|
stack:
|
||||||
- name: whoami
|
name: whoami
|
||||||
compose: "{{ lookup('template', 'docker-stack.yml.j2') | from_yaml }}"
|
compose: "{{ lookup('template', 'docker-stack.yml.j2') | from_yaml }}"
|
||||||
|
|
||||||
whoami_upstream: >-
|
|
||||||
'{ "@id": "whoami_upstream", "handle": [{ "handler": "reverse_proxy", "upstreams": [{ "dial": "whoami_app:80"}]}] }'
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue