Add the Affine playbook

This commit is contained in:
tanshu committed 2026-10-18 21:35:52 +05:30
1 parent a9ac51bd43
commit 34cb4aa3dc
8 files changed
+164

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
server {
listen 80;
server_name {{ http_host }};
# set max upload size
client_max_body_size 10G;
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive" always;
add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always;
proxy_pass http://localhost:{{ host_port }};
}
}
+13
View File
@@ -0,0 +1,13 @@
#################################################
# Setup Overleaf
#################################################
---
- hosts: monoco
become: true
vars_files:
- vars/default.yml
roles:
# - affine-migration
- affine
# - caddy
View File
Whitespace-only changes.
@@ -0,0 +1,44 @@
---
# Tasks for Sharelatex role
- name: Pull Affine migration image
docker_image:
name: "{{ migration_image }}"
source: pull
force_source: yes
- name: Ensure Affine Storage Directory exists
file:
path: "/var/lib/{{ host_directory }}/storage"
state: directory
mode: 0755
- name: Ensure Affine Config Directory exists
file:
path: "/var/lib/{{ host_directory }}/config"
state: directory
mode: 0755
- name: Ensure 'affine' Docker network exists
docker_network:
name: "{{ docker_network }}"
state: present
connected:
- "{{ postgres_container }}"
- "{{ redis_container }}"
- name: Create Affine migration container
docker_container:
name: "{{ migration_container }}"
image: "{{ migration_image }}"
state: started
restart_policy: "no"
command: "sh -c node ./scripts/self-host-predeploy.js"
env:
REDIS_SERVER_HOST: "{{ redis_container }}"
DATABASE_URL: "{{ db_url }}"
AFFINE_INDEXER_ENABLED: "false"
volumes:
- "/var/lib/{{ host_directory }}/storage:/root/.affine/storage"
- "/var/lib/{{ host_directory }}/config:/root/.affine/config"
networks:
- name: "{{ docker_network }}"
+30
View File
@@ -0,0 +1,30 @@
---
# Tasks for Affine role
- name: Pull Affine image
docker_image:
name: "{{ docker_image }}"
source: pull
force_source: yes
- name: Create Affine container
docker_container:
name: "{{ docker_container }}"
image: "{{ docker_image }}"
state: started
restart_policy: "unless-stopped"
env:
REDIS_SERVER_HOST: "{{ redis_container }}"
DATABASE_URL: "{{ db_url }}"
AFFINE_INDEXER_ENABLED: "false"
volumes:
- "/var/lib/{{ host_directory }}/storage:/root/.affine/storage"
- "/var/lib/{{ host_directory }}/config:/root/.affine/config"
networks:
- name: "{{ docker_network }}"
- name: Add caddy to the 'affine' network
docker_network:
name: "{{ docker_network }}"
connected:
- name: "{{ caddy_container }}"
appends: yes
+7
View File
@@ -0,0 +1,7 @@
---
# Handlers for Nginx role
- name: Restart caddy container
docker_container:
name: "{{ caddy_container }}"
state: started
restart: true
+22
View File
@@ -0,0 +1,22 @@
---
- name: Read current Caddyfile
ansible.builtin.slurp:
path: "{{ caddyfile_path }}"
register: caddyfile_raw
- name: Decode Caddyfile content
set_fact:
caddyfile_content: "{{ caddyfile_raw['content'] | b64decode }}"
- name: Check if snippet already exists
set_fact:
snippet_present: "{{ snippet_block in caddyfile_content }}"
- name: Add snippet if missing
ansible.builtin.blockinfile:
path: "{{ caddyfile_path }}"
marker: "# {mark} Ansible managed Caddy snippet for {{ host }}"
block: "{{ snippet_block }}"
create: yes
when: not snippet_present
notify: Restart caddy container
+28
View File
@@ -0,0 +1,28 @@
---
host: "wiki.tanshu.com"
revision: stable
docker_image: "ghcr.io/toeverything/affine-graphql:{{ revision }}"
docker_container: affine
docker_network: "{{ docker_container }}_net"
migration_image: "ghcr.io/toeverything/affine-graphql:{{ revision }}"
migration_container: affine-migration
postgres_container: postgres
redis_container: valkey
db_name: "affine"
db_username: "postgres"
db_password: "123456"
db_url: "postgresql://{{ db_username }}:{{ db_password }}@{{ postgres_container }}:5432/{{ db_name }}"
host_directory: affine
# Caddy configuration
caddy_container: caddy
caddyfile_path: /var/lib/caddy/conf/Caddyfile
snippet_block: |
{{ host }} {
reverse_proxy {{ docker_container }}:3010
}