Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add Affine #121

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ If you have a spare domain name you can configure applications to be accessible

* [Activepieces](https://www.activepieces.com/) - an open source all-in-one automation tool
* [Admidio](https://www.admidio.org/) - a free online membership management
* [Affine](https://github.com/toeverything/AFFiNE) - a next-gen knowledge base that brings planning, sorting and creating all together
* [Airsonic](https://airsonic.github.io/) - catalog and stream music
* [Authelia](https://www.authelia.com/) - The Single Sign-On Multi-Factor portal for web apps
* [Authentik](https://goauthentik.io/) - an open-source Identity Provider focused on flexibility and versatility
Expand Down
4 changes: 4 additions & 0 deletions nas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
tags:
- admidio

- role: affine
tags:
- affine

- role: airsonic
tags:
- airsonic
Expand Down
53 changes: 53 additions & 0 deletions roles/affine/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
affine_enabled: false
affine_available_externally: false

# directories
affine_data_directory: "{{ docker_home }}/affine"

# network
affine_port_a: "3016"
affine_port_b: "5555"
affine_hostname: "affine"
affine_network_name: "affine"

# specs
affine_memory: 1g
affine_db_memory: 1g
affine_redis_memory: 1g

# docker
affine_container_name: affine
affine_image_name: "ghcr.io/toeverything/affine-graphql"
affine_image_version: stable
affine_db_container_name: affine-db
affine_db_image_name: postgres
affine_db_image_version: latest
affine_redis_container_name: affine-redis
affine_redis_image_name: redis
affine_redis_image_version: latest
affine_user_id: "1000"
affine_group_id: "1000"

# affine
affine_postgres_user: affine
affine_postgres_password: affine
affine_postgres_db: "affine"
affine_node_options: "--import=./scripts/register.js"
affine_config_path: "/root/.affine/config"
affine_admin_email: "affine@{{ ansible_nas_domain }}"
affine_admin_password: "changeme"
affine_telemetry_enable: "false"
affine_redis_server_host: "{{ affine_redis_container_name }}"
affine_redis_server_port: "6379"
affine_redis_server_user: "redis"
affine_redis_server_password: "redis"
affine_redis_server_database: "0" # Redis server database (0-20 number only)
affine_server_host: "{{ affine_hostname }}.{{ ansible_nas_domain }}"
affine_server_port: "3010"
affine_server_https: "true"
affine_mailer_host: ""
affine_mailer_port: ""
affine_mailer_user: ""
affine_mailer_password: ""
affine_mailer_sender: ""
11 changes: 11 additions & 0 deletions roles/affine/docs/affine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Affine

Homepage: [https://github.com/toeverything/AFFiNE](https://github.com/toeverything/AFFiNE)

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

## Usage

Set `affine_enabled: true` in your `inventories/<your_inventory>/group_vars/nas.yml` file.

affine web interface can be found at [http://ansible_nas_host_or_ip:3016](http://ansible_nas_host_or_ip:3016).
6 changes: 6 additions & 0 deletions roles/affine/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
provisioner:
inventory:
group_vars:
all:
affine_enabled: true
10 changes: 10 additions & 0 deletions roles/affine/molecule/default/side_effect.yml
Original file line number Diff line number Diff line change
@@ -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:
affine_enabled: false
33 changes: 33 additions & 0 deletions roles/affine/molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Include vars
ansible.builtin.include_vars:
file: ../../defaults/main.yml

- name: Get affine redis container state
community.docker.docker_container:
name: "{{ affine_redis_container_name }}"
register: result_redis

- name: Get affine db container state
community.docker.docker_container:
name: "{{ affine_db_container_name }}"
register: result_db

- name: Get affine container state
community.docker.docker_container:
name: "{{ affine_container_name }}"
register: result

- name: Check if affine containers are running
ansible.builtin.assert:
that:
- result_redis.container['State']['Status'] == "running"
- result_redis.container['State']['Restarting'] == false
- result_db.container['State']['Status'] == "running"
- result_db.container['State']['Restarting'] == false
- result.container['State']['Status'] == "running"
- result.container['State']['Restarting'] == false
33 changes: 33 additions & 0 deletions roles/affine/molecule/default/verify_stopped.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- 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 affine redis
community.docker.docker_container:
name: "{{ affine_db_container_name }}"
state: absent
register: result_redis

- name: Try and stop and remove affine db
community.docker.docker_container:
name: "{{ affine_db_container_name }}"
state: absent
register: result_db

- name: Try and stop and remove affine
community.docker.docker_container:
name: "{{ affine_container_name }}"
state: absent
register: result

- name: Check if affine is stopped
ansible.builtin.assert:
that:
- not result_redis.changed
- not result_db.changed
- not result.changed
1 change: 1 addition & 0 deletions roles/affine/requirements.yml
129 changes: 129 additions & 0 deletions roles/affine/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
- name: Start Affine
block:
- name: Create Affine Directories
ansible.builtin.file:
path: "{{ item }}"
state: directory
with_items:
- "{{ affine_data_directory }}"

- name: Create Affine network
community.docker.docker_network:
name: "{{ affine_network_name }}"

- name: Create Affine Redis Docker Container
community.docker.docker_container:
name: "{{ affine_redis_container_name }}"
image: "{{ affine_redis_image_name }}:{{ affine_redis_image_version }}"
pull: true
volumes:
- "{{ affine_data_directory }}/redis:/data:rw"
networks:
- name: "{{ affine_network_name }}"
network_mode: "{{ affine_network_name }}"
container_default_behavior: no_defaults
labels:
traefik.enable: "false"
restart_policy: always
memory: "{{ affine_redis_memory }}"
healthcheck:
test: ['CMD', 'redis-cli', '--raw', 'incr', 'ping']
interval: 10s
timeout: 5s
retries: 5

- name: Create Affine Db Docker Container
community.docker.docker_container:
name: "{{ affine_db_container_name }}"
image: "{{ affine_db_image_name }}:{{ affine_db_image_version }}"
pull: true
volumes:
- "{{ affine_data_directory }}/postgres:/var/lib/postgresql/data:rw"
networks:
- name: "{{ affine_network_name }}"
network_mode: "{{ affine_network_name }}"
container_default_behavior: no_defaults
env:
POSTGRES_USER: "{{ affine_postgres_user }}"
POSTGRES_PASSWORD: "{{ affine_postgres_password }}"
POSTGRES_DB: "{{ affine_postgres_db }}"
PGDATA: /var/lib/postgresql/data/pgdata
labels:
traefik.enable: "false"
restart_policy: always
memory: "{{ affine_db_memory }}"
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U affine']
interval: 10s
timeout: 5s
retries: 5

- name: Create Affine Docker Container
community.docker.docker_container:
container_default_behavior: no_defaults
name: "{{ affine_container_name }}"
image: "{{ affine_image_name }}:{{ affine_image_version }}"
pull: true
volumes:
- "{{ affine_data_directory }}/config:/root/.affine/config:rw"
- "{{ affine_data_directory }}/storage:/root/.affine/storage:rw"
networks:
- name: "{{ affine_network_name }}"
network_mode: "{{ affine_network_name }}"
ports:
- "{{ affine_port_a }}:3010"
- "{{ affine_port_b }}:5555"
command:
['sh', '-c', 'node ./scripts/self-host-predeploy && node ./dist/index.js']
env:
NODE_OPTIONS: "{{ affine_node_options }}"
AFFINE_CONFIG_PATH: "{{ affine_config_path }}"
REDIS_SERVER_HOST: "{{ affine_redis_server_host }}"
REDIS_SERVER_PORT: "{{ affine_redis_server_port }}"
REDIS_SERVER_USER: "{{ affine_redis_server_user }}"
REDIS_SERVER_PASSWORD: "{{ affine_redis_server_password }}"
REDIS_SERVER_DATABASE: "{{ affine_redis_server_database }}"
DATABASE_URL: "postgres://{{ affine_postgres_user }}:{{ affine_postgres_password }}@{{ affine_db_container_name }}:5432/affine"
NODE_ENV: "production"
AFFINE_ADMIN_EMAIL: "{{ affine_admin_email }}"
AFFINE_ADMIN_PASSWORD: "{{ affine_admin_password }}"
AFFINE_SERVER_HOST: "{{ affine_server_host }}"
AFFINE_SERVER_PORT: "{{ affine_server_port }}"
AFFINE_SERVER_HTTPS: "{{ affine_server_https }}"
MAILER_HOST: "{{ affine_mailer_host }}"
MAILER_PORT: "{{ affine_mailer_port }}"
MAILER_USER: "{{ affine_mailer_user }}"
MAILER_PASSWORD: "{{ affine_mailer_password }}"
MAILER_SENDER: "{{ affine_mailer_sender }}"
# Telemetry allows us to collect data on how you use the affine. This data will helps us improve the app and provide better features.
# Uncomment next line if you wish to quit telemetry.
# TELEMETRY_ENABLE: "{{ affine_telemetry_enable }}"
restart_policy: unless-stopped
memory: "{{ affine_memory }}"
labels:
traefik.enable: "{{ affine_available_externally | string }}"
traefik.http.routers.affine.rule: "Host(`{{ affine_hostname }}.{{ ansible_nas_domain }}`)"
traefik.http.routers.affine.tls.certresolver: "letsencrypt"
traefik.http.routers.affine.tls.domains[0].main: "{{ ansible_nas_domain }}"
traefik.http.routers.affine.tls.domains[0].sans: "*.{{ ansible_nas_domain }}"
traefik.http.services.affine.loadbalancer.server.port: "3010"
when: affine_enabled is true

- name: Stop Affine
block:
- name: Stop Affine redis
community.docker.docker_container:
name: "{{ affine_redis_container_name }}"
state: absent

- name: Stop Affine db
community.docker.docker_container:
name: "{{ affine_db_container_name }}"
state: absent

- name: Stop Affine
community.docker.docker_container:
name: "{{ affine_container_name }}"
state: absent
when: affine_enabled is false
14 changes: 14 additions & 0 deletions website/docs/applications/content-management/affine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: "Affine"
description: "A next-gen knowledge base that brings planning, sorting and creating all together"
---

Homepage: [https://github.com/toeverything/AFFiNE](https://github.com/toeverything/AFFiNE)

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

## Usage

Set `affine_enabled: true` in your `inventories/<your_inventory>/group_vars/nas.yml` file.

affine web interface can be found at [http://ansible_nas_host_or_ip:3016](http://ansible_nas_host_or_ip:3016).