02_build_context.ymlΒΆ

---
# Populate the Dockerfile build context with extracted scripts and
# config so files/Dockerfile can stay lean (just FROM + COPY + RUN).
# Filenames are read from MOODLE_BUILD_FILES (vars/main.yml) β€” a single
# spot consumed here AND referenced literally by the Dockerfile.

- name: "πŸ”§ Set fact: moodle compose dir"
  ansible.builtin.set_fact:
    _moodle_compose_dir: >-
      {{ docker_compose.directories.instance
         | default(lookup('container', application_id, 'directories.instance')) }}

- name: "πŸ”§ Set fact: moodle build context base"
  ansible.builtin.set_fact:
    _moodle_build_dir: "{{ [_moodle_compose_dir, MOODLE_BUILD_DIR] | path_join }}"

- name: "βœ… Ensure moodle build context dirs exist"
  ansible.builtin.file:
    path: "{{ item }}"
    state: directory
    mode: "0755"
  loop:
    - "{{ _moodle_build_dir }}"
    - "{{ [_moodle_build_dir, 'php-conf'] | path_join }}"
    - "{{ [_moodle_build_dir, 'install'] | path_join }}"
    - "{{ [_moodle_build_dir, 'patch'] | path_join }}"
    - "{{ [_moodle_build_dir, 'moodle'] | path_join }}"
    - "{{ [_moodle_build_dir, 'install', 'moodle'] | path_join }}"

- name: "πŸ“‹ Copy static build assets into compose context"
  ansible.builtin.copy:
    src: "{{ [MOODLE_BUILD_DIR, item.path] | path_join }}"
    dest: "{{ [_moodle_build_dir, item.path] | path_join }}"
    mode: "{{ item.mode }}"
  loop:
    - { path: "{{ MOODLE_BUILD_FILES.entrypoint }}", mode: "0755" }
    - { path: "{{ MOODLE_BUILD_FILES.release_lib }}", mode: "0644" }
    - { path: "{{ MOODLE_BUILD_FILES.config_php }}", mode: "0644" }
    - { path: "{{ MOODLE_BUILD_FILES.opcache_ini }}", mode: "0644" }
    - { path: "{{ MOODLE_BUILD_FILES.fpm_pool }}", mode: "0644" }
    - { path: "{{ MOODLE_BUILD_FILES.install_source }}", mode: "0755" }
    - { path: "{{ MOODLE_BUILD_FILES.install_upgrade_path }}", mode: "0755" }
    - { path: "{{ MOODLE_BUILD_FILES.install_oidc }}", mode: "0755" }
    - { path: "{{ MOODLE_BUILD_FILES.install_mcp }}", mode: "0755" }
    - { path: "{{ MOODLE_BUILD_FILES.install_objectfs }}", mode: "0755" }
    - { path: "{{ MOODLE_BUILD_FILES.patch_objectfs }}", mode: "0644" }
  loop_control:
    label: "{{ item.path }}"
  notify:
    - compose-build
    - compose-up

- name: "πŸ“‹ Copy msmtprc to {{ MOODLE_MSMTP_ABS }} (Mailu relay for mail() + healthcheck)"
  stack_host_template:
    src: "{{ MOODLE_MSMTP_SRC }}"
    dest: "{{ MOODLE_MSMTP_ABS }}"
    mode: "0640"
  vars:
    sys_svc_mail_msmtp_in_container: true
  notify:
    - compose-build
    - compose-up

- name: "πŸ“„ Render PHP runtime tuning into compose context"
  stack_host_template:
    src: "{{ [MOODLE_BUILD_DIR, MOODLE_BUILD_FILES.runtime_ini ~ '.j2'] | path_join }}"
    dest: "{{ [_moodle_build_dir, MOODLE_BUILD_FILES.runtime_ini] | path_join }}"
    mode: "0644"
  notify:
    - compose-build
    - compose-up