updates
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
---
|
||||
web_static_dir: "{{ apps_base_dir }}/web-static"
|
||||
web_static_image: nginx:alpine
|
||||
@@ -0,0 +1,57 @@
|
||||
---
|
||||
# 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([]) | 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
|
||||
|
||||
- name: web-static | start container
|
||||
ansible.builtin.command:
|
||||
cmd: "docker compose up -d --remove-orphans{{ ' --force-recreate' if (_compose_file 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 and _compose_file is not changed
|
||||
changed_when: true
|
||||
@@ -0,0 +1,12 @@
|
||||
# Managed by Ansible (roles/web-static). Do not edit by hand.
|
||||
services:
|
||||
web-static:
|
||||
image: {{ web_static_image }}
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
{% for a in _static_apps %}
|
||||
- "{{ a.port }}:{{ a.port }}"
|
||||
{% endfor %}
|
||||
volumes:
|
||||
- {{ web_static_root }}:{{ web_static_root }}:ro
|
||||
- ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
@@ -0,0 +1,19 @@
|
||||
# Managed by Ansible (roles/web-static). Do not edit by hand.
|
||||
{% for a in _static_apps %}
|
||||
server {
|
||||
listen {{ a.port }};
|
||||
server_name _;
|
||||
|
||||
root {{ (app_catalog[a.name].webroot_pattern | default(web_static_root ~ '/{env}_' ~ a.name)) | replace('{env}', a.env) }};
|
||||
index index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location ~* \.(?:js|css|woff2?|png|jpg|jpeg|gif|svg|ico)$ {
|
||||
expires 7d;
|
||||
add_header Cache-Control "public";
|
||||
}
|
||||
}
|
||||
{% endfor %}
|
||||
Reference in New Issue
Block a user