From 5c54c56cce43a3de22eae92a1479eae83cb38486 Mon Sep 17 00:00:00 2001 From: Anarion Date: Mon, 10 Jun 2024 18:23:37 +0200 Subject: [PATCH] :sparkles: Add Librum Server --- README.md | 1 + nas.yml | 4 + roles/librum/defaults/main.yml | 40 +++++++++ roles/librum/docs/librum.md | 11 +++ roles/librum/molecule/default/molecule.yml | 16 ++++ roles/librum/molecule/default/side_effect.yml | 10 +++ roles/librum/molecule/default/verify.yml | 26 ++++++ .../molecule/default/verify_stopped.yml | 26 ++++++ roles/librum/requirements.yml | 1 + roles/librum/tasks/main.yml | 89 +++++++++++++++++++ .../docs/applications/media-serving/librum.md | 14 +++ 11 files changed, 238 insertions(+) create mode 100644 roles/librum/defaults/main.yml create mode 100644 roles/librum/docs/librum.md create mode 100644 roles/librum/molecule/default/molecule.yml create mode 100644 roles/librum/molecule/default/side_effect.yml create mode 100644 roles/librum/molecule/default/verify.yml create mode 100644 roles/librum/molecule/default/verify_stopped.yml create mode 120000 roles/librum/requirements.yml create mode 100644 roles/librum/tasks/main.yml create mode 100644 website/docs/applications/media-serving/librum.md diff --git a/README.md b/README.md index 5b75bce108..024a7faeff 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,7 @@ If you have a spare domain name you can configure applications to be accessible * [Librephotos](https://github.com/LibrePhotos/librephotos) - self-hosted open source photo * [Librespeed](https://github.com/librespeed/speedtest) - Self-hosted Speedtest for HTML5 and more * [LibreTranslate](https://libretranslate.com/) - Free and Open Source Machine Translation API +* [Librum Server](https://github.com/Librum-Reader/Librum-Server) - A clean and powerful way to read and manage your e-books on any device * [Lidarr](https://github.com/lidarr/Lidarr) - Music collection manager for Usenet and BitTorrent users * [Light LDAP](https://github.com/lldap/lldap) - Light LDAP implementation * [Linkding](https://github.com/sissbruecker/linkding) - Self-hosted bookmark service diff --git a/nas.yml b/nas.yml index d6e6c7730b..2e56b53a39 100644 --- a/nas.yml +++ b/nas.yml @@ -425,6 +425,10 @@ tags: - libretranslate + - role: librum + tags: + - librum + - role: lidarr tags: - lidarr diff --git a/roles/librum/defaults/main.yml b/roles/librum/defaults/main.yml new file mode 100644 index 0000000000..d190f52b59 --- /dev/null +++ b/roles/librum/defaults/main.yml @@ -0,0 +1,40 @@ +--- +librum_enabled: false +librum_available_externally: false + +# directories +librum_data_directory: "{{ docker_home }}/librum" + +# network +librum_port: "5009" +librum_hostname: "librum" +librum_network_name: "librum" + +# specs +librum_memory: 1g +librum_db_memory: 1g + +# docker +librum_container_name: librum +librum_db_container_name: librum-db +librum_image_name: "ghcr.io/librum-reader/librum-server" +librum_image_version: "latest" +librum_db_image_name: "mariadb" +librum_db_image_version: latest +librum_user_id: "1000" +librum_group_id: "1000" + +librum_db_database: "librum" +librum_db_user: "librum" +librum_db_password: "librum" +librum_db_root_password: "supersecure" +librum_jwt_valid_issuer: exampleIssuer +librum_jwt_key: exampleOfALongSecretToken +librum_smtp_endpoint: "smtp.example.com:587" +librum_smtp_username: "mailuser123" +librum_smtp_password: "smtpUserPassword123" +librum_smtp_mail_from: "mailuser123@example.com" +librum_db_connection_string: "Server={{ librum_db_container_name }};port=3306;Database={{ librum_db_database }};Uid=root;Pwd={{ librum_db_root_password }};" +librum_admin_email: "admin@example.com" +librum_admin_password: "strongPassword123" +librum_open_ai_token: "" diff --git a/roles/librum/docs/librum.md b/roles/librum/docs/librum.md new file mode 100644 index 0000000000..3cd0abfeb1 --- /dev/null +++ b/roles/librum/docs/librum.md @@ -0,0 +1,11 @@ +# Librum Server + +Homepage: [https://github.com/Librum-Reader/Librum-Server](https://github.com/Librum-Reader/Librum-Server) + +A clean and powerful way to read and manage your e-books on any device. + +## Usage + +Set `librum_enabled: true` in your `inventories//group_vars/nas.yml` file. + +Librum web interface can be found at [http://ansible_nas_host_or_ip:5009](http://ansible_nas_host_or_ip:5009). diff --git a/roles/librum/molecule/default/molecule.yml b/roles/librum/molecule/default/molecule.yml new file mode 100644 index 0000000000..76f5189660 --- /dev/null +++ b/roles/librum/molecule/default/molecule.yml @@ -0,0 +1,16 @@ +--- +platforms: + - name: instance + image: geerlingguy/docker-ubuntu2204-ansible:latest + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + - /var/run/docker.sock:/var/run/docker.sock + - /tmp:/tmp:rw + privileged: true + pre_build_image: true +provisioner: + inventory: + group_vars: + all: + librum_enabled: true + librum_data_directory: "/tmp/librum" diff --git a/roles/librum/molecule/default/side_effect.yml b/roles/librum/molecule/default/side_effect.yml new file mode 100644 index 0000000000..c892ce5fe3 --- /dev/null +++ b/roles/librum/molecule/default/side_effect.yml @@ -0,0 +1,10 @@ +--- +- name: Stop + hosts: all + become: true + tasks: + - name: "Include {{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }} role" + ansible.builtin.include_role: + name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}" + vars: + librum_enabled: false diff --git a/roles/librum/molecule/default/verify.yml b/roles/librum/molecule/default/verify.yml new file mode 100644 index 0000000000..6640e78a81 --- /dev/null +++ b/roles/librum/molecule/default/verify.yml @@ -0,0 +1,26 @@ +--- +- name: Verify + hosts: all + gather_facts: false + tasks: + - name: Include vars + ansible.builtin.include_vars: + file: ../../defaults/main.yml + + - name: Get librum db container state + community.docker.docker_container: + name: "{{ librum_db_container_name }}" + register: result_db + + - name: Get librum container state + community.docker.docker_container: + name: "{{ librum_container_name }}" + register: result + + - name: Check if librum containers are running + ansible.builtin.assert: + that: + - result_db.container['State']['Status'] == "running" + - result_db.container['State']['Restarting'] == false + - result.container['State']['Status'] == "running" + - result.container['State']['Restarting'] == false diff --git a/roles/librum/molecule/default/verify_stopped.yml b/roles/librum/molecule/default/verify_stopped.yml new file mode 100644 index 0000000000..324a64cc9f --- /dev/null +++ b/roles/librum/molecule/default/verify_stopped.yml @@ -0,0 +1,26 @@ +--- +- name: Verify + hosts: all + gather_facts: false + tasks: + - name: Include vars + ansible.builtin.include_vars: + file: ../../defaults/main.yml + + - name: Try and stop and remove librum + community.docker.docker_container: + name: "{{ librum_container_name }}" + state: absent + register: result + + - name: Try and stop and remove librum db + community.docker.docker_container: + name: "{{ librum_db_container_name }}" + state: absent + register: result_db + + - name: Check if librum is stopped + ansible.builtin.assert: + that: + - not result.changed + - not result_db.changed diff --git a/roles/librum/requirements.yml b/roles/librum/requirements.yml new file mode 120000 index 0000000000..9a736435ab --- /dev/null +++ b/roles/librum/requirements.yml @@ -0,0 +1 @@ +../../requirements.yml \ No newline at end of file diff --git a/roles/librum/tasks/main.yml b/roles/librum/tasks/main.yml new file mode 100644 index 0000000000..1d67aceddb --- /dev/null +++ b/roles/librum/tasks/main.yml @@ -0,0 +1,89 @@ +--- +- name: Start Librum + block: + - name: Create Librum Directories + ansible.builtin.file: + path: "{{ item }}" + state: directory + owner: 999 + group: 999 + with_items: + - "{{ librum_data_directory }}" + - "{{ librum_data_directory }}/data" + + - name: Create Librum network + community.docker.docker_network: + name: "{{ librum_network_name }}" + + - name: Create Librum database container + community.docker.docker_container: + name: "{{ librum_db_container_name }}" + image: "{{ librum_db_image_name }}:{{ librum_db_image_version }}" + networks: + - name: "{{ librum_network_name }}" + network_mode: "{{ librum_network_name }}" + pull: true + volumes: + - "{{ librum_data_directory }}/mariadb_data:/var/lib/mysql" + env: + MARIADB_DATABASE: "{{ librum_db_database }}" + MARIADB_USER: "{{ librum_db_user }}" + MARIADB_PASSWORD: "{{ librum_db_password }}" + MARIADB_ROOT_PASSWORD: "{{ librum_db_root_password }}" + restart_policy: unless-stopped + memory: "{{ librum_db_memory }}" + labels: + traefik.enable: "false" + healthcheck: + test: ["CMD", "mariadb-admin", "ping", "-u", "root", "-p'{{ librum_db_root_password }}'", "-h", "localhost"] + interval: 20s + timeout: 40s + retries: 3 + start_period: 30s + + - name: Create Librum Docker Container + community.docker.docker_container: + name: "{{ librum_container_name }}" + image: "{{ librum_image_name }}:{{ librum_image_version }}" + networks: + - name: "{{ librum_network_name }}" + network_mode: "{{ librum_network_name }}" + pull: true + volumes: + - "{{ librum_data_directory }}/data:/var/lib/librum-server/librum_storage" + ports: + - "{{ librum_port }}:5000" + env: + JWTValidIssuer: "{{ librum_jwt_valid_issuer }}" + JWTKey: "{{ librum_jwt_key }}" + SMTPEndpoint: "{{ librum_smtp_endpoint }}" + SMTPUsername: "{{ librum_smtp_username }}" + SMTPPassword: "{{ librum_smtp_password }}" + SMTPMailFrom: "{{ librum_smtp_mail_from }}" + DBConnectionString: "{{ librum_db_connection_string }}" + AdminEmail: "{{ librum_admin_email }}" + AdminPassword: "{{ librum_admin_password }}" + # OpenAIToken: "{{ librum_open_ai_token }}" + restart_policy: unless-stopped + memory: "{{ librum_memory }}" + labels: + traefik.enable: "{{ librum_available_externally | string }}" + traefik.http.routers.librum.rule: "Host(`{{ librum_hostname }}.{{ ansible_nas_domain }}`)" + traefik.http.routers.librum.tls.certresolver: "letsencrypt" + traefik.http.routers.librum.tls.domains[0].main: "{{ ansible_nas_domain }}" + traefik.http.routers.librum.tls.domains[0].sans: "*.{{ ansible_nas_domain }}" + traefik.http.services.librum.loadbalancer.server.port: "5000" + when: librum_enabled is true + +- name: Stop Librum + block: + - name: Stop Librum + community.docker.docker_container: + name: "{{ librum_container_name }}" + state: absent + + - name: Stop Librum DB + community.docker.docker_container: + name: "{{ librum_db_container_name }}" + state: absent + when: librum_enabled is false diff --git a/website/docs/applications/media-serving/librum.md b/website/docs/applications/media-serving/librum.md new file mode 100644 index 0000000000..a966fbb080 --- /dev/null +++ b/website/docs/applications/media-serving/librum.md @@ -0,0 +1,14 @@ +--- +title: "Librum Server" +description: "A clean and powerful way to read and manage your e-books on any device." +--- + +Homepage: [https://github.com/Librum-Reader/Librum-Server](https://github.com/Librum-Reader/Librum-Server) + +The Librum-Server includes the API, database, and other fundamental infrastructure required for the "backend" of all Librum client applications and the website. + +## Usage + +Set `tooljet_enabled: true` in your `inventories//group_vars/nas.yml` file. + +Librum web interface can be found at [http://ansible_nas_host_or_ip:5009](http://ansible_nas_host_or_ip:5009).