diff --git a/roles/_init/tasks/drupal8.yml b/roles/_init/tasks/drupal8.yml index 3792c489..478b4426 100644 --- a/roles/_init/tasks/drupal8.yml +++ b/roles/_init/tasks/drupal8.yml @@ -5,4 +5,4 @@ - name: Define path to drush for currently live build. set_fact: - drush_live_bin: "{{ drush_live_bin | default('{{ live_symlink_dest }}/vendor/bin/drush') }}" \ No newline at end of file + drush_live_bin: "{{ drush_live_bin | default('{{ live_symlink_dest }}/vendor/bin/drush') }}" diff --git a/roles/_init/tasks/main.yml b/roles/_init/tasks/main.yml index c054e8fb..225e9b60 100644 --- a/roles/_init/tasks/main.yml +++ b/roles/_init/tasks/main.yml @@ -3,27 +3,35 @@ - name: Define deploy user. ansible.builtin.set_fact: deploy_user: "{{ deploy_user | default('deploy') }}" + - name: Define deploy base path. ansible.builtin.set_fact: deploy_base_path: "{{ deploy_base_path | default('/home/{{ deploy_user }}/deploy/{{ project_name }}_{{ build_type }}') }}" + - name: Define mounted directory for assets. ansible.builtin.set_fact: deploy_assets_base_path: "{{ deploy_assets_base_path | default('/home/{{ deploy_user }}/shared/{{ project_name }}_{{ build_type }}/assets') }}" + - name: Define webroot. ansible.builtin.set_fact: webroot: "{{ webroot | default('web') }}" + - name: Define build deploy path prefix. ansible.builtin.set_fact: deploy_path_prefix: "{{ deploy_base_path }}/{{ project_name }}_{{ build_type }}_build_" + - name: Define build deploy path. ansible.builtin.set_fact: deploy_path: "{{ deploy_path | default('{{ deploy_path_prefix }}{{ build_number }}') }}" + - name: Define live_symlink dest. ansible.builtin.set_fact: live_symlink_dest: "{{ live_symlink_dest | default('{{ deploy_base_path }}/live.{{ project_name }}_{{ build_type }}') }}" + - name: Define opcache cachetool path. ansible.builtin.set_fact: cachetool_bin: "{{ deploy_base_path }}/cachetool.phar" + - name: Set opcache cachetool path from variable if provided. ansible.builtin.set_fact: cachetool_bin: "{{ cache_clear_opcache.cachetool_bin }}" @@ -31,38 +39,37 @@ - cache_clear_opcache.cachetool_bin is defined - cache_clear_opcache.cachetool_bin | length > 0 -# Manipulate variables for SquashFS builds. -- name: Define image builds base path. - ansible.builtin.set_fact: - build_base_path: "/home/{{ deploy_user }}/builds/{{ project_name }}_{{ build_type }}" - when: - - deploy_code.mount_type is defined - - deploy_code.mount_type == "squashfs" -- name: Define image builds build path prefix. - ansible.builtin.set_fact: - build_path_prefix: "{{ build_base_path }}/{{ project_name }}_{{ build_type }}_build_" - when: - - deploy_code.mount_type is defined - - deploy_code.mount_type == "squashfs" -- name: Define live_symlink dest for image builds. - ansible.builtin.set_fact: - live_symlink_build_dest: "{{ live_symlink_build_dest | default('{{ build_base_path }}/live.{{ project_name }}_{{ build_type }}') }}" - when: - - deploy_code.mount_type is defined - - deploy_code.mount_type == "squashfs" -- name: Overwrite deploy and live_symlink paths if SquashFS deploy. - ansible.builtin.set_fact: - deploy_path: "{{ build_path | default('{{ build_path_prefix }}{{ build_number }}') }}" - when: - - deploy_code.mount_type is defined - - deploy_code.mount_type == "squashfs" -- name: Overwrite cachetool path if SquashFS deploy and path not provided. - ansible.builtin.set_fact: - cachetool_bin: "{{ build_base_path }}/cachetool.phar" +- name: Manipulate variables for SquashFS builds. + block: + - name: Define image builds base path. + ansible.builtin.set_fact: + build_base_path: "/home/{{ deploy_user }}/builds/{{ project_name }}_{{ build_type }}" + + - name: Define image builds build path prefix. + ansible.builtin.set_fact: + build_path_prefix: "{{ build_base_path }}/{{ project_name }}_{{ build_type }}_build_" + + - name: Define live_symlink dest for image builds. + ansible.builtin.set_fact: + live_symlink_build_dest: "{{ live_symlink_build_dest | default('{{ build_base_path }}/live.{{ project_name }}_{{ build_type }}') }}" + + - name: Overwrite deploy and live_symlink paths if SquashFS deploy. + ansible.builtin.set_fact: + deploy_path: "{{ build_path | default('{{ build_path_prefix }}{{ build_number }}') }}" + + - name: Overwrite cachetool path if SquashFS deploy and path not provided. + ansible.builtin.set_fact: + cachetool_bin: "{{ build_base_path }}/cachetool.phar" + when: + - cache_clear_opcache.cachetool_bin is not defined + + - name: Ensure build target directory exists. + ansible.builtin.file: + path: "{{ build_base_path }}" + state: directory when: - deploy_code.mount_type is defined - deploy_code.mount_type == "squashfs" - - cache_clear_opcache.cachetool_bin is not defined # Gather last known good build directly from symlink. # This can happen: @@ -99,15 +106,6 @@ path: "{{ deploy_base_path }}" state: directory -# Make sure the build target exists. -- name: Ensure build target directory exists. - ansible.builtin.file: - path: "{{ build_base_path }}" - state: directory - when: - - deploy_code.mount_type is defined - - deploy_code.mount_type == "squashfs" - # Check for project specific init tasks. - name: Check that {{ project_type }}.yml exists. ansible.builtin.stat: diff --git a/roles/cache_clear/cache_clear-drupal8/tasks/main.yml b/roles/cache_clear/cache_clear-drupal8/tasks/main.yml index 92db6584..1fc9d2f2 100644 --- a/roles/cache_clear/cache_clear-drupal8/tasks/main.yml +++ b/roles/cache_clear/cache_clear-drupal8/tasks/main.yml @@ -1,4 +1,17 @@ --- +- name: Override paths for squashfs build cleanup step. + block: + - name: Override path to drush binary. + set_fact: + drush_bin: "{{ drush_live_bin }}" + - name: Override deploy_path. + set_fact: + deploy_path: "{{ live_symlink_dest }}" + when: + - deploy_code.mount_type is defined + - deploy_code.mount_type == "squashfs" + - deploy_operation == 'cleanup' + - name: Clear Drupal cache. ansible.builtin.command: cmd: "{{ drush_bin }} -l {{ site_drupal.folder }} -y cr" diff --git a/roles/deploy_code/tasks/cleanup.yml b/roles/deploy_code/tasks/cleanup.yml index f3fc2c73..449c1103 100644 --- a/roles/deploy_code/tasks/cleanup.yml +++ b/roles/deploy_code/tasks/cleanup.yml @@ -17,15 +17,6 @@ - deploy_code.perms_fix_path | length > 1 - deploy_code.mount_type != "squashfs" -- name: Ensure permissions are set on builds directory. - ansible.builtin.shell: - cmd: "if [ -d {{ build_path_prefix }}{{ item }}/{{ deploy_code.perms_fix_path }} ]; then chmod 755 {{ build_path_prefix }}{{ item }}/{{ deploy_code.perms_fix_path }}; fi" - with_sequence: start={{ [previous_build_number | int - cleanup_history_depth, 0] | max }} end={{ [previous_build_number | int - deploy_code.keep, 0] | max }} - when: - - deploy_code.perms_fix_path is defined - - deploy_code.perms_fix_path | length > 1 - - deploy_code.mount_type == "squashfs" - - name: Delete codebases from deploy directory. ansible.builtin.file: name: "{{ deploy_path_prefix }}{{ item }}" @@ -34,14 +25,6 @@ when: - deploy_code.mount_type != "squashfs" -- name: Delete codebases from builds directory. - ansible.builtin.file: - name: "{{ build_path_prefix }}{{ item }}" - state: absent - with_sequence: start={{ [previous_build_number | int - cleanup_history_depth, 0] | max }} end={{ [previous_build_number | int - deploy_code.keep, 0] | max }} - when: - - deploy_code.mount_type == "squashfs" - - name: Create a tarball of the deployed codebases. ansible.builtin.command: cmd: "tar -cvf /tmp/{{ project_name }}_{{ build_type }}_{{ build_number }}.tar --owner=0 --group=0 {{ deploy_base_path }}" @@ -51,15 +34,6 @@ - deploy_code.mount_type == "tarball" run_once: true -- name: Create a SquashFS image of the deployed codebases. - ansible.builtin.command: - cmd: "mksquashfs {{ build_base_path }} /tmp/{{ project_name }}_{{ build_type }}_{{ build_number }}.sqsh -e {{ build_base_path }}/deploy.sqsh" - when: - - deploy_code.mount_sync is defined - - deploy_code.mount_sync | length > 1 - - deploy_code.mount_type == "squashfs" - run_once: true - - name: Create destination folder. ansible.builtin.file: path: "{{ deploy_code.mount_sync }}" @@ -79,60 +53,57 @@ - deploy_code.mount_type == "tarball" run_once: true -- name: Move SquashFS image to final destination. - ansible.builtin.command: - cmd: "mv /tmp/{{ project_name }}_{{ build_type }}_{{ build_number }}.sqsh {{ deploy_code.mount_sync }}/{{ project_name }}_{{ build_type }}.sqsh" - when: - - deploy_code.mount_sync is defined - - deploy_code.mount_sync | length > 1 - - deploy_code.mount_type == "squashfs" - run_once: true +# Beginning of the squashFS block. +- name: Execute tasks for squashFS mount type. + block: + - name: Ensure permissions are set on builds directory. + ansible.builtin.shell: + cmd: "if [ -d {{ build_path_prefix }}{{ item }}/{{ deploy_code.perms_fix_path }} ]; then chmod 755 {{ build_path_prefix }}{{ item }}/{{ deploy_code.perms_fix_path }}; fi" + with_sequence: start={{ [previous_build_number | int - cleanup_history_depth, 0] | max }} end={{ [previous_build_number | int - deploy_code.keep, 0] | max }} + when: + - deploy_code.perms_fix_path is defined + - deploy_code.perms_fix_path | length > 1 -- name: Check if we have a SquashFS image already there. - ansible.builtin.stat: - path: "{{ build_base_path }}/deploy.sqsh" - register: _deploy_code_mount_image - when: - - deploy_code.mount_sync is defined - - deploy_code.mount_sync | length > 1 - - deploy_code.mount_type == "squashfs" + - name: Delete codebases from builds directory. + ansible.builtin.file: + name: "{{ build_path_prefix }}{{ item }}" + state: absent + with_sequence: start={{ [previous_build_number | int - cleanup_history_depth, 0] | max }} end={{ [previous_build_number | int - deploy_code.keep, 0] | max }} -- name: Copy previous SquashFS image to shared mount point in case of rollback. - ansible.builtin.copy: - remote_src: true - force: true - src: "{{ build_base_path }}/deploy.sqsh" - dest: "{{ deploy_code.mount_sync }}/{{ project_name }}_{{ build_type }}_previous.sqsh" - when: - - deploy_code.mount_sync is defined - - deploy_code.mount_sync | length > 1 - - deploy_code.mount_type == "squashfs" - - _deploy_code_mount_image.stat.islnk is defined - run_once: true + - name: Create a SquashFS image of the deployed codebases. + ansible.builtin.command: + cmd: "mksquashfs {{ build_base_path }} /tmp/{{ project_name }}_{{ build_type }}_{{ build_number }}.sqsh -e {{ build_base_path }}/deploy.sqsh" + run_once: true -- name: Ensure mounted SquashFS image is deleted. - ansible.builtin.file: - path: "{{ build_base_path }}/deploy.sqsh" - state: absent - when: - - deploy_code.mount_sync is defined - - deploy_code.mount_sync | length > 1 - - deploy_code.mount_type == "squashfs" + - name: Move SquashFS image to final destination. + ansible.builtin.command: + cmd: "mv /tmp/{{ project_name }}_{{ build_type }}_{{ build_number }}.sqsh {{ deploy_code.mount_sync }}/{{ project_name }}_{{ build_type }}.sqsh" + run_once: true + + - name: Check if we have a SquashFS image already there. + ansible.builtin.stat: + path: "{{ build_base_path }}/deploy.sqsh" + register: _deploy_code_mount_image + + - name: Copy previous SquashFS image to shared mount point in case of rollback. + ansible.builtin.copy: + remote_src: true + force: true + src: "{{ build_base_path }}/deploy.sqsh" + dest: "{{ deploy_code.mount_sync }}/{{ project_name }}_{{ build_type }}_previous.sqsh" + when: + - _deploy_code_mount_image.stat.islnk is defined + run_once: true -- name: Copy SquashFS image to local server. - ansible.builtin.command: - cmd: "cp {{ deploy_code.mount_sync }}/{{ project_name }}_{{ build_type }}.sqsh {{ build_base_path }}/deploy.sqsh" - when: - - deploy_code.mount_sync is defined - - deploy_code.mount_sync | length > 1 - - deploy_code.mount_type == "squashfs" + - name: Ensure mounted SquashFS image is deleted. + ansible.builtin.file: + path: "{{ build_base_path }}/deploy.sqsh" + state: absent + + - name: Copy SquashFS image to local server. + ansible.builtin.command: + cmd: "cp {{ deploy_code.mount_sync }}/{{ project_name }}_{{ build_type }}.sqsh {{ build_base_path }}/deploy.sqsh" -- name: Unmount and remount squashfs images. - when: - - deploy_code.mount_sync is defined - - deploy_code.mount_sync | length > 1 - - deploy_code.mount_type == "squashfs" - block: - name: Check if we have a mount already. ansible.builtin.shell: cmd: "set -o pipefail && mount | grep {{ deploy_base_path }}" @@ -224,6 +195,11 @@ - _deploy_code_mount_check.rc == 0 - deploy_code.service_action == "stop" - deploy_code.services | length > 0 + when: + - deploy_code.mount_sync is defined + - deploy_code.mount_sync | length > 1 + - deploy_code.mount_type == "squashfs" +# End of the squashFS block. - name: Trigger an infrastructure rebuild. ansible.builtin.include_role: