Tonne of updates
This commit is contained in:
15
bunker-ops/roles/changemaker/tasks/backup.yml
Normal file
15
bunker-ops/roles/changemaker/tasks/backup.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
# Configure automated backup cron job
|
||||
|
||||
- name: Ensure backup script is executable
|
||||
ansible.builtin.file:
|
||||
path: "{{ cml_deploy_path }}/scripts/backup.sh"
|
||||
mode: "0755"
|
||||
|
||||
- name: Configure daily backup cron
|
||||
ansible.builtin.cron:
|
||||
name: "changemaker-lite-backup"
|
||||
minute: "{{ cml_backup_cron_minute }}"
|
||||
hour: "{{ cml_backup_cron_hour }}"
|
||||
job: "cd {{ cml_deploy_path }} && ./scripts/backup.sh{% if cml_backup_s3_enabled %} --s3{% endif %} --retention {{ cml_backup_retention_days }} >> {{ cml_deploy_path }}/logs/backup.log 2>&1"
|
||||
user: "{{ ansible_user }}"
|
||||
21
bunker-ops/roles/changemaker/tasks/clone.yml
Normal file
21
bunker-ops/roles/changemaker/tasks/clone.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
# Clone or update the Changemaker Lite repository
|
||||
|
||||
- name: Ensure deploy directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ cml_deploy_path }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: Clone repository
|
||||
ansible.builtin.git:
|
||||
repo: "{{ cml_repo_url }}"
|
||||
dest: "{{ cml_deploy_path }}"
|
||||
version: "{{ cml_repo_branch }}"
|
||||
force: false
|
||||
update: true
|
||||
register: git_result
|
||||
|
||||
- name: Show git status
|
||||
ansible.builtin.debug:
|
||||
msg: "Repository {{ 'updated' if git_result.changed else 'unchanged' }} at {{ git_result.after[:8] | default('unknown') }}"
|
||||
54
bunker-ops/roles/changemaker/tasks/deploy.yml
Normal file
54
bunker-ops/roles/changemaker/tasks/deploy.yml
Normal file
@@ -0,0 +1,54 @@
|
||||
---
|
||||
# Deploy Docker Compose stack
|
||||
|
||||
- name: Pull latest images
|
||||
ansible.builtin.command:
|
||||
cmd: docker compose pull
|
||||
chdir: "{{ cml_deploy_path }}"
|
||||
changed_when: true
|
||||
tags: [pull]
|
||||
|
||||
- name: Build custom images
|
||||
ansible.builtin.command:
|
||||
cmd: docker compose build --no-cache
|
||||
chdir: "{{ cml_deploy_path }}"
|
||||
changed_when: true
|
||||
tags: [build]
|
||||
|
||||
- name: Start core services
|
||||
ansible.builtin.command:
|
||||
cmd: docker compose up -d --remove-orphans
|
||||
chdir: "{{ cml_deploy_path }}"
|
||||
changed_when: true
|
||||
|
||||
- name: Wait for PostgreSQL to be ready
|
||||
ansible.builtin.command:
|
||||
cmd: docker compose exec -T v2-postgres pg_isready -U {{ cml_v2_postgres_user }}
|
||||
chdir: "{{ cml_deploy_path }}"
|
||||
register: pg_ready
|
||||
retries: 15
|
||||
delay: 2
|
||||
until: pg_ready.rc == 0
|
||||
changed_when: false
|
||||
|
||||
- name: Run Prisma migrations
|
||||
ansible.builtin.command:
|
||||
cmd: docker compose exec -T api npx prisma migrate deploy
|
||||
chdir: "{{ cml_deploy_path }}"
|
||||
register: migrate_result
|
||||
changed_when: "'applied' in migrate_result.stdout"
|
||||
|
||||
- name: Run database seed (first deploy only)
|
||||
ansible.builtin.command:
|
||||
cmd: docker compose exec -T api npx prisma db seed
|
||||
chdir: "{{ cml_deploy_path }}"
|
||||
register: seed_result
|
||||
changed_when: "'created' in seed_result.stdout"
|
||||
failed_when: false
|
||||
|
||||
- name: Start monitoring services (if enabled)
|
||||
ansible.builtin.command:
|
||||
cmd: docker compose --profile monitoring up -d
|
||||
chdir: "{{ cml_deploy_path }}"
|
||||
when: cml_monitoring_enabled | bool
|
||||
changed_when: true
|
||||
20
bunker-ops/roles/changemaker/tasks/dirs.yml
Normal file
20
bunker-ops/roles/changemaker/tasks/dirs.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
# Create all directories required by Docker containers
|
||||
|
||||
- name: Create required directories
|
||||
ansible.builtin.file:
|
||||
path: "{{ cml_deploy_path }}/{{ item }}"
|
||||
state: directory
|
||||
mode: "0775"
|
||||
loop: "{{ cml_required_dirs }}"
|
||||
|
||||
- name: Ensure .gitkeep files exist
|
||||
ansible.builtin.copy:
|
||||
content: ""
|
||||
dest: "{{ cml_deploy_path }}/{{ item }}/.gitkeep"
|
||||
force: false
|
||||
mode: "0644"
|
||||
loop:
|
||||
- configs/code-server/.config
|
||||
- configs/code-server/.local
|
||||
- configs/homepage/logs
|
||||
14
bunker-ops/roles/changemaker/tasks/env.yml
Normal file
14
bunker-ops/roles/changemaker/tasks/env.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
# Generate .env from Jinja2 template (replaces config.sh)
|
||||
|
||||
- name: Generate .env file
|
||||
ansible.builtin.template:
|
||||
src: env.j2
|
||||
dest: "{{ cml_deploy_path }}/.env"
|
||||
mode: "0600"
|
||||
backup: true
|
||||
register: env_result
|
||||
|
||||
- name: Report .env status
|
||||
ansible.builtin.debug:
|
||||
msg: ".env {{ 'updated' if env_result.changed else 'unchanged' }}"
|
||||
38
bunker-ops/roles/changemaker/tasks/health.yml
Normal file
38
bunker-ops/roles/changemaker/tasks/health.yml
Normal file
@@ -0,0 +1,38 @@
|
||||
---
|
||||
# Post-deploy health checks
|
||||
|
||||
- name: Wait for API to respond
|
||||
ansible.builtin.uri:
|
||||
url: "http://localhost:{{ cml_api_port }}/api/health"
|
||||
method: GET
|
||||
status_code: 200
|
||||
timeout: 5
|
||||
register: api_health
|
||||
retries: 15
|
||||
delay: 3
|
||||
until: api_health.status == 200
|
||||
|
||||
- name: Wait for Admin GUI to respond
|
||||
ansible.builtin.uri:
|
||||
url: "http://localhost:{{ cml_admin_port }}"
|
||||
method: GET
|
||||
status_code: 200
|
||||
timeout: 5
|
||||
register: admin_health
|
||||
retries: 10
|
||||
delay: 3
|
||||
until: admin_health.status == 200
|
||||
|
||||
- name: Check container health
|
||||
ansible.builtin.command:
|
||||
cmd: docker compose ps --format json
|
||||
chdir: "{{ cml_deploy_path }}"
|
||||
register: compose_ps
|
||||
changed_when: false
|
||||
|
||||
- name: Report deployment status
|
||||
ansible.builtin.debug:
|
||||
msg: |
|
||||
Deployment health check:
|
||||
API: {{ 'OK' if api_health.status == 200 else 'FAILED' }}
|
||||
Admin: {{ 'OK' if admin_health.status == 200 else 'FAILED' }}
|
||||
30
bunker-ops/roles/changemaker/tasks/main.yml
Normal file
30
bunker-ops/roles/changemaker/tasks/main.yml
Normal file
@@ -0,0 +1,30 @@
|
||||
---
|
||||
# Changemaker role — Full deployment orchestration
|
||||
|
||||
- name: Clone/update repository
|
||||
ansible.builtin.include_tasks: clone.yml
|
||||
tags: [clone, deploy]
|
||||
|
||||
- name: Create required directories
|
||||
ansible.builtin.include_tasks: dirs.yml
|
||||
tags: [dirs, deploy]
|
||||
|
||||
- name: Generate .env configuration
|
||||
ansible.builtin.include_tasks: env.yml
|
||||
tags: [env, configure, deploy]
|
||||
|
||||
- name: Generate Homepage services.yaml
|
||||
ansible.builtin.include_tasks: services.yml
|
||||
tags: [services, configure, deploy]
|
||||
|
||||
- name: Deploy Docker stack
|
||||
ansible.builtin.include_tasks: deploy.yml
|
||||
tags: [deploy]
|
||||
|
||||
- name: Run health checks
|
||||
ansible.builtin.include_tasks: health.yml
|
||||
tags: [health, deploy]
|
||||
|
||||
- name: Configure backup cron
|
||||
ansible.builtin.include_tasks: backup.yml
|
||||
tags: [backup, deploy]
|
||||
14
bunker-ops/roles/changemaker/tasks/services.yml
Normal file
14
bunker-ops/roles/changemaker/tasks/services.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
# Generate Homepage services.yaml from template
|
||||
|
||||
- name: Ensure Homepage config directory exists
|
||||
ansible.builtin.file:
|
||||
path: "{{ cml_deploy_path }}/configs/homepage"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: Generate Homepage services.yaml
|
||||
ansible.builtin.template:
|
||||
src: services.yaml.j2
|
||||
dest: "{{ cml_deploy_path }}/configs/homepage/services.yaml"
|
||||
mode: "0644"
|
||||
Reference in New Issue
Block a user