Files
server-infra/roles/web-static/tasks/main.yml
T
westfarn 726ad971cb
Sync runner checkout / sync (push) Successful in 6s
Add stop.sh (compose down) and disable print_forge (#34)
## Summary
- Closes [#33](#33).
- Add `scripts/stop.sh` → `playbooks/stop-apps.yml` → `docker compose down` for one `--app` + `--env` (no `-v`; checkouts/secrets stay).
- `host_apps.enabled: false` skips deploy (including CI `--app`) so a stopped app cannot come back. Rows stay for ports and `stop.sh`.
- Disable `print_forge` beta + prod on all app hosts. After merge (or from this branch): `./scripts/stop.sh --app print_forge --env prod` and `--env beta`.

## Test plan
- [ ] `./scripts/stop.sh --help` shows required `--app` / `--env`
- [ ] `ansible-playbook playbooks/stop-apps.yml --syntax-check -e app=print_forge -e app_env=prod`
- [ ] `./scripts/stop.sh --app print_forge --env prod` compose-downs `print_forge_prod` on all webservers
- [ ] `./scripts/stop.sh --app print_forge --env beta` compose-downs `print_forge_beta` (including adama worker)
- [ ] `./scripts/deploy.sh --app print_forge --env prod --check` skips disabled rows (does not start containers)
- [ ] NPM: `print-forge-preview.aimloperations.com` will 502 until the proxy host is disabled (out of scope)

Reviewed-on: #34
2026-09-16 03:11:23 -07:00

86 lines
3.1 KiB
YAML

---
# Serves node/vite static builds (dta_webapp beta/prod) via a single nginx
# container. Skips itself on hosts that have no node-static apps.
- name: web-static | node-static app names
ansible.builtin.set_fact:
_node_names: "{{ app_catalog | dict2items | selectattr('value.type', 'equalto', 'node-static') | map(attribute='key') | list }}"
- name: web-static | this host's static apps
ansible.builtin.set_fact:
_static_apps: "{{ host_apps | default([]) | rejectattr('enabled', 'equalto', false) | selectattr('name', 'in', _node_names) | list }}"
- name: web-static | configure and run
when: _static_apps | length > 0
block:
- name: web-static | ensure project dir
ansible.builtin.file:
path: "{{ web_static_dir }}"
state: directory
owner: "{{ admin_user }}"
group: "{{ admin_user }}"
mode: "0750"
- name: web-static | nginx config
ansible.builtin.template:
src: nginx.conf.j2
dest: "{{ web_static_dir }}/nginx.conf"
owner: "{{ admin_user }}"
group: "{{ admin_user }}"
mode: "0644"
register: _nginx_conf
- name: web-static | compose file
ansible.builtin.template:
src: docker-compose.yml.j2
dest: "{{ web_static_dir }}/docker-compose.yml"
owner: "{{ admin_user }}"
group: "{{ admin_user }}"
mode: "0644"
register: _compose_file
# Free host ports before bind. Catches leftover/orphan containers from older
# compose projects that still publish 8080/8081/etc. Includes the current
# web-static container when present — compose up recreates it next.
- name: web-static | find containers publishing static ports
ansible.builtin.command:
cmd: docker ps -q --filter publish={{ item }}
loop: "{{ _static_apps | map(attribute='port') | list | unique }}"
register: _port_holders
changed_when: false
become: true
- name: web-static | unique container ids on static ports
ansible.builtin.set_fact:
_stale_port_cids: "{{ _port_holders.results | map(attribute='stdout_lines') | flatten | unique | list }}"
- name: web-static | remove containers holding static ports
ansible.builtin.command:
cmd: "docker rm -f {{ _stale_port_cids | join(' ') }}"
when: _stale_port_cids | length > 0
become: true
changed_when: true
register: _stale_port_rm
- name: web-static | start container
ansible.builtin.command:
cmd: >-
docker compose up -d --remove-orphans
{{ '--force-recreate' if (_compose_file is changed or (_stale_port_rm is changed)) else '' }}
chdir: "{{ web_static_dir }}"
become: true
become_user: "{{ admin_user }}"
changed_when: true
- name: web-static | reload nginx on config change
ansible.builtin.command:
cmd: "docker compose exec -T web-static nginx -s reload"
chdir: "{{ web_static_dir }}"
become: true
become_user: "{{ admin_user }}"
when:
- _nginx_conf is changed
- _compose_file is not changed
- _stale_port_rm is not changed
changed_when: true