---
- name: "π Find optional Dockerfile for {{ application_id }}"
set_fact:
dockerfile_src: >-
{{ lookup(
'first_found',
{
'files': [
application_id | abs_role_path_by_application_id ~ '/templates/Dockerfile.j2',
application_id | abs_role_path_by_application_id ~ '/files/Dockerfile'
]
},
errors='ignore'
) | default('', true)
}}
- name: "π Create (optional) Dockerfile for {{ application_id }}"
stack_host_template:
src: "{{ dockerfile_src }}"
dest: "{{ lookup('container', application_id, 'files.dockerfile') }}"
mode: "0640"
notify:
- compose-build
- compose-up
register: dockerfile_template
when:
- dockerfile_src | default('') | length > 0
- name: "π Create (optional) '{{ lookup('container', application_id, 'files.env') }}'"
stack_host_template:
src: "{{ item }}"
dest: "{{ lookup('container', application_id, 'files.env') }}"
mode: "0640"
force: true
notify:
- compose-up
- compose-build
with_first_found:
- files:
- "{{ application_id | abs_role_path_by_application_id }}/templates/env.j2"
- "{{ application_id | abs_role_path_by_application_id }}/files/env"
skip: true
register: env_template
- name: "π Create (optional) per-service env files for '{{ application_id }}'"
stack_host_template:
src: "{{ item }}"
dest: "{{ lookup('container', application_id, 'directories.env') }}{{ item | basename | regex_replace('\\.j2$', '.env') }}"
mode: "0640"
force: true
notify:
- compose-up
- compose-build
loop: "{{ query('fileglob', (application_id | abs_role_path_by_application_id) ~ '/templates/env/*.j2') }}"
loop_control:
label: "{{ item | basename }}"
- name: "π Create (optional) compose override for '{{ application_id }}'"
stack_host_template:
src: "{{ item }}"
dest: "{{ lookup('container', application_id, 'files.compose_override') }}"
mode: "0640"
force: true
notify: compose-up
with_first_found:
- files:
- "{{ application_id | abs_role_path_by_application_id }}/templates/compose.override.yml.j2"
- "{{ application_id | abs_role_path_by_application_id }}/files/compose.override.yml"
skip: true
register: compose_override_template
- name: "π Create (optional) '{{ lookup('container', application_id, 'files.compose') }}'"
stack_host_template:
src: "{{ item }}"
dest: "{{ lookup('container', application_id, 'files.compose') }}"
mode: "0640"
force: true
with_first_found:
- files:
- "compose.yml.j2"
skip: true
register: docker_compose_template
notify: compose-up
- name: "π¨ Refresh the build inputs of '{{ application_id }}'"
when: docker_compose_template is changed
block:
- name: "π Read the rendered compose file of '{{ application_id }}'"
ansible.builtin.slurp:
src: "{{ lookup('container', application_id, 'files.compose') }}"
delegate_to: "{{ STACK_HOST }}"
run_once: true
register: docker_compose_rendered
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
- name: "π¨ Record build inputs of '{{ application_id }}' to rebuild only on change"
stack_host_copy:
content: "{{ docker_compose_rendered.content | b64decode | docker_build_digest }}"
dest: "{{ [lookup('container', application_id, 'directories.instance'), '.build-inputs'] | path_join }}"
mode: "0640"
notify: compose-build
- name: "π Mark compose up pending for '{{ application_id }}' until it succeeds"
stack_host_copy:
content: ""
dest: "{{ COMPOSE_UP_PENDING_MARKER }}"
mode: "0640"
register: compose_up_marker
when:
- compose_mode == 'compose'
- dockerfile_template.changed or env_template.changed or compose_override_template.changed or docker_compose_template.changed