From bfeb10bd13091a3e1f1f1423fc2d8e3b526afed6 Mon Sep 17 00:00:00 2001 From: Greg Harvey Date: Mon, 30 Dec 2024 11:23:47 +0100 Subject: [PATCH 1/6] Fixing Mautic deployment workflow. --- roles/_meta/deploy-mautic/tasks/main.yml | 30 ++++++++++++------------ roles/cron/cron_mautic/tasks/main.yml | 7 ++++-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/roles/_meta/deploy-mautic/tasks/main.yml b/roles/_meta/deploy-mautic/tasks/main.yml index ab4a38d2..4ec69f31 100644 --- a/roles/_meta/deploy-mautic/tasks/main.yml +++ b/roles/_meta/deploy-mautic/tasks/main.yml @@ -1,37 +1,37 @@ --- # Default Mautic role. -- import_role: +- ansible.builtin.import_role: name: _init -- import_role: +- ansible.builtin.import_role: name: deploy_code -# - import_role: -# name: composer -# - import_role: +- ansible.builtin.import_role: + name: composer +# - ansible.builtin.import_role: # name: maintenance_mode # vars: # maintenance_mode: # operation: offline -- import_role: +- ansible.builtin.import_role: name: database_backup -- import_role: +- ansible.builtin.import_role: name: config_generate -- import_role: +- ansible.builtin.import_role: name: database_apply -- import_role: +- ansible.builtin.import_role: name: live_symlink -- import_role: +- ansible.builtin.import_role: name: cache_clear/cache_clear-opcache -- import_role: +- ansible.builtin.import_role: name: cache_clear/cache_clear-mautic -# - import_role: +# - ansible.builtin.import_role: # name: maintenance_mode # vars: # maintenance_mode: # operation: online -- import_role: +- ansible.builtin.import_role: name: cron/cron_database_backup -- import_role: +- ansible.builtin.import_role: name: cron/cron_mautic -- import_role: +- ansible.builtin.import_role: name: _exit diff --git a/roles/cron/cron_mautic/tasks/main.yml b/roles/cron/cron_mautic/tasks/main.yml index f0b6071b..403536dd 100644 --- a/roles/cron/cron_mautic/tasks/main.yml +++ b/roles/cron/cron_mautic/tasks/main.yml @@ -1,12 +1,15 @@ --- +- name: Set console path. + ansible.builtin.set_fact: + symfony_console_bin: "{{ symfony_console_bin | default('env php ' + deploy_path + '/bin/console') }}" - name: Setup Mautic cron tasks. cron: name: "{{ project_name }}_{{ build_type }}_{{ entry.job }}" minute: "{{ entry.minute }}" hour: "{{ entry.hour | default(omit) }}" - job: "env php {{ live_symlink_dest }}/{{ webroot }}/app/console {{ entry.job }}" + job: "env php {{ symfony_console_bin }} {{ entry.job }}" with_items: "{{ cron_mautic.entries }}" loop_control: loop_var: entry - when: deploy_operation == 'deploy' \ No newline at end of file + when: deploy_operation == 'deploy' From cc95886cdf3c5355affe583b72e7d6e07c34babc Mon Sep 17 00:00:00 2001 From: Greg Harvey Date: Mon, 30 Dec 2024 11:42:03 +0100 Subject: [PATCH 2/6] Ensuring symlink destinations exist. --- roles/live_symlink/defaults/main.yml | 4 ++-- roles/live_symlink/tasks/main.yml | 30 ++++++++++++++++++---------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/roles/live_symlink/defaults/main.yml b/roles/live_symlink/defaults/main.yml index 51618671..8bf22492 100644 --- a/roles/live_symlink/defaults/main.yml +++ b/roles/live_symlink/defaults/main.yml @@ -3,11 +3,11 @@ deploy_user: 'deploy' live_symlink: # Either update (for successful builds) or revert. operation: update - # Specify any additional symlink to create, with src (target) and dest (link). + # Specify any additional directory symlink to create, with src (target) and dest (link). # src: can be either absolute or relative to the dest (eg. '/var/my_data', '/home/deploy/simplesaml', '../../../myconfig') # dest: can only be relative to the root of your repository (eg. 'www/themes/myassets', 'var/cache') # force: set to true to create the symlinks in two cases: the source file does not exist but will appear later; the destination exists and is a file. - # - src: '/home/{{ deploy_user }}//{{ project_name }}_{{ build_type }}/simplesaml' + # - src: '/home/{{ deploy_user }}/shared/{{ project_name }}_{{ build_type }}/simplesaml' # dest: 'vendor/simplesamlphp/simplesamlphp/config' # force: true # - src: '/var/simplesaml/etc' diff --git a/roles/live_symlink/tasks/main.yml b/roles/live_symlink/tasks/main.yml index d85e4e7f..a60e19ea 100644 --- a/roles/live_symlink/tasks/main.yml +++ b/roles/live_symlink/tasks/main.yml @@ -32,16 +32,24 @@ - live_symlink.templates | length - deploy_operation == 'deploy' -- name: Create additional symlinks. - ansible.builtin.file: - src: "{{ link.src }}" - dest: "{{ deploy_path }}/{{ link.dest }}" - state: link - follow: false - force: "{{ link.force | default(true) }}" - with_items: "{{ live_symlink.symlinks }}" - loop_control: - loop_var: link +- name: Handle additional symlinks. when: - live_symlink.symlinks | length - - deploy_operation == 'deploy' \ No newline at end of file + - deploy_operation == 'deploy' + loop_control: + loop_var: link + with_items: "{{ live_symlink.symlinks }}" + block: + - name: Ensure additional symlink sources exist. + ansible.builtin.file: + path: "{{ link.src }}" + state: directory + mode: '0755' + + - name: Create additional symlinks. + ansible.builtin.file: + src: "{{ link.src }}" + dest: "{{ deploy_path }}/{{ link.dest }}" + state: link + follow: false + force: "{{ link.force | default(true) }}" From 4664a018a8544d8fc8d5c9effe009b59aec854a5 Mon Sep 17 00:00:00 2001 From: Greg Harvey Date: Mon, 30 Dec 2024 12:27:11 +0100 Subject: [PATCH 3/6] The docroot folder doesn't exist yet, so ensure it gets created. --- .../deploy_code-mautic/tasks/main.yml | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/roles/deploy_code/deploy_code-mautic/tasks/main.yml b/roles/deploy_code/deploy_code-mautic/tasks/main.yml index 2ad14359..c9a60df3 100644 --- a/roles/deploy_code/deploy_code-mautic/tasks/main.yml +++ b/roles/deploy_code/deploy_code-mautic/tasks/main.yml @@ -1,8 +1,14 @@ -- name: Ensure public files directory exists. +--- +- name: Ensure public files source directory exists. file: path: "{{ deploy_assets_base_path }}/{{ project_name }}_{{ build_type }}_public_files" state: directory +- name: Ensure public files destination directory exists. + file: + path: "{{ deploy_path }}/{{ webroot }}/{{ mautic.image_path }}" + state: directory + - name: Ensure public files directory permissions. file: path: "{{ deploy_assets_base_path }}/{{ project_name }}_{{ build_type }}_public_files" @@ -13,21 +19,6 @@ become: true when: "www_user != deploy_user" -- name: Check if we have a commited public folder. - stat: - path: "{{ deploy_path }}/{{ webroot }}/{{ mautic.image_path }}" - register: _mautic_public_dir_commited - -- name: Synchronize existing assets. - command: - cmd: "rsync -av {{ deploy_path }}/{{ webroot }}/{{ mautic.image_path }}/ {{ deploy_assets_base_path }}/{{ project_name }}_{{ build_type }}_public_files" - when: _mautic_public_dir_commited.stat.isdir is defined and _mautic_public_dir_commited.stat.isdir - -- name: Remove commited public dir. - file: - path: "{{ deploy_path }}/{{ webroot }}/{{ mautic.image_path }}" - state: absent - - name: Create symlink to public files. file: src: "{{ deploy_assets_base_path }}/{{ project_name }}_{{ build_type }}_public_files" From d6d0de86f9b36debf62dd22b945a411a0be8f5de Mon Sep 17 00:00:00 2001 From: Greg Harvey Date: Mon, 30 Dec 2024 12:37:19 +0100 Subject: [PATCH 4/6] Mautic cache role obsolete as it now uses Symfony properly. --- roles/cache_clear/cache_clear-mautic/README.md | 7 ------- roles/cache_clear/cache_clear-mautic/tasks/main.yml | 10 ---------- 2 files changed, 17 deletions(-) delete mode 100644 roles/cache_clear/cache_clear-mautic/README.md delete mode 100644 roles/cache_clear/cache_clear-mautic/tasks/main.yml diff --git a/roles/cache_clear/cache_clear-mautic/README.md b/roles/cache_clear/cache_clear-mautic/README.md deleted file mode 100644 index 16360291..00000000 --- a/roles/cache_clear/cache_clear-mautic/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Drupal 8 -Clear caches for Drupal 8. - - - - - diff --git a/roles/cache_clear/cache_clear-mautic/tasks/main.yml b/roles/cache_clear/cache_clear-mautic/tasks/main.yml deleted file mode 100644 index 56884d16..00000000 --- a/roles/cache_clear/cache_clear-mautic/tasks/main.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: set console path - set_fact: - mautic_console_bin: "env php {{ deploy_path }}/{{ webroot }}/app/console" - -- name: Clear cache. - command: - cmd: "{{ mautic_console_bin }} cache:clear --no-interaction --env=prod --no-warmup" - become: "{{ 'no' if www_user == deploy_user else 'yes' }}" - become_user: "{{ www_user }}" From d68947f1dda757d14598cd266b322cc614dfa96f Mon Sep 17 00:00:00 2001 From: Greg Harvey Date: Mon, 30 Dec 2024 12:37:38 +0100 Subject: [PATCH 5/6] Updating Mautic console bin location. --- roles/_meta/deploy-mautic/tasks/main.yml | 2 +- .../database_apply-mautic/tasks/main.yml | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/roles/_meta/deploy-mautic/tasks/main.yml b/roles/_meta/deploy-mautic/tasks/main.yml index 4ec69f31..0bf4723f 100644 --- a/roles/_meta/deploy-mautic/tasks/main.yml +++ b/roles/_meta/deploy-mautic/tasks/main.yml @@ -23,7 +23,7 @@ - ansible.builtin.import_role: name: cache_clear/cache_clear-opcache - ansible.builtin.import_role: - name: cache_clear/cache_clear-mautic + name: cache_clear/cache_clear-symfony # - ansible.builtin.import_role: # name: maintenance_mode # vars: diff --git a/roles/database_apply/database_apply-mautic/tasks/main.yml b/roles/database_apply/database_apply-mautic/tasks/main.yml index ec806f33..66e52472 100644 --- a/roles/database_apply/database_apply-mautic/tasks/main.yml +++ b/roles/database_apply/database_apply-mautic/tasks/main.yml @@ -1,7 +1,7 @@ --- -- name: set console path - set_fact: - mautic_console_bin: "env php {{ deploy_path }}/{{ webroot }}/app/console" +- name: Set console path. + ansible.builtin.set_fact: + symfony_console_bin: "{{ symfony_console_bin | default('env php ' + deploy_path + '/bin/console') }}" - name: Fix file permissions for local.php. file: @@ -16,19 +16,19 @@ - name: Install Mautic. command: - cmd: "{{ mautic_console_bin }} mautic:install:data --no-interaction --force" + cmd: "{{ symfony_console_bin }} mautic:install:data --no-interaction --force" become: "{{ 'no' if www_user == deploy_user else 'yes' }}" become_user: "{{ www_user }}" when: previous_build_number == 0 or (mautic.force_install is defined and mautic.force_install) - name: Clear cache. command: - cmd: "{{ mautic_console_bin }} cache:clear --no-interaction --env=prod --no-warmup" + cmd: "{{ symfony_console_bin }} cache:clear --no-interaction --env=prod --no-warmup" become: "{{ 'no' if www_user == deploy_user else 'yes' }}" become_user: "{{ www_user }}" - name: Apply Mautic database updates. command: - cmd: "{{ mautic_console_bin }} doctrine:migrations:migrate --no-interaction --env=prod" + cmd: "{{ symfony_console_bin }} doctrine:migrations:migrate --no-interaction --env=prod" become: "{{ 'no' if www_user == deploy_user else 'yes' }}" become_user: "{{ www_user }}" From 7a9bc2b8ff6ac3dbdd95f98aba89059f042605e4 Mon Sep 17 00:00:00 2001 From: Greg Harvey Date: Mon, 30 Dec 2024 13:59:14 +0100 Subject: [PATCH 6/6] Fixing missing code. --- roles/live_symlink/tasks/main.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/roles/live_symlink/tasks/main.yml b/roles/live_symlink/tasks/main.yml index a60e19ea..63225e16 100644 --- a/roles/live_symlink/tasks/main.yml +++ b/roles/live_symlink/tasks/main.yml @@ -36,15 +36,15 @@ when: - live_symlink.symlinks | length - deploy_operation == 'deploy' - loop_control: - loop_var: link - with_items: "{{ live_symlink.symlinks }}" block: - name: Ensure additional symlink sources exist. ansible.builtin.file: path: "{{ link.src }}" state: directory mode: '0755' + with_items: "{{ live_symlink.symlinks }}" + loop_control: + loop_var: link - name: Create additional symlinks. ansible.builtin.file: @@ -53,3 +53,6 @@ state: link follow: false force: "{{ link.force | default(true) }}" + with_items: "{{ live_symlink.symlinks }}" + loop_control: + loop_var: link