Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion roles/_init/tasks/drupal8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}"
drush_live_bin: "{{ drush_live_bin | default('{{ live_symlink_dest }}/vendor/bin/drush') }}"
74 changes: 36 additions & 38 deletions roles/_init/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,73 @@
- 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 }}"
when:
- 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:
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions roles/cache_clear/cache_clear-drupal8/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
126 changes: 51 additions & 75 deletions roles/deploy_code/tasks/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand All @@ -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 }}"
Expand All @@ -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 }}"
Expand All @@ -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 }}"
Expand Down Expand Up @@ -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:
Expand Down