Skip to content

Commit fa06063

Browse files
authored
Merge pull request #739 from wmudge/feature/couchdb
Add CouchDB
2 parents 4d17250 + 22aaf4a commit fa06063

File tree

8 files changed

+146
-0
lines changed

8 files changed

+146
-0
lines changed

nas.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
tags:
9090
- cloudflare_ddns
9191

92+
- role: couchdb
93+
tags:
94+
- couchdb
95+
9296
- role: code-server
9397
tags:
9498
- code-server

roles/couchdb/defaults/main.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
couchdb_enabled: false
3+
couchdb_available_externally: false
4+
5+
# Data directory for config and data directories
6+
couchdb_data_directory: "{{ docker_home }}/couchdb"
7+
8+
# CouchDB local admin user
9+
couchdb_admin_user: "admin"
10+
couchdb_admin_password: "changeme"
11+
12+
# network
13+
couchdb_hostname: "couchdb"
14+
couchdb_port: "5984"
15+
16+
# specs
17+
couchdb_memory: 1024MB
18+
19+
# docker
20+
couchdb_container_name: "couchdb"
21+
couchdb_image_name: "couchdb"
22+
couchdb_image_version: "latest"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
provisioner:
3+
inventory:
4+
group_vars:
5+
all:
6+
couchdb_enabled: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: Stop
3+
hosts: all
4+
become: true
5+
tasks:
6+
- name: "Include {{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }} role"
7+
ansible.builtin.include_role:
8+
name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"
9+
vars:
10+
couchdb_enabled: false
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
- name: Verify
3+
hosts: all
4+
gather_facts: false
5+
tasks:
6+
- ansible.builtin.include_vars:
7+
file: ../../defaults/main.yml
8+
9+
- name: Get container state
10+
community.docker.docker_container_info:
11+
name: "{{ couchdb_container_name }}"
12+
register: result
13+
14+
- name: Check CouchDB is running
15+
ansible.builtin.assert:
16+
that:
17+
- result.container['State']['Status'] == "running"
18+
- result.container['State']['Restarting'] == false
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
- name: Verify
3+
hosts: all
4+
gather_facts: false
5+
tasks:
6+
- ansible.builtin.include_vars:
7+
file: ../../defaults/main.yml
8+
9+
- name: Stop and remove CouchDB
10+
community.docker.docker_container:
11+
name: "{{ couchdb_container_name }}"
12+
state: absent
13+
register: result
14+
15+
- name: Check CouchDB is stopped
16+
ansible.builtin.assert:
17+
that:
18+
- not result.changed

roles/couchdb/tasks/main.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
- name: Start CouchDB
3+
block:
4+
- name: Create CouchDB Directories
5+
ansible.builtin.file:
6+
path: "{{ item }}"
7+
state: directory
8+
with_items:
9+
- "{{ couchdb_data_directory }}/config"
10+
- "{{ couchdb_data_directory }}/data"
11+
12+
- name: CouchDB Container
13+
community.docker.docker_container:
14+
name: "{{ couchdb_container_name }}"
15+
image: "{{ couchdb_image_name }}:{{ couchdb_image_version }}"
16+
pull: true
17+
env:
18+
COUCHDB_USER: "{{ couchdb_admin_user }}"
19+
COUCHDB_PASSWORD: "{{ couchdb_admin_password }}"
20+
ports:
21+
- "{{ couchdb_port }}:5984"
22+
volumes:
23+
- "{{ couchdb_data_directory }}/config:/opt/couchdb/etc/local.d"
24+
- "{{ couchdb_data_directory }}/data:/opt/couchdb/data"
25+
restart_policy: unless-stopped
26+
memory: "{{ couchdb_memory }}"
27+
labels:
28+
traefik.enable: "{{ couchdb_available_externally | string }}"
29+
traefik.http.routers.couchdb.rule: "Host(`{{ couchdb_hostname }}.{{ ansible_nas_domain }}`)"
30+
traefik.http.routers.couchdb.tls.certresolver: "letsencrypt"
31+
traefik.http.routers.couchdb.tls.domains[0].main: "{{ ansible_nas_domain }}"
32+
traefik.http.routers.couchdb.tls.domains[0].sans: "*.{{ ansible_nas_domain }}"
33+
traefik.http.services.couchdb.loadbalancer.server.port: "5984"
34+
when: couchdb_enabled is true
35+
36+
- name: Stop CouchDB
37+
block:
38+
- name: Stop CouchDB
39+
community.docker.docker_container:
40+
name: "{{ couchdb_container_name }}"
41+
state: absent
42+
when: couchdb_enabled is false
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: "CouchDB"
3+
---
4+
5+
Homepage: [https://couchdb.apache.org/](https://couchdb.apache.org/)
6+
7+
Apache CouchDB is an open-source, document-oriented NoSQL database, implemented in Erlang.
8+
9+
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.
10+
11+
## Usage
12+
13+
Set `couchdb_enabled: true` in your `inventories/<your_inventory>/group_vars/nas.yml` file.
14+
15+
Tread carefully.
16+
17+
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)
18+
19+
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.
20+
21+
| Parameter | Default |
22+
| --- | --- |
23+
| `couchdb_admin_user` | `admin` |
24+
| `couchdb_admin_password` | `changeme` |
25+
26+
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.

0 commit comments

Comments
 (0)