From 3f944df048997a02dfb676dff0276b932d83ef87 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 24 Oct 2021 10:55:46 +0200 Subject: [PATCH] Add traggo deployment --- group_vars/testing.yml | 1 + roles/traggo/README.md | 41 +++++++++++++++++ roles/traggo/defaults/main.yml | 14 ++++++ roles/traggo/handlers/main.yml | 53 ++++++++++++++++++++++ roles/traggo/meta/main.yml | 14 ++++++ roles/traggo/tasks/main.yml | 24 ++++++++++ roles/traggo/templates/docker-stack.yml.j2 | 19 ++++++++ roles/traggo/templates/upstream.json.j2 | 44 ++++++++++++++++++ roles/traggo/vars/main.yml | 7 +++ site-dev.yml | 1 + site.yml | 1 + 11 files changed, 219 insertions(+) create mode 100644 roles/traggo/README.md create mode 100644 roles/traggo/defaults/main.yml create mode 100644 roles/traggo/handlers/main.yml create mode 100644 roles/traggo/meta/main.yml create mode 100644 roles/traggo/tasks/main.yml create mode 100644 roles/traggo/templates/docker-stack.yml.j2 create mode 100644 roles/traggo/templates/upstream.json.j2 create mode 100644 roles/traggo/vars/main.yml diff --git a/group_vars/testing.yml b/group_vars/testing.yml index a5282e2..6ccf603 100644 --- a/group_vars/testing.yml +++ b/group_vars/testing.yml @@ -10,5 +10,6 @@ whoami_use_https: no wallabag_use_https: no miniflux_use_https: no searx_use_https: no +traggo_use_https: no #server_domain: mytest.com diff --git a/roles/traggo/README.md b/roles/traggo/README.md new file mode 100644 index 0000000..648933f --- /dev/null +++ b/roles/traggo/README.md @@ -0,0 +1,41 @@ +# traggo + +A minimalist rss feed reader. +Deployed in a docker swarm with caddy. + +## Defaults + +``` +traggo_upstream_file_dir: "{{ docker_stack_files_dir }}/{{ stack_name }}" +``` + +The on-target directory where the proxy configuration file should be stashed. + +``` +traggo_use_https: true +``` + +Whether the service should be reachable through http (port 80) or through https (port 443) and provision an https certificate. Usually you will want this to stay `true`. + +``` +traggo_version: latest +``` + +The docker image version to be used in stack creation. + +``` +subdomain_alias: time +``` + +If the deployed container should be served over a uri that is not the stack name. +By default, it will be set to `time.yourdomain.com` - +if this option is not set it will be served on `traggo.yourdomain.com` instead. + +``` +traggo_username: mytraggouser +traggo_password: mytraggopassword +``` + +Set the default username and password combination on first container start. +If loading from an existing volume this does nothing, otherwise it sets the +first user so you can instantly log in. diff --git a/roles/traggo/defaults/main.yml b/roles/traggo/defaults/main.yml new file mode 100644 index 0000000..60b5b75 --- /dev/null +++ b/roles/traggo/defaults/main.yml @@ -0,0 +1,14 @@ +--- + +traggo_version: latest + +traggo_upstream_file_dir: "{{ docker_stack_files_dir }}/{{ stack_name }}" + +traggo_use_https: true + +# the subdomain link traggo will be reachable under +subdomain_alias: time + +# Should ideally be overwritten in encrypted group/host vars +traggo_username: mytraggouser +traggo_password: mytraggopassword diff --git a/roles/traggo/handlers/main.yml b/roles/traggo/handlers/main.yml new file mode 100644 index 0000000..e072105 --- /dev/null +++ b/roles/traggo/handlers/main.yml @@ -0,0 +1,53 @@ +## Register reverse proxy +- name: Ensure upstream directory exists + ansible.builtin.file: + path: "{{ traggo_upstream_file_dir }}" + state: directory + mode: '0755' + become: yes + listen: "update traggo upstream" + +- name: Update upstream template + ansible.builtin.template: + src: upstream.json.j2 + dest: "{{ traggo_upstream_file_dir }}/upstream.json" + become: yes + listen: "update traggo upstream" + +# figure out if upstream id exists +- name: check {{ stack_name }} 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: "update traggo upstream" + +# upstream already exists, patch it +- name: remove old {{ stack_name }} upstream + community.docker.docker_container_exec: + container: "{{ caddy_container_id }}" + command: > + curl -X DELETE localhost:2019/id/{{ stack_name }}_upstream/ + become: yes + when: (result.stdout | from_json)['error'] is not defined + listen: "update traggo upstream" + +# upstream has to be created +- name: add {{ stack_name }} upstream + community.docker.docker_container_exec: + container: "{{ caddy_container_id }}" + command: > + curl -X POST -H "Content-Type: application/json" -d @{{ traggo_upstream_file_dir }}/upstream.json localhost:2019/config/apps/http/servers/{{ (traggo_use_https == True) | ternary(caddy_https_server_name, caddy_http_server_name) }}/routes/0/ + become: yes + listen: "update traggo upstream" + +- name: Ensure upstream directory is gone again + ansible.builtin.file: + path: "{{ traggo_upstream_file_dir }}" + state: absent + become: yes + listen: "update traggo upstream" + diff --git a/roles/traggo/meta/main.yml b/roles/traggo/meta/main.yml new file mode 100644 index 0000000..ddd5c7f --- /dev/null +++ b/roles/traggo/meta/main.yml @@ -0,0 +1,14 @@ +--- + +galaxy_info: + author: Marty Oehme + description: Installs traggo as a docker stack service + license: GPL-3.0-only + min_ansible_version: 2.9 + galaxy_tags: [] + + +dependencies: + - docker + - docker-swarm + - caddy diff --git a/roles/traggo/tasks/main.yml b/roles/traggo/tasks/main.yml new file mode 100644 index 0000000..331e851 --- /dev/null +++ b/roles/traggo/tasks/main.yml @@ -0,0 +1,24 @@ +--- +## install traggo container +- name: Check upstream status + community.docker.docker_container_exec: + container: "{{ caddy_container_id }}" + command: > + curl localhost:2019/id/{{ stack_name }}_upstream/ + register: result + changed_when: (result.stdout | from_json) != (lookup('template', 'upstream.json.j2') | from_yaml) + become: yes + notify: "update traggo upstream" + +- name: Deploy traggo to swarm + community.general.docker_stack: + name: "{{ stack_name }}" + state: present + prune: yes + compose: + - "{{ stack_compose }}" + become: yes + tags: + - docker-swarm + notify: "update traggo upstream" + diff --git a/roles/traggo/templates/docker-stack.yml.j2 b/roles/traggo/templates/docker-stack.yml.j2 new file mode 100644 index 0000000..a42f74b --- /dev/null +++ b/roles/traggo/templates/docker-stack.yml.j2 @@ -0,0 +1,19 @@ +version: '3.7' + +services: + app: + image: {{ stack_image }}:{{ traggo_version }} + networks: + - "{{ docker_swarm_public_network_name }}" + volumes: + - data:/opt/traggo/data + environment: + - TRAGGO_DEFAULT_USER_NAME={{ traggo_username }} + - TRAGGO_DEFAULT_USER_PASS={{ traggo_password }} + +volumes: + data: + +networks: + "{{ docker_swarm_public_network_name }}": + external: true diff --git a/roles/traggo/templates/upstream.json.j2 b/roles/traggo/templates/upstream.json.j2 new file mode 100644 index 0000000..80b3545 --- /dev/null +++ b/roles/traggo/templates/upstream.json.j2 @@ -0,0 +1,44 @@ +{ + "@id": "{{ stack_name }}_upstream", +{% if server_domain is not undefined and not none %} + "match": [ + { + "host": [ +{% if subdomain_alias is not undefined and not none %} + "{{ subdomain_alias }}.{{ server_domain }}" +{% else %} + "{{ stack_name }}.{{ server_domain }}" +{% endif %} + ] + } + ], +{% else %} + "match": [ + { + "path": [ +{% if subdomain_alias is not undefined and not none %} + "/{{ subdomain_alias }}*" +{% else %} + "/{{ stack_name }}*" +{% endif %} + ] + } + ], +{% endif %} + "handle": [ +{% if server_domain is undefined or none %} + { + "handler": "rewrite", + "strip_path_prefix": "/{{ (subdomain_alias is not undefined and not none) | ternary(subdomain_alias, stack_name) }}" + }, +{% endif %} + { + "handler": "reverse_proxy", + "upstreams": [ + { + "dial": "{{ stack_name }}_app:3030" + } + ] + } + ] +} diff --git a/roles/traggo/vars/main.yml b/roles/traggo/vars/main.yml new file mode 100644 index 0000000..114f166 --- /dev/null +++ b/roles/traggo/vars/main.yml @@ -0,0 +1,7 @@ +--- + +stack_name: traggo + +stack_image: "traggo/server" + +stack_compose: "{{ lookup('template', 'docker-stack.yml.j2') | from_yaml }}" diff --git a/site-dev.yml b/site-dev.yml index 76931f0..ad24dbf 100644 --- a/site-dev.yml +++ b/site-dev.yml @@ -6,3 +6,4 @@ - wallabag - miniflux - searx + - traggo diff --git a/site.yml b/site.yml index 8d4f2d7..0c82e38 100644 --- a/site.yml +++ b/site.yml @@ -13,3 +13,4 @@ - wallabag - miniflux - searx + - traggo