Add wallabag docker deployment role
Added role of wallabag. Can take a subdomain alias to be presented on a different uri than its stack name. All services contain a healthcheck for docker swarm to be informed of their status. Copy whoami template to wallabag role Change non-domain domain name to localhost Fix correct handler notify naming Allow setting different subdomain alias than name Add meta information
This commit is contained in:
parent
80185e39dd
commit
ebd995b8c4
9 changed files with 226 additions and 0 deletions
42
roles/wallabag/README.md
Normal file
42
roles/wallabag/README.md
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# wallabag
|
||||
|
||||
A very simple service application stack role which can be used to base other roles off of.
|
||||
Contains only a single deployed image and a couple of simple variables to set.
|
||||
|
||||
## Variables
|
||||
|
||||
```
|
||||
wallabag_upstream_file_dir: "{{ docker_stack_files_dir }}/{{ stack.name }}"
|
||||
```
|
||||
|
||||
The on-target directory where the proxy configuration file should be stashed.
|
||||
|
||||
```
|
||||
wallabag_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`.
|
||||
|
||||
```
|
||||
wallabag_version: latest
|
||||
```
|
||||
|
||||
The docker image version to be used in stack creation.
|
||||
|
||||
## Internal variables
|
||||
|
||||
```
|
||||
stack:
|
||||
name: wallabag
|
||||
compose: "{{ lookup('template', 'docker-stack.yml.j2') | from_yaml }}"
|
||||
```
|
||||
|
||||
The name of the stack to be provisioned and the compose file to be used.
|
||||
See caddy ReadMe for configuration.
|
||||
|
||||
```
|
||||
stack_image: "wallabag/wallabag"
|
||||
```
|
||||
|
||||
The docker hub image to be use in provisioning.
|
||||
|
||||
10
roles/wallabag/defaults/main.yml
Normal file
10
roles/wallabag/defaults/main.yml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
|
||||
wallabag_version: latest
|
||||
|
||||
wallabag_upstream_file_dir: "{{ docker_stack_files_dir }}/{{ stack.name }}"
|
||||
|
||||
wallabag_use_https: true
|
||||
|
||||
# the subdomain link wallabag will be reachable under
|
||||
subdomain_alias: read
|
||||
53
roles/wallabag/handlers/main.yml
Normal file
53
roles/wallabag/handlers/main.yml
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
## Register reverse proxy
|
||||
- name: Ensure upstream directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ wallabag_upstream_file_dir }}"
|
||||
state: directory
|
||||
mode: '0755'
|
||||
become: yes
|
||||
listen: "update wallabag upstream"
|
||||
|
||||
- name: Update upstream template
|
||||
ansible.builtin.template:
|
||||
src: upstream.json.j2
|
||||
dest: "{{ wallabag_upstream_file_dir }}/upstream.json"
|
||||
become: yes
|
||||
listen: "update wallabag 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 wallabag 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 wallabag 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 @{{ wallabag_upstream_file_dir }}/upstream.json localhost:2019/config/apps/http/servers/{{ (wallabag_use_https == True) | ternary(caddy_https_server_name, caddy_http_server_name) }}/routes/0/
|
||||
become: yes
|
||||
listen: "update wallabag upstream"
|
||||
|
||||
- name: Ensure upstream directory is gone again
|
||||
ansible.builtin.file:
|
||||
path: "{{ wallabag_upstream_file_dir }}"
|
||||
state: absent
|
||||
become: yes
|
||||
listen: "update wallabag upstream"
|
||||
|
||||
14
roles/wallabag/meta/main.yml
Normal file
14
roles/wallabag/meta/main.yml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
|
||||
galaxy_info:
|
||||
author: Marty Oehme
|
||||
description: Installs wallabag as a docker stack service
|
||||
license: GPL-3.0-only
|
||||
min_ansible_version: 2.9
|
||||
galaxy_tags: []
|
||||
|
||||
|
||||
dependencies:
|
||||
- docker
|
||||
- docker-swarm
|
||||
- caddy
|
||||
25
roles/wallabag/tasks/main.yml
Normal file
25
roles/wallabag/tasks/main.yml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
## install wallabag 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 wallabag upstream"
|
||||
|
||||
- name: Deploy wallabag to swarm
|
||||
community.general.docker_stack:
|
||||
name: "{{ stack.name }}"
|
||||
state: present
|
||||
prune: yes
|
||||
compose:
|
||||
- "{{ stack.compose }}"
|
||||
when: stack is defined
|
||||
become: yes
|
||||
tags:
|
||||
- docker-swarm
|
||||
notify: "update wallabag upstream"
|
||||
|
||||
36
roles/wallabag/templates/docker-stack.yml.j2
Normal file
36
roles/wallabag/templates/docker-stack.yml.j2
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
version: "3.7"
|
||||
|
||||
services:
|
||||
app:
|
||||
image: {{ stack_image }}:{{ wallabag_version }}
|
||||
networks:
|
||||
- "{{ docker_swarm_public_network_name }}"
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost"]
|
||||
interval: 1m
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 1m
|
||||
volumes:
|
||||
- data:/var/www/wallabag/data
|
||||
environment:
|
||||
- SYMFONY__ENV__FOSUSER_REGISTRATION=false
|
||||
{% if server_domain is not undefined and not none %}
|
||||
- SYMFONY__ENV__DOMAIN_NAME={{ (wallabag_use_https == True) | ternary('https', 'http') }}://wallabag.{{ server_domain }}
|
||||
{% else %}
|
||||
- SYMFONY__ENV__DOMAIN_NAME={{ (wallabag_use_https == True) | ternary('https', 'http') }}://localhost
|
||||
{% endif %}
|
||||
|
||||
redis:
|
||||
image: redis:alpine
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 20s
|
||||
timeout: 3s
|
||||
|
||||
volumes:
|
||||
data:
|
||||
|
||||
networks:
|
||||
"{{ docker_swarm_public_network_name }}":
|
||||
external: true
|
||||
38
roles/wallabag/templates/upstream.json.j2
Normal file
38
roles/wallabag/templates/upstream.json.j2
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"@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": [
|
||||
{
|
||||
"handler": "reverse_proxy",
|
||||
"upstreams": [
|
||||
{
|
||||
"dial": "{{ stack.name }}_app:80"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
7
roles/wallabag/vars/main.yml
Normal file
7
roles/wallabag/vars/main.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
|
||||
stack:
|
||||
name: wallabag
|
||||
compose: "{{ lookup('template', 'docker-stack.yml.j2') | from_yaml }}"
|
||||
|
||||
stack_image: "wallabag/wallabag"
|
||||
1
site.yml
1
site.yml
|
|
@ -10,3 +10,4 @@
|
|||
roles:
|
||||
- caddy
|
||||
- whoami
|
||||
- wallabag
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue