multica deployment
This commit is contained in:
1 parent
63c5f7eed7
commit
39e2b87941
26 files changed
+2746
-394
No files matched your search
@@ -0,0 +1,88 @@
|
||||
---
|
||||
- name: Create Multica install directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ multica_install_dir }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: Clone / update Multica repository
|
||||
ansible.builtin.git:
|
||||
repo: "{{ multica_repo_url }}"
|
||||
dest: "{{ multica_install_dir }}"
|
||||
version: "{{ multica_version }}"
|
||||
update: "{{ multica_git_update }}"
|
||||
force: false
|
||||
register: _multica_git
|
||||
|
||||
# Optional: dump Postgres before touching a stack that is already running
|
||||
- name: Back up Postgres before changes
|
||||
when:
|
||||
- multica_backup_enabled | bool
|
||||
- _multica_compose_stat.stat.exists
|
||||
- (_multica_ps.stdout | default('') | length) > 0
|
||||
block:
|
||||
- name: Create backup directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ multica_backup_dir }}"
|
||||
state: directory
|
||||
mode: "0700"
|
||||
|
||||
- name: Gather date facts
|
||||
ansible.builtin.setup:
|
||||
gather_subset: [date_time]
|
||||
|
||||
- name: Dump database (redirect to file first so pg_dump's exit status counts)
|
||||
ansible.builtin.shell: >-
|
||||
docker compose -p {{ multica_compose_project }} -f {{ _multica_compose_file }}
|
||||
exec -T postgres pg_dump -U {{ multica_postgres_user }} {{ multica_postgres_db }}
|
||||
> {{ multica_backup_dir }}/multica-{{ ansible_date_time.iso8601_basic_short }}.sql
|
||||
&& gzip {{ multica_backup_dir }}/multica-{{ ansible_date_time.iso8601_basic_short }}.sql
|
||||
args:
|
||||
chdir: "{{ multica_install_dir }}"
|
||||
changed_when: true
|
||||
|
||||
# `make selfhost` only creates .env when missing; we do the same, then manage specific keys.
|
||||
- name: Create .env from .env.example (first run only)
|
||||
ansible.builtin.copy:
|
||||
src: "{{ multica_install_dir }}/.env.example"
|
||||
dest: "{{ multica_install_dir }}/.env"
|
||||
remote_src: true
|
||||
force: false
|
||||
mode: "0600"
|
||||
|
||||
- name: Set managed keys in .env
|
||||
ansible.builtin.lineinfile:
|
||||
path: "{{ multica_install_dir }}/.env"
|
||||
regexp: "^{{ item.key }}="
|
||||
line: "{{ item.key }}={{ item.value }}"
|
||||
mode: "0600"
|
||||
loop: "{{ _multica_env | dict2items }}"
|
||||
loop_control:
|
||||
label: "{{ item.key }}"
|
||||
no_log: "{{ multica_no_log }}"
|
||||
|
||||
# Compose re-reads .env and recreates containers whose config changed (equivalent of `up -d`).
|
||||
- name: Start / update Multica stack
|
||||
community.docker.docker_compose_v2:
|
||||
project_name: "{{ multica_compose_project }}"
|
||||
project_src: "{{ multica_install_dir }}"
|
||||
files:
|
||||
- "{{ _multica_compose_file }}"
|
||||
state: present
|
||||
pull: "{{ 'always' if multica_pull_latest | bool else 'missing' }}"
|
||||
recreate: auto
|
||||
register: _multica_up
|
||||
|
||||
- name: Wait for backend /readyz (db + migrations ok)
|
||||
ansible.builtin.uri:
|
||||
url: "http://127.0.0.1:{{ _multica_backend_port }}/readyz"
|
||||
return_content: true
|
||||
status_code: 200
|
||||
register: _multica_ready
|
||||
until: >-
|
||||
_multica_ready.status == 200 and
|
||||
(_multica_ready.json.checks.db | default('')) == 'ok' and
|
||||
(_multica_ready.json.checks.migrations | default('')) == 'ok'
|
||||
retries: 30
|
||||
delay: 5
|
||||
changed_when: false
|
||||
Reference in new issue
Block a user