From cd6861eca9ad9493997a83fdfd764431bc615a93 Mon Sep 17 00:00:00 2001 From: Anarion Dunedain Date: Tue, 14 Jan 2025 13:12:32 +0100 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Update=20affine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roles/affine/defaults/main.yml | 6 +- roles/affine/molecule/default/molecule.yml | 1 + roles/affine/tasks/main.yml | 83 ++++++++++++++++++++-- 3 files changed, 82 insertions(+), 8 deletions(-) diff --git a/roles/affine/defaults/main.yml b/roles/affine/defaults/main.yml index e8429e3798..70392a1be2 100644 --- a/roles/affine/defaults/main.yml +++ b/roles/affine/defaults/main.yml @@ -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 diff --git a/roles/affine/molecule/default/molecule.yml b/roles/affine/molecule/default/molecule.yml index 3e336e7543..277a5b6214 100644 --- a/roles/affine/molecule/default/molecule.yml +++ b/roles/affine/molecule/default/molecule.yml @@ -4,3 +4,4 @@ provisioner: group_vars: all: affine_enabled: true + affine_data_directory: /tmp/affine diff --git a/roles/affine/tasks/main.yml b/roles/affine/tasks/main.yml index 95e04c9d79..6d73f91a8b 100644 --- a/roles/affine/tasks/main.yml +++ b/roles/affine/tasks/main.yml @@ -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 @@ -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 }}" @@ -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: @@ -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