Add basic shaarli deployment

This commit is contained in:
Marty Oehme 2021-11-21 21:20:26 +01:00
parent f2e709590b
commit b75e5e58c6
Signed by: Marty
GPG key ID: B7538B8F50A1C800
11 changed files with 214 additions and 0 deletions

40
roles/shaarli/README.md Normal file
View file

@ -0,0 +1,40 @@
# shaarli
A simple and fast bookmark manager.
Can be deployed in minutes and takes minimum amount of resources.
Be aware that shaarli installations can *not* be fully automated.
That means after running this ansible role you will still have to setup up the first run wizard and create a user and so forth
(if not running with an existing data-store).
Do this quickly after setup,
*especially* if your instance is public-facing!
{: .alert .alert-warning}
## Defaults
```
shaarli_upstream_file_dir: "{{ docker_stack_files_dir }}/{{ stack_name }}"
```
The on-target directory where the proxy configuration file should be stashed.
```
shaarli_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`.
```
shaarli_version: latest
```
The docker image version to be used in stack creation.
```
subdomain_alias: links
```
If the deployed container should be served over a uri that is not the stack name.
By default, it will be set to `links.yourdomain.com` -
if this option is not set it will be served on `shaarli.yourdomain.com` instead.

View file

@ -0,0 +1,10 @@
---
shaarli_version: latest
shaarli_upstream_file_dir: "{{ docker_stack_files_dir }}/{{ stack_name }}"
shaarli_use_https: true
# the subdomain link shaarli will be reachable under
subdomain_alias: links

View file

@ -0,0 +1,53 @@
## Register reverse proxy
- name: Ensure upstream directory exists
ansible.builtin.file:
path: "{{ shaarli_upstream_file_dir }}"
state: directory
mode: '0755'
become: yes
listen: "update shaarli upstream"
- name: Update upstream template
ansible.builtin.template:
src: upstream.json.j2
dest: "{{ shaarli_upstream_file_dir }}/upstream.json"
become: yes
listen: "update shaarli 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 shaarli 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 shaarli 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 @{{ shaarli_upstream_file_dir }}/upstream.json localhost:2019/config/apps/http/servers/{{ (shaarli_use_https == True) | ternary(caddy_https_server_name, caddy_http_server_name) }}/routes/0/
become: yes
listen: "update shaarli upstream"
- name: Ensure upstream directory is gone again
ansible.builtin.file:
path: "{{ shaarli_upstream_file_dir }}"
state: absent
become: yes
listen: "update shaarli upstream"

View file

@ -0,0 +1,14 @@
---
galaxy_info:
author: Marty Oehme
description: Installs shaarli as a docker stack service
license: GPL-3.0-only
min_ansible_version: 2.9
galaxy_tags: []
dependencies:
- docker
- docker-swarm
- caddy

View file

@ -0,0 +1,24 @@
---
## install shaarli 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 shaarli upstream"
- name: Deploy shaarli to swarm
community.general.docker_stack:
name: "{{ stack_name }}"
state: present
prune: yes
compose:
- "{{ stack_compose }}"
become: yes
tags:
- docker-swarm
notify: "update shaarli upstream"

View file

@ -0,0 +1,25 @@
version: '3.4'
services:
app:
image: "{{ stack_image }}:{{ shaarli_version }}"
healthcheck:
test: ["CMD", "wget", "--quiet", "--spider", "--tries=1", "http://localhost:80"]
interval: 1m
timeout: 10s
retries: 3
start_period: 1m
networks:
- "{{ docker_swarm_public_network_name }}"
volumes:
- data:/var/www/shaarli/data
- cache:/var/www/shaarli/cache
volumes:
data:
cache:
networks:
"{{ docker_swarm_public_network_name }}":
external: true

View 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"
}
]
}
]
}

View file

@ -0,0 +1,7 @@
---
stack_name: shaarli
stack_image: "shaarli/shaarli"
stack_compose: "{{ lookup('template', 'docker-stack.yml.j2') | from_yaml }}"