summaryrefslogtreecommitdiff
path: root/roles/apps/wikijs
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2023-01-20 20:52:25 +0100
committerChristian Pointner <equinox@spreadspace.org>2023-01-20 20:52:25 +0100
commit68e89c48a709514dd4fb1bb8be159e78d52670f4 (patch)
tree23c573467ddca5e39f546863c640d21fd4de3d15 /roles/apps/wikijs
parentsync nextcloud version with deployed instances (diff)
apps: add wiki.js
Diffstat (limited to 'roles/apps/wikijs')
-rw-r--r--roles/apps/wikijs/defaults/main.yml20
-rw-r--r--roles/apps/wikijs/tasks/main.yml85
-rw-r--r--roles/apps/wikijs/templates/pod-spec.yml.j252
3 files changed, 157 insertions, 0 deletions
diff --git a/roles/apps/wikijs/defaults/main.yml b/roles/apps/wikijs/defaults/main.yml
new file mode 100644
index 00000000..04c9c1f6
--- /dev/null
+++ b/roles/apps/wikijs/defaults/main.yml
@@ -0,0 +1,20 @@
+---
+wikijs_db_uid: "901"
+wikijs_db_gid: "901"
+
+# wikijs_base_path: /srv/wikijs
+
+# wikijs_zfs:
+# pool: storage
+# name: wikijs
+# properties:
+# compression: lz4
+
+# wikijs_instances:
+# example:
+# version: 2.5.295
+# port: 8050
+# hostname: wiki.example.com
+# database:
+# version: 15.1
+# password: secret
diff --git a/roles/apps/wikijs/tasks/main.yml b/roles/apps/wikijs/tasks/main.yml
new file mode 100644
index 00000000..e2b03d24
--- /dev/null
+++ b/roles/apps/wikijs/tasks/main.yml
@@ -0,0 +1,85 @@
+---
+- name: create zfs datasets
+ when: wikijs_zfs is defined
+ block:
+ - name: create zfs base dataset
+ zfs:
+ name: "{{ wikijs_zfs.pool }}/{{ wikijs_zfs.name }}"
+ state: present
+ extra_zfs_properties: "{{ wikijs_zfs.properties | dehumanize_zfs_properties | default(omit) }}"
+
+ - name: create zfs volumes for instances
+ loop: "{{ wikijs_instances | dict2items }}"
+ loop_control:
+ label: "{{ item.key }} ({{ (item.value.zfs_properties | default({})).items() | map('join', '=') | join(', ') }})"
+ zfs:
+ name: "{{ wikijs_zfs.pool }}/{{ wikijs_zfs.name }}/{{ item.key }}"
+ state: present
+ extra_zfs_properties: "{{ item.value.zfs_properties | dehumanize_zfs_properties | default(omit) }}"
+
+ - name: configure wikijs base bath
+ set_fact:
+ wikijs_base_path: "{{ (zfs_pools[wikijs_zfs.pool].mountpoint, wikijs_zfs.name) | path_join }}"
+
+
+- name: create instance subdirectories
+ when: wikijs_zfs is not defined
+ loop: "{{ wikijs_instances | list }}"
+ file:
+ path: "{{ wikijs_base_path }}/{{ item }}"
+ state: directory
+
+
+- name: add group for wikijs db
+ group:
+ name: wikijs-db
+ gid: "{{ wikijs_db_gid }}"
+
+- name: add user for wikijs db
+ user:
+ name: wikijs-db
+ uid: "{{ wikijs_db_uid }}"
+ group: wikijs-db
+ password: "!"
+
+- name: create wikijs database subdirectory
+ loop: "{{ wikijs_instances | dict2items}}"
+ loop_control:
+ label: "{{ item.key }}"
+ file:
+ path: "{{ wikijs_base_path }}/{{ item.key }}/postgres"
+ owner: "{{ wikijs_db_uid }}"
+ group: "{{ wikijs_db_gid }}"
+ state: directory
+
+
+- name: install pod manifest
+ loop: "{{ wikijs_instances | dict2items }}"
+ loop_control:
+ label: "{{ item.key }}"
+ vars:
+ kubernetes_standalone_pod:
+ name: "wikijs-{{ item.key }}"
+ spec: "{{ lookup('template', 'pod-spec.yml.j2') }}"
+ mode: "0600"
+ include_role:
+ name: kubernetes/standalone/pod
+
+- name: configure nginx vhost
+ loop: "{{ wikijs_instances | dict2items }}"
+ loop_control:
+ label: "{{ item.key }}"
+ vars:
+ nginx_vhost:
+ name: "wikijs-{{ item.key }}"
+ template: generic
+ acme: true
+ hostnames:
+ - "{{ item.value.hostname }}"
+ locations:
+ '/':
+ proxy_pass: "http://127.0.0.1:{{ item.value.port }}"
+ extra_directives: |-
+ client_max_body_size 0;
+ include_role:
+ name: nginx/vhost
diff --git a/roles/apps/wikijs/templates/pod-spec.yml.j2 b/roles/apps/wikijs/templates/pod-spec.yml.j2
new file mode 100644
index 00000000..448a1413
--- /dev/null
+++ b/roles/apps/wikijs/templates/pod-spec.yml.j2
@@ -0,0 +1,52 @@
+securityContext:
+ allowPrivilegeEscalation: false
+terminationGracePeriodSeconds: 120
+containers:
+- name: wiki
+ image: "requarks/wiki:{{ item.value.version }}"
+ resources:
+ limits:
+ memory: "1Gi"
+ env:
+ - name: "DB_TYPE"
+ value: "postgres"
+ - name: "DB_HOST"
+ value: "127.0.0.1"
+ - name: "DB_PORT"
+ value: "5432"
+ - name: "DB_NAME"
+ value: "wiki"
+ - name: "DB_USER"
+ value: "wikijs"
+ - name: "DB_PASS"
+ value: "{{ item.value.database.password }}"
+ ports:
+ - containerPort: 3000
+ hostPort: {{ item.value.port }}
+ hostIP: 127.0.0.1
+
+- name: postgresql
+ image: "postgres:{{ item.value.database.version }}"
+ args:
+ - postgres
+ - -c
+ - listen_addresses=127.0.0.1
+ securityContext:
+ runAsUser: {{ wikijs_db_uid }}
+ runAsGroup: {{ wikijs_db_gid }}
+ env:
+ - name: "POSTGRES_DB"
+ value: "wiki"
+ - name: "POSTGRES_USER"
+ value: "wikijs"
+ - name: "POSTGRES_PASSWORD"
+ value: "{{ item.value.database.password }}"
+ volumeMounts:
+ - name: postgres
+ mountPath: /var/lib/postgresql/data
+
+volumes:
+- name: postgres
+ hostPath:
+ path: "{{ wikijs_base_path }}/{{ item.key }}/postgres"
+ type: Directory