From 22aaf4ad030d241b5e2829ea1a231a95cf04c9c6 Mon Sep 17 00:00:00 2001 From: Webster Mudge Date: Sun, 15 Dec 2024 11:16:56 -0500 Subject: [PATCH] Add Apache CouchDB (single-node) Signed-off-by: Webster Mudge --- nas.yml | 4 ++ roles/couchdb/defaults/main.yml | 22 ++++++++++ roles/couchdb/molecule/default/molecule.yml | 6 +++ .../couchdb/molecule/default/side_effect.yml | 10 +++++ roles/couchdb/molecule/default/verify.yml | 18 ++++++++ .../molecule/default/verify_stopped.yml | 18 ++++++++ roles/couchdb/tasks/main.yml | 42 +++++++++++++++++++ website/docs/applications/other/couchdb.md | 26 ++++++++++++ 8 files changed, 146 insertions(+) create mode 100644 roles/couchdb/defaults/main.yml create mode 100644 roles/couchdb/molecule/default/molecule.yml create mode 100644 roles/couchdb/molecule/default/side_effect.yml create mode 100644 roles/couchdb/molecule/default/verify.yml create mode 100644 roles/couchdb/molecule/default/verify_stopped.yml create mode 100644 roles/couchdb/tasks/main.yml create mode 100644 website/docs/applications/other/couchdb.md diff --git a/nas.yml b/nas.yml index 9f2bf3695..0bf64d683 100644 --- a/nas.yml +++ b/nas.yml @@ -89,6 +89,10 @@ tags: - cloudflare_ddns + - role: couchdb + tags: + - couchdb + - role: code-server tags: - code-server diff --git a/roles/couchdb/defaults/main.yml b/roles/couchdb/defaults/main.yml new file mode 100644 index 000000000..14bfd1384 --- /dev/null +++ b/roles/couchdb/defaults/main.yml @@ -0,0 +1,22 @@ +--- +couchdb_enabled: false +couchdb_available_externally: false + +# Data directory for config and data directories +couchdb_data_directory: "{{ docker_home }}/couchdb" + +# CouchDB local admin user +couchdb_admin_user: "admin" +couchdb_admin_password: "changeme" + +# network +couchdb_hostname: "couchdb" +couchdb_port: "5984" + +# specs +couchdb_memory: 1024MB + +# docker +couchdb_container_name: "couchdb" +couchdb_image_name: "couchdb" +couchdb_image_version: "latest" diff --git a/roles/couchdb/molecule/default/molecule.yml b/roles/couchdb/molecule/default/molecule.yml new file mode 100644 index 000000000..e9df8b324 --- /dev/null +++ b/roles/couchdb/molecule/default/molecule.yml @@ -0,0 +1,6 @@ +--- +provisioner: + inventory: + group_vars: + all: + couchdb_enabled: true diff --git a/roles/couchdb/molecule/default/side_effect.yml b/roles/couchdb/molecule/default/side_effect.yml new file mode 100644 index 000000000..447d7f728 --- /dev/null +++ b/roles/couchdb/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: + couchdb_enabled: false diff --git a/roles/couchdb/molecule/default/verify.yml b/roles/couchdb/molecule/default/verify.yml new file mode 100644 index 000000000..6021416a0 --- /dev/null +++ b/roles/couchdb/molecule/default/verify.yml @@ -0,0 +1,18 @@ +--- +- name: Verify + hosts: all + gather_facts: false + tasks: + - ansible.builtin.include_vars: + file: ../../defaults/main.yml + + - name: Get container state + community.docker.docker_container_info: + name: "{{ couchdb_container_name }}" + register: result + + - name: Check CouchDB is running + ansible.builtin.assert: + that: + - result.container['State']['Status'] == "running" + - result.container['State']['Restarting'] == false diff --git a/roles/couchdb/molecule/default/verify_stopped.yml b/roles/couchdb/molecule/default/verify_stopped.yml new file mode 100644 index 000000000..54ad5ae6b --- /dev/null +++ b/roles/couchdb/molecule/default/verify_stopped.yml @@ -0,0 +1,18 @@ +--- +- name: Verify + hosts: all + gather_facts: false + tasks: + - ansible.builtin.include_vars: + file: ../../defaults/main.yml + + - name: Stop and remove CouchDB + community.docker.docker_container: + name: "{{ couchdb_container_name }}" + state: absent + register: result + + - name: Check CouchDB is stopped + ansible.builtin.assert: + that: + - not result.changed diff --git a/roles/couchdb/tasks/main.yml b/roles/couchdb/tasks/main.yml new file mode 100644 index 000000000..baa030501 --- /dev/null +++ b/roles/couchdb/tasks/main.yml @@ -0,0 +1,42 @@ +--- +- name: Start CouchDB + block: + - name: Create CouchDB Directories + ansible.builtin.file: + path: "{{ item }}" + state: directory + with_items: + - "{{ couchdb_data_directory }}/config" + - "{{ couchdb_data_directory }}/data" + + - name: CouchDB Container + community.docker.docker_container: + name: "{{ couchdb_container_name }}" + image: "{{ couchdb_image_name }}:{{ couchdb_image_version }}" + pull: true + env: + COUCHDB_USER: "{{ couchdb_admin_user }}" + COUCHDB_PASSWORD: "{{ couchdb_admin_password }}" + ports: + - "{{ couchdb_port }}:5984" + volumes: + - "{{ couchdb_data_directory }}/config:/opt/couchdb/etc/local.d" + - "{{ couchdb_data_directory }}/data:/opt/couchdb/data" + restart_policy: unless-stopped + memory: "{{ couchdb_memory }}" + labels: + traefik.enable: "{{ couchdb_available_externally | string }}" + traefik.http.routers.couchdb.rule: "Host(`{{ couchdb_hostname }}.{{ ansible_nas_domain }}`)" + traefik.http.routers.couchdb.tls.certresolver: "letsencrypt" + traefik.http.routers.couchdb.tls.domains[0].main: "{{ ansible_nas_domain }}" + traefik.http.routers.couchdb.tls.domains[0].sans: "*.{{ ansible_nas_domain }}" + traefik.http.services.couchdb.loadbalancer.server.port: "5984" + when: couchdb_enabled is true + +- name: Stop CouchDB + block: + - name: Stop CouchDB + community.docker.docker_container: + name: "{{ couchdb_container_name }}" + state: absent + when: couchdb_enabled is false diff --git a/website/docs/applications/other/couchdb.md b/website/docs/applications/other/couchdb.md new file mode 100644 index 000000000..2e2ce9a1c --- /dev/null +++ b/website/docs/applications/other/couchdb.md @@ -0,0 +1,26 @@ +--- +title: "CouchDB" +--- + +Homepage: [https://couchdb.apache.org/](https://couchdb.apache.org/) + +Apache CouchDB is an open-source, document-oriented NoSQL database, implemented in Erlang. + +CouchDB uses multiple formats and protocols to store, transfer, and process its data. It uses JSON to store data, JavaScript as its query language using MapReduce, and HTTP for an API. + +## Usage + +Set `couchdb_enabled: true` in your `inventories//group_vars/nas.yml` file. + +Tread carefully. + +The CouchDB API can be found at [http://ansible_nas_host_or_ip:5984](http://ansible_nas_host_or_ip:5984). Its web interface, Fauxton, is located at [http://ansible_nas_host_or_ip:5984/_utils](http://ansible_nas_host_or_ip:5984/_utils) + +You must specify the default adminstrator username and password, but all other configuration -- **including authentication and authorization** -- is left to either files in the `config` directory or subsequent API calls. Read more about setup and configuration on the [Apache CouchDB documentation](https://docs.couchdb.org/en/stable/index.html) site. + +| Parameter | Default | +| --- | --- | +| `couchdb_admin_user` | `admin` | +| `couchdb_admin_password` | `changeme` | + +The contents of the `config` directory are mounted to the container's `local.d` directory; see the [Configuration files](https://docs.couchdb.org/en/stable/config/intro.html#configuration-files) documentation.