feat(cinny): add ansible role for container based cinny-web deployment

This commit is contained in:
Johanna Dorothea Reichmann 2023-06-04 14:02:31 +02:00
parent c374bfee68
commit a53a91fa71
No known key found for this signature in database
GPG key ID: 03624C433676E465
4 changed files with 133 additions and 0 deletions

View file

@ -0,0 +1,34 @@
---
cinny_user: "cinny"
cinny_version: "2.2.6"
cinny_base_path: "/opt/cinny"
cinny_config_file: "{{ cinny_base_path }}/config.json"
cinny_sources_path: "{{ cinny_base_path }}/src"
cinny_source_repo_url: "https://github.com/cinnyapp/cinny.git"
cinny_container_name: cinny
cinny_container_image_registry: "ghcr.io"
cinny_container_image_namespace: "cinnyapp/"
cinny_container_image_name: "cinny"
cinny_container_image_repository: >-
{{
(container_registries[cinny_container_image_registry]
| default(cinny_container_image_registry))
+ '/' + (cinny_container_image_namespace | default(''))
+ cinny_container_image_name
}}
cinny_container_image_reference: >-
{{ ((cinny_container_image_repository + ':')
if not cinny_container_image_build_local else '')
+ (cinny_container_image_tag | default('v' + cinny_version)) }}
cinny_container_image_build_local: false
cinny_container_labels: {}
cinny_container_volumes: []
cinny_container_combined_labels: >-
{{ cinny_container_preset_labels | combine(cinny_container_labels) }}
cinny_config_default_homeserver: ~
cinny_config_homeserver_list: []
cinny_config_allow_custom_homeservers: true
cinny_config: ~

View file

@ -0,0 +1,8 @@
---
- name: Ensure container for cinny is restarted
community.docker.docker_container:
name: "{{ cinny_container_name }}"
state: started
restart: true
listen: "restart-cinny"

View file

@ -0,0 +1,67 @@
---
- name: Ensure cinny user '{{ cinny_user }}' exists
ansible.builtin.user:
name: "{{ cinny_user }}"
state: present
system: true
register: cinny_user_info
- name: Ensure cinny host directories exist
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
owner: "{{ cinny_user_info.uid | default(cinny_user) }}"
group: "{{ cinny_user_info.group | default(cinny_user) }}"
mode: "{{ item.mode | default('0750') }}"
loop:
- path: "{{ cinny_base_path }}"
- path: "{{ cinny_sources_path }}"
- name: Ensure cinny sources are available
ansible.builtin.git:
repo: "{{ cinny_source_repo_url }}"
dest: "{{ cinny_sources_path }}"
version: "{{ cinny_container_image_tag | default('v' + cinny_version) }}"
accept_newhostkey: true
when: cinny_container_image_build_local
- name: Ensure cinny container image is present
community.docker.docker_image:
name: "{{ cinny_container_image_reference }}"
state: present
source: pull
force_source: "{{ cinny_container_image_tag | default(false, true) | bool }}"
when: not cinny_container_image_build_local
- name: Ensure cinny container image is built
community.docker.docker_image:
name: "{{ cinny_container_image_reference }}"
build:
path: "{{ cinny_sources_path }}"
state: present
source: build
when: cinny_container_image_build_local
- name: Ensure cinny config.json is up to date
ansible.builtin.copy:
content: "{{ cinny_config_complete | to_nice_json }}"
dest: "{{ cinny_config_file }}"
owner: "{{ cinny_user_info.uid | default(cinny_user) }}"
group: "{{ cinny_user_info.group | default(cinny_user) }}"
mode: "0644"
notify:
- restart-cinny
- name: Ensure cinny container named '{{ cinny_container_name }}' is running
community.docker.docker_container:
name: "{{ cinny_container_name }}"
image: "{{ cinny_container_image_reference }}"
env: "{{ cinny_container_env | default(omit, true) }}"
user: "{{ cinny_container_user | default(omit, true) }}"
ports: "{{ cinny_container_ports | default(omit, true) }}"
labels: "{{ cinny_container_combined_labels }}"
volumes: "{{ cinny_container_combined_volumes }}"
networks: "{{ cinny_container_networks | default(omit, true) }}"
purge_networks: "{{ cinny_container_purge_networks | default(omit, true) }}"
etc_hosts: "{{ cinny_container_etc_hosts | default(omit, true) }}"

24
roles/cinny/vars/main.yml Normal file
View file

@ -0,0 +1,24 @@
---
cinny_container_preset_labels:
version: "{{ cinny_container_image_tag | default('v' + cinny_user, true) }}"
cinny_config_from_defaults:
homeserverList: >-2
{{
([ cinny_config_default_homeserver ]
if cinny_config_default_homeserver else [])
+ cinny_config_homeserver_list | default([])
}}
allowCustomHomeservers: "{{ cinny_config_allow_custom_homeservers | bool }}"
cinny_config_complete: >-
{{
cinny_config_from_defaults
| combine({'defaultHomeserver': 0} if cinny_config_default_homeserver else {}, recursive=true)
| combine(cinny_config | default({}, true), recursive=true)
}}
cinny_container_preset_volumes:
- "{{ cinny_config_file }}:/usr/share/nginx/html/config.json:ro"
cinny_container_combined_volumes: >-
{{ cinny_container_preset_volumes + cinny_container_volumes }}