mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-03 00:08:22 +00:00
feat(akaunting): multi-replica HA via one-shot install service
Swarm: deploy N replicas without AKAUNTING_SETUP, run install exactly once in a one-shot swarm job (scale 0 -> install -> scale N), marker-gated. The one-shot runs akaunting.sh with AKAUNTING_SETUP=true and --no-start so it installs then exits 0. Compose: single container self-installs via AKAUNTING_SETUP. SESSION_DRIVER=database keeps sessions consistent across replicas. Repeated lookups extracted to vars; run_once core guard split (main -> 01_core -> 02_swarm). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
42781f113d
commit
b94ffdaded
6 files changed
+118
-31
No files matched your search
@@ -0,0 +1,37 @@
|
||||
---
|
||||
- include_tasks: utils/once/flag.yml
|
||||
|
||||
- name: "🔎 Akaunting | Check if first run (marker exists?)"
|
||||
ansible.builtin.stat:
|
||||
path: "{{ AKAUNTING_SETUP_MARKER }}"
|
||||
register: akaunting_marker_stat
|
||||
|
||||
- name: "🤔 Akaunting | Decide if setup should be enabled"
|
||||
ansible.builtin.set_fact:
|
||||
akaunting_setup_enabled: "{{ not akaunting_marker_stat.stat.exists }}"
|
||||
|
||||
- name: "🧩 For '{{ application_id }}': load docker, db and proxy"
|
||||
include_role:
|
||||
name: sys-stk-full
|
||||
vars:
|
||||
compose_repository_url: "{{ AKAUNTING_REPOSITORY }}"
|
||||
compose_repository_pull: true
|
||||
compose_repository_ref: "{{ AKAUNTING_REF }}"
|
||||
compose_handlers_flush: true
|
||||
|
||||
- when:
|
||||
- akaunting_setup_enabled | bool
|
||||
- IS_STACK_HOST | bool
|
||||
block:
|
||||
- name: "▶️ Akaunting | First-run install one-shot (swarm)"
|
||||
ansible.builtin.include_tasks:
|
||||
file: 02_swarm.yml
|
||||
apply:
|
||||
delegate_to: "{{ STACK_HOST }}"
|
||||
when: DEPLOYMENT_MODE == 'swarm'
|
||||
|
||||
- name: "📁 Akaunting | Create first-run marker to disable future setup"
|
||||
ansible.builtin.file:
|
||||
path: "{{ AKAUNTING_SETUP_MARKER }}"
|
||||
state: touch
|
||||
mode: "0644"
|
||||
@@ -0,0 +1,70 @@
|
||||
---
|
||||
- name: "📏 Akaunting setup | Scale akaunting service to 0 replicas"
|
||||
ansible.builtin.shell: >
|
||||
container service update --detach --replicas 0
|
||||
{{ AKAUNTING_SERVICE | quote }}
|
||||
changed_when: true
|
||||
|
||||
- name: "⏳ Akaunting setup | Wait until no running task remains"
|
||||
ansible.builtin.shell: |
|
||||
container service ps {{ AKAUNTING_SERVICE | quote }} \
|
||||
--filter desired-state=running \
|
||||
--format '{{ "{{.CurrentState}}" }}' | wc -l | grep -qE '^\s*0\s*$'
|
||||
register: akaunting_swarm_drained
|
||||
changed_when: false
|
||||
retries: 60
|
||||
delay: 5
|
||||
until: akaunting_swarm_drained.rc == 0
|
||||
|
||||
- name: "▶️ Akaunting setup | Run one-shot install job (--no-start → akaunting.sh installs, then exits instead of serving)"
|
||||
ansible.builtin.shell: |
|
||||
set -euo pipefail
|
||||
JOB={{ AKAUNTING_SETUP_JOB | quote }}
|
||||
container service rm "$JOB" 2>/dev/null || true
|
||||
container service create --detach --restart-condition none --name "$JOB" \
|
||||
--constraint node.role==manager \
|
||||
--env-file {{ lookup('container', application_id, 'files.env') | quote }} \
|
||||
--env AKAUNTING_SETUP=true \
|
||||
--network {{ application_id | get_entity_name | quote }} \
|
||||
{% if lookup('database', application_id, 'shared') | bool %}--network {{ lookup('database', application_id, 'network') | quote }} {% endif %}\
|
||||
{{ AKAUNTING_IMAGE }}:{{ AKAUNTING_VERSION }} \
|
||||
--no-start
|
||||
changed_when: true
|
||||
|
||||
- name: "⏳ Akaunting setup | Wait for install job to complete"
|
||||
ansible.builtin.shell: |
|
||||
container service ps {{ AKAUNTING_SETUP_JOB }} \
|
||||
--no-trunc \
|
||||
--format '{{ "{{.CurrentState}}" }}' \
|
||||
| head -1 | grep -qE '^(Complete|Shutdown)'
|
||||
register: akaunting_setup_done
|
||||
changed_when: false
|
||||
retries: 60
|
||||
delay: 5
|
||||
until: akaunting_setup_done.rc == 0
|
||||
|
||||
- name: "🗑️ Akaunting setup | Remove one-shot install service"
|
||||
ansible.builtin.shell: >
|
||||
container service rm
|
||||
{{ AKAUNTING_SETUP_JOB }}
|
||||
changed_when: true
|
||||
failed_when: false
|
||||
|
||||
- name: "📏 Akaunting setup | Scale akaunting back to nominal replicas"
|
||||
ansible.builtin.shell: >
|
||||
container service update --detach --replicas {{ AKAUNTING_REPLICAS }}
|
||||
{{ AKAUNTING_SERVICE | quote }}
|
||||
changed_when: true
|
||||
|
||||
- name: "⏳ Akaunting setup | Wait until replicas converge X/X"
|
||||
ansible.builtin.shell: |
|
||||
set -euo pipefail
|
||||
SVC={{ AKAUNTING_SERVICE | quote }}
|
||||
WANT={{ AKAUNTING_REPLICAS }}/{{ AKAUNTING_REPLICAS }}
|
||||
got="$(container service ls --filter name="$SVC" --format '{{ "{{.Replicas}}" }}' | head -1)"
|
||||
test "$got" = "$WANT"
|
||||
register: akaunting_replicas_converged
|
||||
changed_when: false
|
||||
retries: 60
|
||||
delay: 5
|
||||
until: akaunting_replicas_converged.rc == 0
|
||||
@@ -1,27 +1,3 @@
|
||||
---
|
||||
- name: "🔎 Akaunting | Check if first run (marker exists?)"
|
||||
ansible.builtin.stat:
|
||||
path: "{{ AKAUNTING_SETUP_MARKER }}"
|
||||
register: akaunting_marker_stat
|
||||
|
||||
- name: "🤔 Akaunting | Decide if setup should be enabled"
|
||||
ansible.builtin.set_fact:
|
||||
akaunting_setup_enabled: "{{ not akaunting_marker_stat.stat.exists }}"
|
||||
|
||||
- name: "🧩 For '{{ application_id }}': load docker, db and proxy"
|
||||
include_role:
|
||||
name: sys-stk-full
|
||||
vars:
|
||||
compose_repository_url: "{{ AKAUNTING_REPOSITORY }}"
|
||||
compose_repository_pull: true
|
||||
compose_repository_ref: "{{ AKAUNTING_REF }}"
|
||||
compose_handlers_flush: true
|
||||
|
||||
- name: "📁 Akaunting | Create first-run marker to disable future setup"
|
||||
ansible.builtin.file:
|
||||
path: "{{ AKAUNTING_SETUP_MARKER }}"
|
||||
state: touch
|
||||
mode: "0644"
|
||||
when:
|
||||
- akaunting_setup_enabled | bool
|
||||
- IS_STACK_HOST | bool
|
||||
- include_tasks: 01_core.yml
|
||||
when: run_once_web_app_akaunting is not defined
|
||||
@@ -11,10 +11,6 @@
|
||||
{{ lookup('compose_only', 'pull_policy', 'never') }}
|
||||
{{ lookup('container_ports', ['akaunting', 'http', DOCKER_BIND_HOST]) | indent(4) }}
|
||||
{{ lookup('container_volumes', application_id, 'akaunting') | indent(4) }}
|
||||
{% if akaunting_setup_enabled | bool %}
|
||||
environment:
|
||||
- AKAUNTING_SETUP=true
|
||||
{% endif %}
|
||||
{% include 'roles/sys-svc-container/templates/healthcheck/tcp.yml.j2' %}
|
||||
{{ lookup('container_networks') | indent(4) }}
|
||||
{{ lookup('container_depends_on', application_id) | indent(4) }}
|
||||
|
||||
@@ -23,6 +23,9 @@ TRUSTED_PROXIES=*
|
||||
TRUSTED_HEADERS=X_FORWARDED_FOR,X_FORWARDED_HOST,X_FORWARDED_PORT,X_FORWARDED_PROTO
|
||||
|
||||
# These define the first company to exist on this instance. They are only used during setup.
|
||||
{% if akaunting_setup_enabled | bool and DEPLOYMENT_MODE == 'compose' %}
|
||||
AKAUNTING_SETUP=true
|
||||
{% endif %}
|
||||
COMPANY_NAME={{ AKAUNTING_COMPANY_NAME }}
|
||||
COMPANY_EMAIL={{ AKAUNTING_COMPANY_EMAIL }}
|
||||
|
||||
@@ -35,7 +38,7 @@ ADMIN_PASSWORD={{ AKAUNTING_ADMIN_PASSWORD | dotenv_quote }}
|
||||
|
||||
# Cache
|
||||
CACHE_DRIVER={{ AKAUNTING_CACHE_DRIVER }}
|
||||
SESSION_DRIVER={{ AKAUNTING_CACHE_DRIVER }}
|
||||
SESSION_DRIVER={{ 'redis' if AKAUNTING_CACHE_DRIVER == 'redis' else 'database' }}
|
||||
QUEUE_CONNECTION={{ 'sync' if AKAUNTING_CACHE_DRIVER == 'file' else AKAUNTING_CACHE_DRIVER }}
|
||||
{% if AKAUNTING_CACHE_DRIVER == 'redis' %}
|
||||
REDIS_CLIENT=phpredis
|
||||
|
||||
@@ -4,6 +4,8 @@ application_id: "web-app-akaunting"
|
||||
database_password: "{{ lookup('config', application_id, 'credentials.database_password') }}" # nocheck: lookup-config-path
|
||||
|
||||
AKAUNTING_URL: "{{ lookup('tls', application_id, 'url.base') }}"
|
||||
AKAUNTING_IMAGE: "{{ lookup('config', application_id, 'services.akaunting.image') }}"
|
||||
AKAUNTING_VERSION: "{{ lookup('config', application_id, 'services.akaunting.version') }}"
|
||||
AKAUNTING_REPOSITORY: "{{ lookup('config', application_id, 'services.akaunting.repository') }}"
|
||||
AKAUNTING_REF: "{{ lookup('config', application_id, 'services.akaunting.ref') }}"
|
||||
AKAUNTING_CONTAINER: "{{ lookup('config', application_id, 'services.akaunting.name') }}"
|
||||
@@ -13,6 +15,9 @@ AKAUNTING_COMPANY_EMAIL: "{{ lookup('config', application_id, 'services.akauntin
|
||||
AKAUNTING_ADMIN_EMAIL: "{{ lookup('config', application_id, 'services.akaunting.setup_admin_email') }}"
|
||||
AKAUNTING_ADMIN_PASSWORD: "{{ lookup('config', application_id, 'credentials.setup_admin_password') }}"
|
||||
AKAUNTING_SETUP_MARKER: "{{ [ (AKAUNTING_VOLUME | docker_volume_path), '.akaunting_installed' ] | path_join }}"
|
||||
AKAUNTING_SERVICE: "{{ lookup('container_service', application_id, 'akaunting') }}"
|
||||
AKAUNTING_SETUP_JOB: "{{ AKAUNTING_SERVICE }}_setup"
|
||||
AKAUNTING_REPLICAS: "{{ groups[application_id] | length }}"
|
||||
AKAUNTING_APP_KEY: "{{ lookup('config', application_id, 'credentials.app_key') }}"
|
||||
AKAUNTING_CACHE_DRIVER: "{{ 'redis' if lookup('config',application_id, 'services.redis.enabled') else 'file' }}"
|
||||
|
||||
|
||||
Reference in new issue
Block a user