From 09a6e98f252cd0b3bd3c9fedf800e7d2ee1b3847 Mon Sep 17 00:00:00 2001 From: gregharvey Date: Thu, 10 Aug 2023 16:54:24 +0200 Subject: [PATCH 1/8] Adding syncing for feature branches. --- docs/roles/_init.md | 8 ++++++ .../sync/database_sync/database_sync-mysql.md | 2 +- roles/_init/README.md | 8 ++++++ roles/_init/defaults/main.yml | 8 ++++++ .../database_apply-drupal8/tasks/main.yml | 26 +++++++++++++++++++ .../database_sync-mysql/README.md | 2 +- 6 files changed, 52 insertions(+), 2 deletions(-) diff --git a/docs/roles/_init.md b/docs/roles/_init.md index edf1f5d3..8118c9ea 100644 --- a/docs/roles/_init.md +++ b/docs/roles/_init.md @@ -34,9 +34,17 @@ drupal: cron: - minute: "*/{{ 10 | random(start=1) }}" job: cron + feature_branch: false # whether or not this build is a feature branch that should sync assets from another environment + # For syncing database and files on a feature branch initial build + mysql_sync: # see sync/database_sync for docs + databases: [] + files_sync: # see sync/files_sync for docs + cleanup: true + directories: [] mautic: image_path: "media/images" force_install: false +# Used for custom build time tools like cachetool bin_directory: "/home/{{ deploy_user }}/.bin" # Number of dumps/db to look up for cleanup. cleanup_history_depth: 50 diff --git a/docs/roles/sync/database_sync/database_sync-mysql.md b/docs/roles/sync/database_sync/database_sync-mysql.md index d70d770e..c0c2954b 100644 --- a/docs/roles/sync/database_sync/database_sync-mysql.md +++ b/docs/roles/sync/database_sync/database_sync-mysql.md @@ -7,7 +7,7 @@ Sync MySQL databases between environments. mysql_sync: mysqldump_params: "{{ _mysqldump_params }}" # set in _init but you can override here. cleanup: true # if false leaves tmp database dump on deploy server for debugging purposes. - archival_method: "bzip2" # oprions are "bzip2" or "gzip". + archival_method: "gzip" # oprions are "bzip2" or "gzip". databases: - source: # Name of the database to take a dump from. diff --git a/roles/_init/README.md b/roles/_init/README.md index edf1f5d3..8118c9ea 100644 --- a/roles/_init/README.md +++ b/roles/_init/README.md @@ -34,9 +34,17 @@ drupal: cron: - minute: "*/{{ 10 | random(start=1) }}" job: cron + feature_branch: false # whether or not this build is a feature branch that should sync assets from another environment + # For syncing database and files on a feature branch initial build + mysql_sync: # see sync/database_sync for docs + databases: [] + files_sync: # see sync/files_sync for docs + cleanup: true + directories: [] mautic: image_path: "media/images" force_install: false +# Used for custom build time tools like cachetool bin_directory: "/home/{{ deploy_user }}/.bin" # Number of dumps/db to look up for cleanup. cleanup_history_depth: 50 diff --git a/roles/_init/defaults/main.yml b/roles/_init/defaults/main.yml index 57ee7e44..2fad2e47 100644 --- a/roles/_init/defaults/main.yml +++ b/roles/_init/defaults/main.yml @@ -25,9 +25,17 @@ drupal: cron: - minute: "*/{{ 10 | random(start=1) }}" job: cron + feature_branch: false # whether or not this build is a feature branch that should sync assets from another environment + # For syncing database and files on a feature branch initial build + mysql_sync: # see sync/database_sync for docs + databases: [] + files_sync: # see sync/files_sync for docs + cleanup: true + directories: [] mautic: image_path: "media/images" force_install: false +# Used for custom build time tools like cachetool bin_directory: "/home/{{ deploy_user }}/.bin" # Number of dumps/db to look up for cleanup. cleanup_history_depth: 50 diff --git a/roles/database_apply/database_apply-drupal8/tasks/main.yml b/roles/database_apply/database_apply-drupal8/tasks/main.yml index c423fad9..7faf684f 100644 --- a/roles/database_apply/database_apply-drupal8/tasks/main.yml +++ b/roles/database_apply/database_apply-drupal8/tasks/main.yml @@ -25,6 +25,32 @@ when: (previous_build_number == 0) or (site.force_install is defined and site.force_install) register: _drush_output +- name: Sync database. + ansible.builtin.import_role: + name: sync/database_sync + vars: + mysql_sync: "{{ site.mysql_sync }}" + with_items: "{{ drupal.sites }}" + loop_control: + loop_var: site + when: + - (previous_build_number == 0) or (site.force_install is defined and site.force_install) + - site.feature_branch | default(false) + - site.mysql_sync | length > 0 + +- name: Sync files. + ansible.builtin.import_role: + name: sync/files_sync + vars: + files_sync: "{{ site.files_sync }}" + with_items: "{{ drupal.sites }}" + loop_control: + loop_var: site + when: + - (previous_build_number == 0) or (site.force_install is defined and site.force_install) + - site.feature_branch | default(false) + - site.files_sync | length > 0 + - name: Show drush output. ansible.builtin.debug: msg: "{{ _drush_output }}" diff --git a/roles/sync/database_sync/database_sync-mysql/README.md b/roles/sync/database_sync/database_sync-mysql/README.md index d70d770e..c0c2954b 100644 --- a/roles/sync/database_sync/database_sync-mysql/README.md +++ b/roles/sync/database_sync/database_sync-mysql/README.md @@ -7,7 +7,7 @@ Sync MySQL databases between environments. mysql_sync: mysqldump_params: "{{ _mysqldump_params }}" # set in _init but you can override here. cleanup: true # if false leaves tmp database dump on deploy server for debugging purposes. - archival_method: "bzip2" # oprions are "bzip2" or "gzip". + archival_method: "gzip" # oprions are "bzip2" or "gzip". databases: - source: # Name of the database to take a dump from. From fee7ee16775419bab9923ca9db1676ce279dab8f Mon Sep 17 00:00:00 2001 From: gregharvey Date: Thu, 10 Aug 2023 18:19:38 +0200 Subject: [PATCH 2/8] Cannot loop over import_role, changing for include_role. --- docs/roles/database_backup/database_backup-mysql.md | 4 ++-- roles/database_apply/database_apply-drupal8/tasks/main.yml | 4 ++-- roles/database_backup/database_backup-mysql/README.md | 4 ++-- roles/database_backup/database_backup-mysql/defaults/main.yml | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/roles/database_backup/database_backup-mysql.md b/docs/roles/database_backup/database_backup-mysql.md index b52413bf..c52620f6 100644 --- a/docs/roles/database_backup/database_backup-mysql.md +++ b/docs/roles/database_backup/database_backup-mysql.md @@ -22,8 +22,8 @@ mysql_backup: # This is useful for locked-down setups where you do not have GRANT permissions. credentials_handling: rotate databases: - - database: "{{ project_name }}_{{ build_type }}" - user: "{{ project_name }}_{{ build_type }}" + - database: "{{ (project_name + '_' + build_type) | regex_replace('-', '_') }}" # avoid hyphens in MySQL database names + user: "{{ (project_name + '_' + build_type) | truncate(32, true, '', 0) }}" # 32 char limit credentials_file: "/home/{{ deploy_user }}/.mysql.creds" ``` diff --git a/roles/database_apply/database_apply-drupal8/tasks/main.yml b/roles/database_apply/database_apply-drupal8/tasks/main.yml index 7faf684f..7faa03c7 100644 --- a/roles/database_apply/database_apply-drupal8/tasks/main.yml +++ b/roles/database_apply/database_apply-drupal8/tasks/main.yml @@ -26,7 +26,7 @@ register: _drush_output - name: Sync database. - ansible.builtin.import_role: + ansible.builtin.include_role: name: sync/database_sync vars: mysql_sync: "{{ site.mysql_sync }}" @@ -39,7 +39,7 @@ - site.mysql_sync | length > 0 - name: Sync files. - ansible.builtin.import_role: + ansible.builtin.include_role: name: sync/files_sync vars: files_sync: "{{ site.files_sync }}" diff --git a/roles/database_backup/database_backup-mysql/README.md b/roles/database_backup/database_backup-mysql/README.md index b52413bf..c52620f6 100644 --- a/roles/database_backup/database_backup-mysql/README.md +++ b/roles/database_backup/database_backup-mysql/README.md @@ -22,8 +22,8 @@ mysql_backup: # This is useful for locked-down setups where you do not have GRANT permissions. credentials_handling: rotate databases: - - database: "{{ project_name }}_{{ build_type }}" - user: "{{ project_name }}_{{ build_type }}" + - database: "{{ (project_name + '_' + build_type) | regex_replace('-', '_') }}" # avoid hyphens in MySQL database names + user: "{{ (project_name + '_' + build_type) | truncate(32, true, '', 0) }}" # 32 char limit credentials_file: "/home/{{ deploy_user }}/.mysql.creds" ``` diff --git a/roles/database_backup/database_backup-mysql/defaults/main.yml b/roles/database_backup/database_backup-mysql/defaults/main.yml index f7e070e9..1cbc2e11 100644 --- a/roles/database_backup/database_backup-mysql/defaults/main.yml +++ b/roles/database_backup/database_backup-mysql/defaults/main.yml @@ -17,6 +17,6 @@ mysql_backup: # This is useful for locked-down setups where you do not have GRANT permissions. credentials_handling: rotate databases: - - database: "{{ project_name }}_{{ build_type }}" - user: "{{ project_name }}_{{ build_type }}" + - database: "{{ (project_name + '_' + build_type) | regex_replace('-', '_') }}" # avoid hyphens in MySQL database names + user: "{{ (project_name + '_' + build_type) | truncate(32, true, '', 0) }}" # 32 char limit credentials_file: "/home/{{ deploy_user }}/.mysql.creds" From 4f0e5f5b4cf1d5a976e941de256ab7e9400ad792 Mon Sep 17 00:00:00 2001 From: gregharvey Date: Fri, 11 Aug 2023 12:58:26 +0200 Subject: [PATCH 3/8] Adding ability to specify an exact filename for a settings template for Drupal 8 and above. --- docs/roles/_init.md | 16 ++++++++++------ docs/roles/composer.md | 3 ++- docs/roles/config_generate.md | 2 +- .../config_generate/config_generate-drupal8.md | 8 ++++++++ docs/roles/npm.md | 3 ++- roles/_init/README.md | 16 ++++++++++------ roles/_init/defaults/main.yml | 16 ++++++++++------ roles/composer/README.md | 3 ++- roles/composer/defaults/main.yml | 4 ++-- roles/config_generate/README.md | 2 +- .../config_generate-drupal8/README.md | 8 ++++++++ .../config_generate-drupal8/defaults/main.yml | 4 ++++ .../config_generate-drupal8/tasks/drush.yml | 5 +++-- .../config_generate-drupal8/tasks/settings.yml | 5 +++-- roles/config_generate/defaults/main.yml | 2 +- roles/live_symlink/defaults/main.yml | 4 ++-- roles/npm/README.md | 3 ++- roles/npm/defaults/main.yml | 4 ++-- 18 files changed, 73 insertions(+), 35 deletions(-) create mode 100644 roles/config_generate/config_generate-drupal8/defaults/main.yml diff --git a/docs/roles/_init.md b/docs/roles/_init.md index 8118c9ea..d561aac2 100644 --- a/docs/roles/_init.md +++ b/docs/roles/_init.md @@ -35,12 +35,16 @@ drupal: - minute: "*/{{ 10 | random(start=1) }}" job: cron feature_branch: false # whether or not this build is a feature branch that should sync assets from another environment - # For syncing database and files on a feature branch initial build - mysql_sync: # see sync/database_sync for docs - databases: [] - files_sync: # see sync/files_sync for docs - cleanup: true - directories: [] + # For syncing database and files on a feature branch initial build - include all variables if used + mysql_sync: {} # see sync/database_sync for docs + # mysqldump_params: "{{ _mysqldump_params }}" + # cleanup: true + # archival_method: gzip + # databases: [] + files_sync: {} # see sync/files_sync for docs + # unique_workspace: false + # cleanup: true + # directories: [] mautic: image_path: "media/images" force_install: false diff --git a/docs/roles/composer.md b/docs/roles/composer.md index 17144004..74765170 100644 --- a/docs/roles/composer.md +++ b/docs/roles/composer.md @@ -14,7 +14,7 @@ composer: # Specify any additional 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') - # create: wether to create the target if it does not exists. + # create: whether to create the target if it does not exists. # - src: '/home/{{ deploy_user }}//{{ project_name }}_{{ build_type }}/simplesaml' # dest: 'vendor/simplesamlphp/simplesamlphp/config' # - src: '/var/simplesaml/etc' @@ -24,6 +24,7 @@ composer: # src: name of a template, in the "templates" dir relative to your playbook. # dest: can only be relative to the root of your repository (eg. 'www/config.php', 'var/mysettings.php') templates: [] + ``` diff --git a/docs/roles/config_generate.md b/docs/roles/config_generate.md index 5428dd8b..fe7aecfe 100644 --- a/docs/roles/config_generate.md +++ b/docs/roles/config_generate.md @@ -11,7 +11,7 @@ config_generate: # Specify any additional 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') - # create: wether to create the target if it does not exists. + # create: whether to create the target if it does not exists. # - src: '/home/{{ deploy_user }}//{{ project_name }}_{{ build_type }}/simplesaml' # dest: 'vendor/simplesamlphp/simplesamlphp/config' # - src: '/var/simplesaml/etc' diff --git a/docs/roles/config_generate/config_generate-drupal8.md b/docs/roles/config_generate/config_generate-drupal8.md index 20e32b5b..75382886 100644 --- a/docs/roles/config_generate/config_generate-drupal8.md +++ b/docs/roles/config_generate/config_generate-drupal8.md @@ -4,4 +4,12 @@ Generates settings.php file for Drupal 8. +## Default variables +```yaml +config_generate_drupal: + # If you need to specify an exact file name for a template file to use for a build, you can do it here. + drupal_settings_file_name: settings.php + drush_settings_file_name: drush.yml +``` + diff --git a/docs/roles/npm.md b/docs/roles/npm.md index 385e1c84..97f06cdc 100644 --- a/docs/roles/npm.md +++ b/docs/roles/npm.md @@ -18,7 +18,7 @@ npm: # Specify any additional 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') - # create: wether to create the target if it does not exists. + # create: whether to create the target if it does not exists. # - src: '/home/{{ deploy_user }}//{{ project_name }}_{{ build_type }}/simplesaml' # dest: 'vendor/simplesamlphp/simplesamlphp/config' # - src: '/var/simplesaml/etc' @@ -28,6 +28,7 @@ npm: # src: name of a template, in the "templates" dir relative to your playbook. # dest: can only be relative to the root of your repository (eg. 'www/config.php', 'var/mysettings.php') templates: [] + ``` diff --git a/roles/_init/README.md b/roles/_init/README.md index 8118c9ea..d561aac2 100644 --- a/roles/_init/README.md +++ b/roles/_init/README.md @@ -35,12 +35,16 @@ drupal: - minute: "*/{{ 10 | random(start=1) }}" job: cron feature_branch: false # whether or not this build is a feature branch that should sync assets from another environment - # For syncing database and files on a feature branch initial build - mysql_sync: # see sync/database_sync for docs - databases: [] - files_sync: # see sync/files_sync for docs - cleanup: true - directories: [] + # For syncing database and files on a feature branch initial build - include all variables if used + mysql_sync: {} # see sync/database_sync for docs + # mysqldump_params: "{{ _mysqldump_params }}" + # cleanup: true + # archival_method: gzip + # databases: [] + files_sync: {} # see sync/files_sync for docs + # unique_workspace: false + # cleanup: true + # directories: [] mautic: image_path: "media/images" force_install: false diff --git a/roles/_init/defaults/main.yml b/roles/_init/defaults/main.yml index 2fad2e47..5fcee089 100644 --- a/roles/_init/defaults/main.yml +++ b/roles/_init/defaults/main.yml @@ -26,12 +26,16 @@ drupal: - minute: "*/{{ 10 | random(start=1) }}" job: cron feature_branch: false # whether or not this build is a feature branch that should sync assets from another environment - # For syncing database and files on a feature branch initial build - mysql_sync: # see sync/database_sync for docs - databases: [] - files_sync: # see sync/files_sync for docs - cleanup: true - directories: [] + # For syncing database and files on a feature branch initial build - include all variables if used + mysql_sync: {} # see sync/database_sync for docs + # mysqldump_params: "{{ _mysqldump_params }}" + # cleanup: true + # archival_method: gzip + # databases: [] + files_sync: {} # see sync/files_sync for docs + # unique_workspace: false + # cleanup: true + # directories: [] mautic: image_path: "media/images" force_install: false diff --git a/roles/composer/README.md b/roles/composer/README.md index 17144004..74765170 100644 --- a/roles/composer/README.md +++ b/roles/composer/README.md @@ -14,7 +14,7 @@ composer: # Specify any additional 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') - # create: wether to create the target if it does not exists. + # create: whether to create the target if it does not exists. # - src: '/home/{{ deploy_user }}//{{ project_name }}_{{ build_type }}/simplesaml' # dest: 'vendor/simplesamlphp/simplesamlphp/config' # - src: '/var/simplesaml/etc' @@ -24,6 +24,7 @@ composer: # src: name of a template, in the "templates" dir relative to your playbook. # dest: can only be relative to the root of your repository (eg. 'www/config.php', 'var/mysettings.php') templates: [] + ``` diff --git a/roles/composer/defaults/main.yml b/roles/composer/defaults/main.yml index 2e6eec4a..d0dfbd1d 100644 --- a/roles/composer/defaults/main.yml +++ b/roles/composer/defaults/main.yml @@ -7,7 +7,7 @@ composer: # Specify any additional 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') - # create: wether to create the target if it does not exists. + # create: whether to create the target if it does not exists. # - src: '/home/{{ deploy_user }}//{{ project_name }}_{{ build_type }}/simplesaml' # dest: 'vendor/simplesamlphp/simplesamlphp/config' # - src: '/var/simplesaml/etc' @@ -16,4 +16,4 @@ composer: # Specify any additional templates to generate, with src (template) and dest (file). # src: name of a template, in the "templates" dir relative to your playbook. # dest: can only be relative to the root of your repository (eg. 'www/config.php', 'var/mysettings.php') - templates: [] \ No newline at end of file + templates: [] diff --git a/roles/config_generate/README.md b/roles/config_generate/README.md index 5428dd8b..fe7aecfe 100644 --- a/roles/config_generate/README.md +++ b/roles/config_generate/README.md @@ -11,7 +11,7 @@ config_generate: # Specify any additional 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') - # create: wether to create the target if it does not exists. + # create: whether to create the target if it does not exists. # - src: '/home/{{ deploy_user }}//{{ project_name }}_{{ build_type }}/simplesaml' # dest: 'vendor/simplesamlphp/simplesamlphp/config' # - src: '/var/simplesaml/etc' diff --git a/roles/config_generate/config_generate-drupal8/README.md b/roles/config_generate/config_generate-drupal8/README.md index 20e32b5b..75382886 100644 --- a/roles/config_generate/config_generate-drupal8/README.md +++ b/roles/config_generate/config_generate-drupal8/README.md @@ -4,4 +4,12 @@ Generates settings.php file for Drupal 8. +## Default variables +```yaml +config_generate_drupal: + # If you need to specify an exact file name for a template file to use for a build, you can do it here. + drupal_settings_file_name: settings.php + drush_settings_file_name: drush.yml +``` + diff --git a/roles/config_generate/config_generate-drupal8/defaults/main.yml b/roles/config_generate/config_generate-drupal8/defaults/main.yml new file mode 100644 index 00000000..a6b7634d --- /dev/null +++ b/roles/config_generate/config_generate-drupal8/defaults/main.yml @@ -0,0 +1,4 @@ +config_generate_drupal: + # If you need to specify an exact file name for a template file to use for a build, you can do it here. + drupal_settings_file_name: settings.php + drush_settings_file_name: drush.yml \ No newline at end of file diff --git a/roles/config_generate/config_generate-drupal8/tasks/drush.yml b/roles/config_generate/config_generate-drupal8/tasks/drush.yml index f4b7ae7a..0bedd46d 100644 --- a/roles/config_generate/config_generate-drupal8/tasks/drush.yml +++ b/roles/config_generate/config_generate-drupal8/tasks/drush.yml @@ -4,6 +4,7 @@ src: '{{ item }}' dest: "{{ deploy_path }}/{{ webroot }}/sites/{{ site.folder }}/drush.yml" with_first_found: - - "{{ playbook_dir }}/{{ webroot }}/sites/{{ site.folder }}/{{ build_type }}.drush.yml.j2" - - "{{ _ce_deploy_build_dir }}/{{ webroot }}/sites/{{ site.folder }}/{{ build_type }}.drush.yml" + - "{{ playbook_dir }}/{{ webroot }}/sites/{{ site.folder }}/{{ build_type }}.{{ config_generate_drupal.drush_settings_file_name }}.j2" + - "{{ _ce_deploy_build_dir }}/{{ webroot }}/sites/{{ site.folder }}/{{ build_type }}.{{ config_generate_drupal.drush_settings_file_name }}" + - "{{ _ce_deploy_build_dir }}/{{ webroot }}/sites/{{ site.folder }}/{{ config_generate_drupal.drush_settings_file_name }}" - "drush.yml.j2" \ No newline at end of file diff --git a/roles/config_generate/config_generate-drupal8/tasks/settings.yml b/roles/config_generate/config_generate-drupal8/tasks/settings.yml index ebf182e8..6f698ba5 100644 --- a/roles/config_generate/config_generate-drupal8/tasks/settings.yml +++ b/roles/config_generate/config_generate-drupal8/tasks/settings.yml @@ -23,6 +23,7 @@ src: "{{ item }}" dest: "{{ deploy_path }}/{{ webroot }}/sites/{{ site.folder }}/settings.php" with_first_found: - - "{{ playbook_dir }}/{{ webroot }}/sites/{{ site.folder }}/{{ build_type }}.settings.php.j2" - - "{{ _ce_deploy_build_dir }}/{{ webroot }}/sites/{{ site.folder }}/{{ build_type }}.settings.php" + - "{{ playbook_dir }}/{{ webroot }}/sites/{{ site.folder }}/{{ build_type }}.{{ config_generate_drupal.drupal_settings_file_name }}.j2" + - "{{ _ce_deploy_build_dir }}/{{ webroot }}/sites/{{ site.folder }}/{{ build_type }}.{{ config_generate_drupal.drupal_settings_file_name }}" + - "{{ _ce_deploy_build_dir }}/{{ webroot }}/sites/{{ site.folder }}/{{ config_generate_drupal.drupal_settings_file_name }}" - "settings.php.j2" diff --git a/roles/config_generate/defaults/main.yml b/roles/config_generate/defaults/main.yml index 5258730e..8f1987eb 100644 --- a/roles/config_generate/defaults/main.yml +++ b/roles/config_generate/defaults/main.yml @@ -3,7 +3,7 @@ config_generate: # Specify any additional 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') - # create: wether to create the target if it does not exists. + # create: whether to create the target if it does not exists. # - src: '/home/{{ deploy_user }}//{{ project_name }}_{{ build_type }}/simplesaml' # dest: 'vendor/simplesamlphp/simplesamlphp/config' # - src: '/var/simplesaml/etc' diff --git a/roles/live_symlink/defaults/main.yml b/roles/live_symlink/defaults/main.yml index 4b9fb449..eca23ad6 100644 --- a/roles/live_symlink/defaults/main.yml +++ b/roles/live_symlink/defaults/main.yml @@ -6,7 +6,7 @@ live_symlink: # Specify any additional 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') - # create: wether to create the target if it does not exists. + # create: whether to create the target if it does not exists. # - src: '/home/{{ deploy_user }}//{{ project_name }}_{{ build_type }}/simplesaml' # dest: 'vendor/simplesamlphp/simplesamlphp/config' # - src: '/var/simplesaml/etc' @@ -15,4 +15,4 @@ live_symlink: # Specify any additional templates to generate, with src (template) and dest (file). # src: name of a template, in the "templates" dir relative to your playbook. # dest: can only be relative to the root of your repository (eg. 'www/config.php', 'var/mysettings.php') - templates: [] \ No newline at end of file + templates: [] diff --git a/roles/npm/README.md b/roles/npm/README.md index 385e1c84..97f06cdc 100644 --- a/roles/npm/README.md +++ b/roles/npm/README.md @@ -18,7 +18,7 @@ npm: # Specify any additional 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') - # create: wether to create the target if it does not exists. + # create: whether to create the target if it does not exists. # - src: '/home/{{ deploy_user }}//{{ project_name }}_{{ build_type }}/simplesaml' # dest: 'vendor/simplesamlphp/simplesamlphp/config' # - src: '/var/simplesaml/etc' @@ -28,6 +28,7 @@ npm: # src: name of a template, in the "templates" dir relative to your playbook. # dest: can only be relative to the root of your repository (eg. 'www/config.php', 'var/mysettings.php') templates: [] + ``` diff --git a/roles/npm/defaults/main.yml b/roles/npm/defaults/main.yml index be6bdc3f..a29fcac7 100644 --- a/roles/npm/defaults/main.yml +++ b/roles/npm/defaults/main.yml @@ -11,7 +11,7 @@ npm: # Specify any additional 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') - # create: wether to create the target if it does not exists. + # create: whether to create the target if it does not exists. # - src: '/home/{{ deploy_user }}//{{ project_name }}_{{ build_type }}/simplesaml' # dest: 'vendor/simplesamlphp/simplesamlphp/config' # - src: '/var/simplesaml/etc' @@ -20,4 +20,4 @@ npm: # Specify any additional templates to generate, with src (template) and dest (file). # src: name of a template, in the "templates" dir relative to your playbook. # dest: can only be relative to the root of your repository (eg. 'www/config.php', 'var/mysettings.php') - templates: [] \ No newline at end of file + templates: [] From 42e8c1f6a7b205424d1f566214250a6832ceb0dc Mon Sep 17 00:00:00 2001 From: Greg Harvey Date: Fri, 19 Jul 2024 13:25:46 +0200 Subject: [PATCH 4/8] First pass at NGINX vhost handling in ce-deploy. --- roles/deploy_code/defaults/main.yml | 8 ++++ roles/deploy_code/tasks/deploy.yml | 65 +++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/roles/deploy_code/defaults/main.yml b/roles/deploy_code/defaults/main.yml index 7b68c3a7..b8220475 100644 --- a/roles/deploy_code/defaults/main.yml +++ b/roles/deploy_code/defaults/main.yml @@ -1,5 +1,13 @@ --- +# Required for NGINX config in feature branching. +_ce_provision_data_dir: /home/deploy/ce-deploy/data + deploy_code: + # Feature branching config. + feature_branch: + enabled: false + # NGINX domains to build, see ce-provision for docs: https://github.com/codeenigma/ce-provision/blob/2.x/roles/debian/nginx/defaults/main.yml#L133 + domains: [] # Specify any additional 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') diff --git a/roles/deploy_code/tasks/deploy.yml b/roles/deploy_code/tasks/deploy.yml index 0d15425c..95e3a310 100644 --- a/roles/deploy_code/tasks/deploy.yml +++ b/roles/deploy_code/tasks/deploy.yml @@ -38,3 +38,68 @@ loop_var: link when: - deploy_code.symlinks | length + +# Additional vhost handling for feature branch builds. + +# Fetch the NGINX domain handling tasks from ce-provision. +- name: Ensure the nginx directory exists. + ansible.builtin.file: + path: "{{ _ce_deploy_base_dir }}/roles/nginx/{{ item }}" + state: directory + mode: '0755' + delegate_to: localhost + with_items: + - tasks + - defaults + - templates + when: deploy_code.feature_branch.enabled + +- name: Fetch the nginx role files from ce-provision. + when: deploy_code.feature_branch.enabled + delegate_to: localhost + block: + - name: Fetch domain.yml. + ansible.builtin.get_url: + url: https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/tasks/domain.yml + dest: "{{ _ce_deploy_base_dir }}/roles/nginx/tasks/domain.yml" + + - name: Fetch defaults. + ansible.builtin.get_url: + url: https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/defaults/main.yml + dest: "{{ _ce_deploy_base_dir }}/roles/nginx/defaults/main.yml" + + - name: Fetch templates. + ansible.builtin.get_url: + url: "https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/templates/{{ item }}" + dest: "{{ _ce_deploy_base_dir }}/roles/nginx/templates/{{ item }}" + with_items: + - vhosts.j2 + - cloudwatch-vhost.json.j2 + +- name: Create vhost. + when: + - deploy_code.feature_branch.domains is defined + - deploy_code.feature_branch.domains | length > 0 + - deploy_code.feature_branch.enabled + become: true + block: + - name: Generate domain specific configuration. + ansible.builtin.include_tasks: "{{ _ce_deploy_base_dir }}/roles/nginx/tasks/domain.yml" + with_items: "{{ deploy_code.feature_branch.domains }}" + loop_control: + loop_var: domain + + - name: Test NGINX configuration. + ansible.builtin.command: nginx -t + register: _nginx_test_result + failed_when: false + + - name: Display NGINX test result. + ansible.builtin.debug: + msg: "{{ _nginx_test_result.stderr }}" + + - name: Ensure NGINX is reloaded. + ansible.builtin.service: + name: nginx + state: reloaded + when: _nginx_test_result.rc == 0 From edb30c9d07e161cb0e72a83a68a4217a077a58de Mon Sep 17 00:00:00 2001 From: Greg Harvey Date: Fri, 19 Jul 2024 13:43:50 +0200 Subject: [PATCH 5/8] Adding in the SSL role from ce-provision. --- roles/deploy_code/tasks/deploy.yml | 66 +++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/roles/deploy_code/tasks/deploy.yml b/roles/deploy_code/tasks/deploy.yml index 95e3a310..9e62c41c 100644 --- a/roles/deploy_code/tasks/deploy.yml +++ b/roles/deploy_code/tasks/deploy.yml @@ -42,33 +42,43 @@ # Additional vhost handling for feature branch builds. # Fetch the NGINX domain handling tasks from ce-provision. -- name: Ensure the nginx directory exists. - ansible.builtin.file: - path: "{{ _ce_deploy_base_dir }}/roles/nginx/{{ item }}" - state: directory - mode: '0755' - delegate_to: localhost - with_items: - - tasks - - defaults - - templates - when: deploy_code.feature_branch.enabled - - name: Fetch the nginx role files from ce-provision. when: deploy_code.feature_branch.enabled delegate_to: localhost block: - - name: Fetch domain.yml. + - name: Ensure the nginx directory exists. + ansible.builtin.file: + path: "{{ _ce_deploy_base_dir }}/roles/nginx/{{ item }}" + state: directory + mode: '0755' + delegate_to: localhost + with_items: + - tasks + - defaults + - templates + + - name: Ensure the ssl directory exists. + ansible.builtin.file: + path: "{{ _ce_deploy_base_dir }}/roles/ssl/{{ item }}" + state: directory + mode: '0755' + delegate_to: localhost + with_items: + - tasks + - defaults + - templates + + - name: Fetch nginx domain.yml. ansible.builtin.get_url: url: https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/tasks/domain.yml dest: "{{ _ce_deploy_base_dir }}/roles/nginx/tasks/domain.yml" - - name: Fetch defaults. + - name: Fetch nginx defaults. ansible.builtin.get_url: url: https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/defaults/main.yml dest: "{{ _ce_deploy_base_dir }}/roles/nginx/defaults/main.yml" - - name: Fetch templates. + - name: Fetch nginx templates. ansible.builtin.get_url: url: "https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/templates/{{ item }}" dest: "{{ _ce_deploy_base_dir }}/roles/nginx/templates/{{ item }}" @@ -76,6 +86,32 @@ - vhosts.j2 - cloudwatch-vhost.json.j2 + - name: Fetch ssl tasks. + ansible.builtin.get_url: + url: "https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/ssl/tasks/{{ item }}.yml" + dest: "{{ _ce_deploy_base_dir }}/roles/ssl/tasks/{{ item }}.yml" + with_items: + - copy + - generate + - letsencrypt + - main + - manual + - selfsigned + - unmanaged + + - name: Fetch ssl defaults. + ansible.builtin.get_url: + url: https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/ssl/defaults/main.yml + dest: "{{ _ce_deploy_base_dir }}/roles/ssl/defaults/main.yml" + + - name: Fetch ssl templates. + ansible.builtin.get_url: + url: "https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/ssl/templates/{{ item }}" + dest: "{{ _ce_deploy_base_dir }}/roles/nginx/ssl/{{ item }}" + with_items: + - le_cron.sh.j2 + +# Generate the NGINX vhost. - name: Create vhost. when: - deploy_code.feature_branch.domains is defined From 9ac0221829b21ade65ad71b4f1ceef2312eaae8a Mon Sep 17 00:00:00 2001 From: Greg Harvey Date: Fri, 19 Jul 2024 13:54:32 +0200 Subject: [PATCH 6/8] Fixing role paths and ensuring NGINX ssl.yml is available. --- roles/deploy_code/tasks/deploy.yml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/roles/deploy_code/tasks/deploy.yml b/roles/deploy_code/tasks/deploy.yml index 9e62c41c..312ae8b3 100644 --- a/roles/deploy_code/tasks/deploy.yml +++ b/roles/deploy_code/tasks/deploy.yml @@ -48,7 +48,7 @@ block: - name: Ensure the nginx directory exists. ansible.builtin.file: - path: "{{ _ce_deploy_base_dir }}/roles/nginx/{{ item }}" + path: "{{ _ce_deploy_base_dir }}/roles/debian/nginx/{{ item }}" state: directory mode: '0755' delegate_to: localhost @@ -59,7 +59,7 @@ - name: Ensure the ssl directory exists. ansible.builtin.file: - path: "{{ _ce_deploy_base_dir }}/roles/ssl/{{ item }}" + path: "{{ _ce_deploy_base_dir }}/roles/debian/ssl/{{ item }}" state: directory mode: '0755' delegate_to: localhost @@ -68,20 +68,23 @@ - defaults - templates - - name: Fetch nginx domain.yml. + - name: Fetch nginx tasks. ansible.builtin.get_url: - url: https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/tasks/domain.yml - dest: "{{ _ce_deploy_base_dir }}/roles/nginx/tasks/domain.yml" + url: "https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/tasks/{{ item }}.yml" + dest: "{{ _ce_deploy_base_dir }}/roles/debian/nginx/tasks/{{ item }}.yml" + with_items: + - domain + - ssl - name: Fetch nginx defaults. ansible.builtin.get_url: url: https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/defaults/main.yml - dest: "{{ _ce_deploy_base_dir }}/roles/nginx/defaults/main.yml" + dest: "{{ _ce_deploy_base_dir }}/roles/debian/nginx/defaults/main.yml" - name: Fetch nginx templates. ansible.builtin.get_url: url: "https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/templates/{{ item }}" - dest: "{{ _ce_deploy_base_dir }}/roles/nginx/templates/{{ item }}" + dest: "{{ _ce_deploy_base_dir }}/roles/debian/nginx/templates/{{ item }}" with_items: - vhosts.j2 - cloudwatch-vhost.json.j2 @@ -89,7 +92,7 @@ - name: Fetch ssl tasks. ansible.builtin.get_url: url: "https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/ssl/tasks/{{ item }}.yml" - dest: "{{ _ce_deploy_base_dir }}/roles/ssl/tasks/{{ item }}.yml" + dest: "{{ _ce_deploy_base_dir }}/roles/debian/ssl/tasks/{{ item }}.yml" with_items: - copy - generate @@ -102,12 +105,12 @@ - name: Fetch ssl defaults. ansible.builtin.get_url: url: https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/ssl/defaults/main.yml - dest: "{{ _ce_deploy_base_dir }}/roles/ssl/defaults/main.yml" + dest: "{{ _ce_deploy_base_dir }}/roles/debian/ssl/defaults/main.yml" - name: Fetch ssl templates. ansible.builtin.get_url: url: "https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/ssl/templates/{{ item }}" - dest: "{{ _ce_deploy_base_dir }}/roles/nginx/ssl/{{ item }}" + dest: "{{ _ce_deploy_base_dir }}/roles/debian/ssl/templates/{{ item }}" with_items: - le_cron.sh.j2 From ca9fc27af93de718b0b7b4f7318f9c73ba3faf24 Mon Sep 17 00:00:00 2001 From: Greg Harvey Date: Fri, 19 Jul 2024 14:09:55 +0200 Subject: [PATCH 7/8] Fixing NGINX role location. --- roles/deploy_code/tasks/deploy.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/roles/deploy_code/tasks/deploy.yml b/roles/deploy_code/tasks/deploy.yml index 312ae8b3..644688cf 100644 --- a/roles/deploy_code/tasks/deploy.yml +++ b/roles/deploy_code/tasks/deploy.yml @@ -68,13 +68,16 @@ - defaults - templates - - name: Fetch nginx tasks. + - name: Fetch nginx domain.yml. ansible.builtin.get_url: - url: "https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/tasks/{{ item }}.yml" - dest: "{{ _ce_deploy_base_dir }}/roles/debian/nginx/tasks/{{ item }}.yml" - with_items: - - domain - - ssl + url: https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/tasks/domain.yml + dest: "{{ _ce_deploy_base_dir }}/roles/debian/nginx/tasks/domain.yml" + + # Because of the way it is called, this needs putting into the playbook directory. + - name: Fetch nginx ssl.yml. + ansible.builtin.get_url: + url: https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/tasks/ssl.yml + dest: "{{ _ce_deploy_build_dir }}/deploy/ssl.yml" - name: Fetch nginx defaults. ansible.builtin.get_url: @@ -123,7 +126,7 @@ become: true block: - name: Generate domain specific configuration. - ansible.builtin.include_tasks: "{{ _ce_deploy_base_dir }}/roles/nginx/tasks/domain.yml" + ansible.builtin.include_tasks: "{{ _ce_deploy_base_dir }}/roles/debian/nginx/tasks/domain.yml" with_items: "{{ deploy_code.feature_branch.domains }}" loop_control: loop_var: domain From 0841be47add1a461859c8b9edf5c9ba2a4bcc873 Mon Sep 17 00:00:00 2001 From: Greg Harvey Date: Fri, 19 Jul 2024 14:17:32 +0200 Subject: [PATCH 8/8] Tweaking location of domain.yml so it loads the templates correctly. --- roles/deploy_code/tasks/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/deploy_code/tasks/deploy.yml b/roles/deploy_code/tasks/deploy.yml index 644688cf..032e1577 100644 --- a/roles/deploy_code/tasks/deploy.yml +++ b/roles/deploy_code/tasks/deploy.yml @@ -71,7 +71,7 @@ - name: Fetch nginx domain.yml. ansible.builtin.get_url: url: https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/tasks/domain.yml - dest: "{{ _ce_deploy_base_dir }}/roles/debian/nginx/tasks/domain.yml" + dest: "{{ _ce_deploy_base_dir }}/roles/debian/nginx/domain.yml" # Because of the way it is called, this needs putting into the playbook directory. - name: Fetch nginx ssl.yml. @@ -126,7 +126,7 @@ become: true block: - name: Generate domain specific configuration. - ansible.builtin.include_tasks: "{{ _ce_deploy_base_dir }}/roles/debian/nginx/tasks/domain.yml" + ansible.builtin.include_tasks: "{{ _ce_deploy_base_dir }}/roles/debian/nginx/domain.yml" with_items: "{{ deploy_code.feature_branch.domains }}" loop_control: loop_var: domain