Skip to content

Commit

Permalink
⬆️ Update affine
Browse files Browse the repository at this point in the history
  • Loading branch information
anarion80 committed Jan 14, 2025
1 parent d8d6994 commit cd6861e
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 8 deletions.
6 changes: 5 additions & 1 deletion roles/affine/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ affine_network_name: "affine"
affine_memory: 1g
affine_db_memory: 1g
affine_redis_memory: 1g
affine_migration_memory: 1g

# docker
affine_container_name: affine
affine_image_name: "ghcr.io/toeverything/affine-graphql"
affine_image_version: stable
affine_migration_container_name: affine_migration_job
affine_migration_image_name: "ghcr.io/toeverything/affine-graphql"
affine_migration_image_version: stable
affine_db_container_name: affine-db
affine_db_image_name: postgres
affine_db_image_version: latest
affine_db_image_version: 16
affine_redis_container_name: affine-redis
affine_redis_image_name: redis
affine_redis_image_version: latest
Expand Down
1 change: 1 addition & 0 deletions roles/affine/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ provisioner:
group_vars:
all:
affine_enabled: true
affine_data_directory: /tmp/affine
83 changes: 76 additions & 7 deletions roles/affine/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,70 @@
restart_policy: always
memory: "{{ affine_db_memory }}"
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U affine']
test: ['CMD', 'pg_isready', '-U', '{{ affine_postgres_user }}', '-d', '{{ affine_postgres_db }}']
interval: 10s
timeout: 5s
retries: 5

- name: Wait until the DB is initialized and healthy
community.docker.docker_container_info:
name: "{{ affine_db_container_name }}"
register: result
until: result.container.State.Health.Status == "healthy"
retries: 20
delay: 30

- name: Create Affine Migration Docker Container
community.docker.docker_container:
container_default_behavior: no_defaults
name: "{{ affine_migration_container_name }}"
image: "{{ affine_migration_image_name }}:{{ affine_migration_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 }}"
command:
['sh', '-c', 'node ./scripts/self-host-predeploy.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_postgres_db }}"
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 }}"
DB_USERNAME: "{{ affine_postgres_user }}"
DB_PASSWORD: "{{ affine_postgres_password }}"
DB_DATABASE: "{{ affine_postgres_db }}"
# /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: no
memory: "{{ affine_migration_memory }}"
labels:
traefik.enable: "false"
tags: molecule-idempotence-notest

- name: Pause for 60 seconds to wait for DB to be initialized
ansible.builtin.pause:
seconds: 60
tags: molecule-idempotence-notest

- name: Create Affine Docker Container
community.docker.docker_container:
container_default_behavior: no_defaults
Expand All @@ -80,11 +139,11 @@
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"
# 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_postgres_db }}"
NODE_ENV: "production"
AFFINE_ADMIN_EMAIL: "{{ affine_admin_email }}"
AFFINE_ADMIN_PASSWORD: "{{ affine_admin_password }}"
Expand All @@ -96,9 +155,12 @@
MAILER_USER: "{{ affine_mailer_user }}"
MAILER_PASSWORD: "{{ affine_mailer_password }}"
MAILER_SENDER: "{{ affine_mailer_sender }}"
DB_USERNAME: "{{ affine_postgres_user }}"
DB_PASSWORD: "{{ affine_postgres_password }}"
DB_DATABASE: "{{ affine_postgres_db }}"
# 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 }}"
TELEMETRY_ENABLE: "{{ affine_telemetry_enable }}"
restart_policy: unless-stopped
memory: "{{ affine_memory }}"
labels:
Expand All @@ -108,6 +170,13 @@
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"

- name: Delete Affine Migration Container
community.docker.docker_container:
name: "{{ affine_migration_container_name }}"
state: absent
tags: molecule-idempotence-notest

when: affine_enabled is true

- name: Stop Affine
Expand Down

0 comments on commit cd6861e

Please sign in to comment.