From 514a95f6ab2927a95c0fe11aac0e7bf0ba5377e9 Mon Sep 17 00:00:00 2001 From: GraceRuan Date: Tue, 16 Apr 2024 14:08:15 -0700 Subject: [PATCH 1/3] feat: add playbook build generator --- generators/gh-maven-build/index.js | 43 +++++++++- generators/playbook-build/index.js | 58 +++++++++++++ .../playbook-build/templates/playbook.yaml | 83 +++++++++++++++++++ .../playbook-build/templates/vars/all.yaml | 30 +++++++ .../playbook-build/templates/vars/dev.yaml | 30 +++++++ 5 files changed, 242 insertions(+), 2 deletions(-) create mode 100644 generators/playbook-build/index.js create mode 100644 generators/playbook-build/templates/playbook.yaml create mode 100644 generators/playbook-build/templates/vars/all.yaml create mode 100644 generators/playbook-build/templates/vars/dev.yaml diff --git a/generators/gh-maven-build/index.js b/generators/gh-maven-build/index.js index 7c7ba7d..f449154 100644 --- a/generators/gh-maven-build/index.js +++ b/generators/gh-maven-build/index.js @@ -52,6 +52,11 @@ export default class extends Generator { "The path to where your pom file is located relative to the repository's root", ), ); + this.log( + ' ' + + chalk.bold('GitHub Owner with repo path: ') + + chalk.dim('The Github owner with repo path (eg. bcgov-nr/edqa-war) '), + ); this.log(''); this.log(chalk.bold('Prompts')); @@ -94,8 +99,8 @@ export default class extends Generator { { type: 'input', name: 'gitHubOwnerPack', - message: 'GitHub Owner with repo path (eg. bcgov-nr-labs/edqa-war):', - default: 'bcgov-nr-labs/edqa-war', + message: 'GitHub Owner with repo path (eg. bcgov-nr/edqa-war):', + default: 'bcgov-nr/edqa-war', store: true, when: (answers) => answers.gitHubPackages, }, @@ -122,6 +127,14 @@ export default class extends Generator { default: false, store: true, }, + { + type: 'input', + name: 'playbookPath', + message: 'Playbook path:(./playbooks/)', + default: './playbooks/', + store: true, + when: (answers) => answers.deployOnPrem, + }, ]); this.props = answers; @@ -178,6 +191,32 @@ export default class extends Generator { }, ); } + if (this.props.deployOnPrem) { + this.log('writing - turbo'); + this.composeWith('../playbook-build', { + arguments: ['edqa', 'edqa-war', 'playbooks/'], + }); + /* + this.composeWith('../playbook-build', { + arguments: [ + this.props.projectName, + this.props.serviceName, + this.props.playbookPath, + ], + });*/ + } + + /* + + this.composeWith({ + Generator: playbooGenerator, + path: '../playbook-build', + }); + this.composeWith(path.resolve(__dirname, '../playbook-build/index.js'), { + projectName: this.props.projectName, + serviceName: this.props.serviceName, + playbookPath: this.props.playbookPath, + });*/ this.config.save(); } diff --git a/generators/playbook-build/index.js b/generators/playbook-build/index.js new file mode 100644 index 0000000..aa49d78 --- /dev/null +++ b/generators/playbook-build/index.js @@ -0,0 +1,58 @@ +'use strict'; +import Generator from 'yeoman-generator'; +import yosay from 'yosay'; +import chalk from 'chalk'; +import path from 'path'; + +/** + * Generate the CI workflow and NR Broker intention files needed Java/Tomcat Maven builds in GitHub + */ +export default class extends Generator { + constructor(args, opts) { + super(args, opts); + + this.argument('projectName', { + type: String, + required: true, + //default: 'edqa', + description: 'Project Name', + }); + this.argument('servceName', { + type: String, + required: true, + // default: 'edqa-war', + description: 'Service Name', + }); + this.argument('playbookPath', { + type: String, + required: true, + //default: 'playbooks/', + description: 'Playbook Path', + }); + } + + // Generate GitHub workflows and NR Broker intention files + writing() { + this.log('writing - playbook files'); + this.fs.copyTpl( + this.templatePath('playbook.yaml'), + this.destinationPath('playbooks/playbook.yaml'), + { + projectName: 'edqa', + serviceName: 'edqa-war', + }, + ); + /* + this.fs.copy( + this.templatePath('templates/vars/**'), + this.destinationPath('playbooks/vars'), + { + projectName: this.options.projectName, + serviceName: this.options.serviceName, + projectCapName: this.options.projectName.toUpperCase(), + }, + ); + */ + this.config.save(); + } +} diff --git a/generators/playbook-build/templates/playbook.yaml b/generators/playbook-build/templates/playbook.yaml new file mode 100644 index 0000000..608c4c3 --- /dev/null +++ b/generators/playbook-build/templates/playbook.yaml @@ -0,0 +1,83 @@ +--- +- name: <%= projectName %>/<%= serviceName %> + hosts: "{{ tomcat_server_hosts }}" + collections: + - polaris.deploy + vars_files: + - "vars/all.yaml" + - "vars/{{env_vars}}.yaml" + + roles: + # Establish the port number + - name: port_manager + become: yes + become_user: 'wwwadm' + + # prepare the installation environment by creating the necessary folders + - name: cd_prepare + + # individual JDK installation + - name: jdk + vars: + jdk_version: + type: 'openjdk' + major_version: 8 + url: '{{ artifactory_url }}/ext-binaries-local/openjdk/java-se-8u40-ri.tar.gz' + filename: 'java-se-8u40-ri.tar.gz' + checksum: 'sha1:606984531e3eeddba6be5ac626a229ef283c5de0' + cacerts_path: 'jre/lib/security/cacerts' + use_proxy: false + + # create a self signed certificate to allow for HTTPS + - name: self_signed_cert + + # install & configure the Tomcat container + - name: tomcat + + # deploy the webapp + - name: webapp + vars: + webapp_war: + context: "{{ context }}" + jndi_resources: + - "{{ webade_bootstrap_jdbc }}" + webapp_root_log_level: "{{ log_level_root | default('INFO') }}" + proxy_env: "{{ env_vars }}" + + # create a WebADE connection jar for the container + - name: webade_connection_jar + vars: + webade_install_dir: "{{ cd_app_install }}/webapps/{{ alt_app_dir_name }}/WEB-INF/lib" + webade_datastore: "ca.bc.gov.webade.mof.MOFOrganizationDatastore" + become: yes + become_user: "{{ install_user }}" + + tasks: + - name: configure nonstandard files + template: + src: "{{ playbook_dir }}/templates/{{ item.src }}" + dest: "{{ item.dest }}" + mode: 0775 + become: yes + become_user: "{{ install_user }}" + with_items: + - { + src: "web.xml.j2", + dest: "{{ cd_app_install }}/webapps/{{ context }}/WEB-INF/web.xml" + } + - { + src: "JMSConfig.xml.j2", + dest: "{{ cd_app_install }}/webapps/{{ context }}/WEB-INF/classes/JMSConfig.xml" + } + - { + src: "tasks.xml.j2", + dest: "{{ cd_app_install }}/webapps/{{ context }}/WEB-INF/classes/tasks.xml" + } + + - name: "set version {{ pd_prop_project_version }} as current" + file: + path: "{{ cd_app_home }}/current" + src: "{{ cd_app_install }}" + state: link + become: yes + become_user: "{{ install_user }}" \ No newline at end of file diff --git a/generators/playbook-build/templates/vars/all.yaml b/generators/playbook-build/templates/vars/all.yaml new file mode 100644 index 0000000..16066a9 --- /dev/null +++ b/generators/playbook-build/templates/vars/all.yaml @@ -0,0 +1,30 @@ +ssh_user: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_USER') }}" +ssh_pass: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_PASS') }}" +ansible_user: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_USER') }}" +ansible_become_password: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_PASS') }}" +ansible_ssh_extra_args: "-o StrictHostKeyChecking=no" +cd_project: "<%= projectCapName %>" +cd_component: "<%= serviceName %>" +pd_prop_project_version: "{{ lookup('ansible.builtin.env', 'PODMAN_PROJECT_VERSION') }}" +context: "ext#<%= projectName %>" +cd_apps_home: "/apps_ux" +cd_apps_data: "/apps_data" +cd_apps_logs: "{{ cd_apps_home }}/logs" +artifact: "{{ hostvars.localhost.modules['<%= serviceName %>'].artifacts['<%= serviceName %>-war.war'] }}" +tomcat_https_port: "{{ portmanager_assignments[ansible_host] }}" +context_list: [] +portmanager_debug: False +tomcat_version_number: "8.5.51" +log_level_root: "INFO" +install_user: "wwwadm" +run_user: "wwwsvr" +cd_app_home: "/apps_ux/<%= projectCapName %>/<%= serviceName %>" +cd_app_install: "{{ cd_app_home }}/{{ pd_prop_project_version }}" +alt_app_dir_name: ext_<%= projectName %> +pd_prop_artifact_name: "{{ lookup('ansible.builtin.env', 'PODMAN_ARTIFACT_NAME') }}" +pd_prop_artifact_sha256: "{{ lookup('ansible.builtin.env', 'PODMAN_ARTIFACT_SHA256') }}" +cd_app_service: "/apps_ux/s6_services/<%= serviceName %>" + +cfg_webapp_version: "{{ pd_prop_project_version }}" +cfg_app_main_db: "ca.bc.gov.mof" +cfg_object_base: "/ext/<%= projectName %>" diff --git a/generators/playbook-build/templates/vars/dev.yaml b/generators/playbook-build/templates/vars/dev.yaml new file mode 100644 index 0000000..16066a9 --- /dev/null +++ b/generators/playbook-build/templates/vars/dev.yaml @@ -0,0 +1,30 @@ +ssh_user: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_USER') }}" +ssh_pass: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_PASS') }}" +ansible_user: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_USER') }}" +ansible_become_password: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_PASS') }}" +ansible_ssh_extra_args: "-o StrictHostKeyChecking=no" +cd_project: "<%= projectCapName %>" +cd_component: "<%= serviceName %>" +pd_prop_project_version: "{{ lookup('ansible.builtin.env', 'PODMAN_PROJECT_VERSION') }}" +context: "ext#<%= projectName %>" +cd_apps_home: "/apps_ux" +cd_apps_data: "/apps_data" +cd_apps_logs: "{{ cd_apps_home }}/logs" +artifact: "{{ hostvars.localhost.modules['<%= serviceName %>'].artifacts['<%= serviceName %>-war.war'] }}" +tomcat_https_port: "{{ portmanager_assignments[ansible_host] }}" +context_list: [] +portmanager_debug: False +tomcat_version_number: "8.5.51" +log_level_root: "INFO" +install_user: "wwwadm" +run_user: "wwwsvr" +cd_app_home: "/apps_ux/<%= projectCapName %>/<%= serviceName %>" +cd_app_install: "{{ cd_app_home }}/{{ pd_prop_project_version }}" +alt_app_dir_name: ext_<%= projectName %> +pd_prop_artifact_name: "{{ lookup('ansible.builtin.env', 'PODMAN_ARTIFACT_NAME') }}" +pd_prop_artifact_sha256: "{{ lookup('ansible.builtin.env', 'PODMAN_ARTIFACT_SHA256') }}" +cd_app_service: "/apps_ux/s6_services/<%= serviceName %>" + +cfg_webapp_version: "{{ pd_prop_project_version }}" +cfg_app_main_db: "ca.bc.gov.mof" +cfg_object_base: "/ext/<%= projectName %>" From 3a10db5530bcb715a5ccc48e9d82c3e1c1b86a15 Mon Sep 17 00:00:00 2001 From: Andreas Wilson <41663792+andrwils@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:38:12 -0700 Subject: [PATCH 2/3] feat: playbook generator changes --- generators/gh-maven-build/index.js | 37 +++----------- generators/playbook-build/index.js | 23 ++++----- .../playbook-build/templates/vars/all.yaml | 48 +++++++++---------- .../playbook-build/templates/vars/dev.yaml | 38 ++++----------- .../playbook-build/templates/vars/prod.yaml | 8 ++++ .../playbook-build/templates/vars/test.yaml | 8 ++++ 6 files changed, 62 insertions(+), 100 deletions(-) create mode 100644 generators/playbook-build/templates/vars/prod.yaml create mode 100644 generators/playbook-build/templates/vars/test.yaml diff --git a/generators/gh-maven-build/index.js b/generators/gh-maven-build/index.js index f449154..408a0ff 100644 --- a/generators/gh-maven-build/index.js +++ b/generators/gh-maven-build/index.js @@ -55,7 +55,7 @@ export default class extends Generator { this.log( ' ' + chalk.bold('GitHub Owner with repo path: ') + - chalk.dim('The Github owner with repo path (eg. bcgov-nr/edqa-war) '), + chalk.dim('The Github owner with repo path (e.g. bcgov-nr/edqa-war) '), ); this.log(''); @@ -99,8 +99,7 @@ export default class extends Generator { { type: 'input', name: 'gitHubOwnerPack', - message: 'GitHub Owner with repo path (eg. bcgov-nr/edqa-war):', - default: 'bcgov-nr/edqa-war', + message: 'GitHub Owner with repo path (e.g. bcgov-nr/edqa-war):', store: true, when: (answers) => answers.gitHubPackages, }, @@ -130,8 +129,8 @@ export default class extends Generator { { type: 'input', name: 'playbookPath', - message: 'Playbook path:(./playbooks/)', - default: './playbooks/', + message: 'Playbook path: (playbooks)', + default: 'playbooks', store: true, when: (answers) => answers.deployOnPrem, }, @@ -190,33 +189,9 @@ export default class extends Generator { serviceName: this.props.serviceName, }, ); + const playbook_args = [this.props.projectName, this.props.serviceName, this.props.playbookPath] + this.composeWith('nr-repository-composer:playbook-build', playbook_args) } - if (this.props.deployOnPrem) { - this.log('writing - turbo'); - this.composeWith('../playbook-build', { - arguments: ['edqa', 'edqa-war', 'playbooks/'], - }); - /* - this.composeWith('../playbook-build', { - arguments: [ - this.props.projectName, - this.props.serviceName, - this.props.playbookPath, - ], - });*/ - } - - /* - - this.composeWith({ - Generator: playbooGenerator, - path: '../playbook-build', - }); - this.composeWith(path.resolve(__dirname, '../playbook-build/index.js'), { - projectName: this.props.projectName, - serviceName: this.props.serviceName, - playbookPath: this.props.playbookPath, - });*/ this.config.save(); } diff --git a/generators/playbook-build/index.js b/generators/playbook-build/index.js index aa49d78..f500b11 100644 --- a/generators/playbook-build/index.js +++ b/generators/playbook-build/index.js @@ -14,45 +14,40 @@ export default class extends Generator { this.argument('projectName', { type: String, required: true, - //default: 'edqa', description: 'Project Name', }); - this.argument('servceName', { + this.argument('serviceName', { type: String, required: true, - // default: 'edqa-war', description: 'Service Name', }); this.argument('playbookPath', { type: String, required: true, - //default: 'playbooks/', description: 'Playbook Path', }); } // Generate GitHub workflows and NR Broker intention files writing() { - this.log('writing - playbook files'); + this.log('Generating playbook files'); this.fs.copyTpl( this.templatePath('playbook.yaml'), - this.destinationPath('playbooks/playbook.yaml'), + this.destinationPath(`${this.options.playbookPath}/playbook.yaml`), { - projectName: 'edqa', - serviceName: 'edqa-war', + projectName: this.options.projectName, + serviceName: this.options.serviceName, }, ); - /* - this.fs.copy( - this.templatePath('templates/vars/**'), - this.destinationPath('playbooks/vars'), + this.fs.copyTpl( + this.templatePath('vars/**'), + this.destinationPath(`${this.options.playbookPath}/vars`), { projectName: this.options.projectName, serviceName: this.options.serviceName, - projectCapName: this.options.projectName.toUpperCase(), + projectNameUpperCase: this.options.projectName.toUpperCase(), }, ); - */ this.config.save(); } } diff --git a/generators/playbook-build/templates/vars/all.yaml b/generators/playbook-build/templates/vars/all.yaml index 16066a9..eade5af 100644 --- a/generators/playbook-build/templates/vars/all.yaml +++ b/generators/playbook-build/templates/vars/all.yaml @@ -1,30 +1,28 @@ -ssh_user: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_USER') }}" -ssh_pass: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_PASS') }}" -ansible_user: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_USER') }}" -ansible_become_password: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_PASS') }}" +# Ansible connection properties +ssh_user: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_USER') }}" +ssh_pass: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_PASS') }}" +ansible_user: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_USER') }}" +ansible_become_password: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_PASS') }}" ansible_ssh_extra_args: "-o StrictHostKeyChecking=no" -cd_project: "<%= projectCapName %>" -cd_component: "<%= serviceName %>" + +# General properties +pd_prop_project_name: "<%= projectNameUpperCase %>" +pd_prop_service_name: "<%= serviceName %>" pd_prop_project_version: "{{ lookup('ansible.builtin.env', 'PODMAN_PROJECT_VERSION') }}" -context: "ext#<%= projectName %>" -cd_apps_home: "/apps_ux" -cd_apps_data: "/apps_data" -cd_apps_logs: "{{ cd_apps_home }}/logs" -artifact: "{{ hostvars.localhost.modules['<%= serviceName %>'].artifacts['<%= serviceName %>-war.war'] }}" -tomcat_https_port: "{{ portmanager_assignments[ansible_host] }}" -context_list: [] -portmanager_debug: False -tomcat_version_number: "8.5.51" -log_level_root: "INFO" -install_user: "wwwadm" -run_user: "wwwsvr" -cd_app_home: "/apps_ux/<%= projectCapName %>/<%= serviceName %>" -cd_app_install: "{{ cd_app_home }}/{{ pd_prop_project_version }}" -alt_app_dir_name: ext_<%= projectName %> pd_prop_artifact_name: "{{ lookup('ansible.builtin.env', 'PODMAN_ARTIFACT_NAME') }}" pd_prop_artifact_sha256: "{{ lookup('ansible.builtin.env', 'PODMAN_ARTIFACT_SHA256') }}" -cd_app_service: "/apps_ux/s6_services/<%= serviceName %>" +pd_prop_build_number: "{{ lookup('ansible.builtin.env', 'PODMAN_BUILD_NUMBER') }}" +pd_prop_project_version_run: "{{ pd_prop_project_version }}-{{ pd_prop_build_number }}" + +# Properties for creating directories +pd_prop_project_home: "/apps_ux/<%= projectNameUpperCase %>" +pd_prop_service_home: "/apps_ux/<%= projectNameUpperCase %>/<%= serviceName %>" +pd_prop_service_install_directory: "/apps_ux/<%= projectNameUpperCase %>/<%= serviceName %>/{{ pd_prop_project_version_run }}" +pd_prop_service_current_version: "/apps_ux/<%= projectNameUpperCase %>/<%= serviceName %>/current" +pd_prop_service_data: "/apps_data/<%= projectNameUpperCase %>/<%= serviceName %>" +pd_prop_service_logs: "/apps_ux/logs/<%= projectNameUpperCase %>/<%= serviceName %>" +pd_prop_service_s6_path: "/apps_ux/s6_services/<%= serviceName %>" + +# Tomcat properties -cfg_webapp_version: "{{ pd_prop_project_version }}" -cfg_app_main_db: "ca.bc.gov.mof" -cfg_object_base: "/ext/<%= projectName %>" +# Webapp properties diff --git a/generators/playbook-build/templates/vars/dev.yaml b/generators/playbook-build/templates/vars/dev.yaml index 16066a9..3bdddf2 100644 --- a/generators/playbook-build/templates/vars/dev.yaml +++ b/generators/playbook-build/templates/vars/dev.yaml @@ -1,30 +1,8 @@ -ssh_user: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_USER') }}" -ssh_pass: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_PASS') }}" -ansible_user: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_USER') }}" -ansible_become_password: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_PASS') }}" -ansible_ssh_extra_args: "-o StrictHostKeyChecking=no" -cd_project: "<%= projectCapName %>" -cd_component: "<%= serviceName %>" -pd_prop_project_version: "{{ lookup('ansible.builtin.env', 'PODMAN_PROJECT_VERSION') }}" -context: "ext#<%= projectName %>" -cd_apps_home: "/apps_ux" -cd_apps_data: "/apps_data" -cd_apps_logs: "{{ cd_apps_home }}/logs" -artifact: "{{ hostvars.localhost.modules['<%= serviceName %>'].artifacts['<%= serviceName %>-war.war'] }}" -tomcat_https_port: "{{ portmanager_assignments[ansible_host] }}" -context_list: [] -portmanager_debug: False -tomcat_version_number: "8.5.51" -log_level_root: "INFO" -install_user: "wwwadm" -run_user: "wwwsvr" -cd_app_home: "/apps_ux/<%= projectCapName %>/<%= serviceName %>" -cd_app_install: "{{ cd_app_home }}/{{ pd_prop_project_version }}" -alt_app_dir_name: ext_<%= projectName %> -pd_prop_artifact_name: "{{ lookup('ansible.builtin.env', 'PODMAN_ARTIFACT_NAME') }}" -pd_prop_artifact_sha256: "{{ lookup('ansible.builtin.env', 'PODMAN_ARTIFACT_SHA256') }}" -cd_app_service: "/apps_ux/s6_services/<%= serviceName %>" - -cfg_webapp_version: "{{ pd_prop_project_version }}" -cfg_app_main_db: "ca.bc.gov.mof" -cfg_object_base: "/ext/<%= projectName %>" +# Webade connection properties +# webade_jdbc_url: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_jdbc_url') }}" +# webade_datastore: "ca.bc.gov.webade.mof.MOFOrganizationDatastore" +# webade_min_connections: 0 +# webade_max_connections: 10 +# webade_db_user: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_username') }}" +# webade_db_pass: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_password') }}" +# webade_env: DEV diff --git a/generators/playbook-build/templates/vars/prod.yaml b/generators/playbook-build/templates/vars/prod.yaml new file mode 100644 index 0000000..c6b2861 --- /dev/null +++ b/generators/playbook-build/templates/vars/prod.yaml @@ -0,0 +1,8 @@ +# Webade connection properties +# webade_jdbc_url: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_jdbc_url') }}" +# webade_datastore: "ca.bc.gov.webade.mof.MOFOrganizationDatastore" +# webade_min_connections: 0 +# webade_max_connections: 10 +# webade_db_user: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_username') }}" +# webade_db_pass: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_password') }}" +# webade_env: PROD diff --git a/generators/playbook-build/templates/vars/test.yaml b/generators/playbook-build/templates/vars/test.yaml new file mode 100644 index 0000000..c6e109f --- /dev/null +++ b/generators/playbook-build/templates/vars/test.yaml @@ -0,0 +1,8 @@ +# Webade connection properties +# webade_jdbc_url: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_jdbc_url') }}" +# webade_datastore: "ca.bc.gov.webade.mof.MOFOrganizationDatastore" +# webade_min_connections: 0 +# webade_max_connections: 10 +# webade_db_user: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_username') }}" +# webade_db_pass: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_password') }}" +# webade_env: TEST From a093ea89dbdb164db13592bb348fec8eacc31804 Mon Sep 17 00:00:00 2001 From: Andreas Wilson <41663792+andrwils@users.noreply.github.com> Date: Tue, 30 Apr 2024 11:12:29 -0700 Subject: [PATCH 3/3] feat: init custom variable files --- generators/gh-maven-build/index.js | 47 ++++++++++++++++--- .../index.js | 33 +++++++++++-- .../templates/playbook.yaml | 41 +++++++--------- .../templates/vars/custom/all.yaml | 1 + .../templates/vars/custom/dev.yaml | 1 + .../templates/vars/custom/prod.yaml | 1 + .../templates/vars/custom/test.yaml | 1 + .../templates/vars/standard}/all.yaml | 21 +++++---- .../templates/vars/standard/dev.yaml | 7 +++ .../templates/vars/standard/prod.yaml | 7 +++ .../templates/vars/standard/test.yaml | 7 +++ .../playbook-build/templates/vars/dev.yaml | 8 ---- .../playbook-build/templates/vars/prod.yaml | 8 ---- .../playbook-build/templates/vars/test.yaml | 8 ---- 14 files changed, 122 insertions(+), 69 deletions(-) rename generators/{playbook-build => pd-ansible-playbook}/index.js (51%) rename generators/{playbook-build => pd-ansible-playbook}/templates/playbook.yaml (57%) create mode 100644 generators/pd-ansible-playbook/templates/vars/custom/all.yaml create mode 100644 generators/pd-ansible-playbook/templates/vars/custom/dev.yaml create mode 100644 generators/pd-ansible-playbook/templates/vars/custom/prod.yaml create mode 100644 generators/pd-ansible-playbook/templates/vars/custom/test.yaml rename generators/{playbook-build/templates/vars => pd-ansible-playbook/templates/vars/standard}/all.yaml (57%) create mode 100644 generators/pd-ansible-playbook/templates/vars/standard/dev.yaml create mode 100644 generators/pd-ansible-playbook/templates/vars/standard/prod.yaml create mode 100644 generators/pd-ansible-playbook/templates/vars/standard/test.yaml delete mode 100644 generators/playbook-build/templates/vars/dev.yaml delete mode 100644 generators/playbook-build/templates/vars/prod.yaml delete mode 100644 generators/playbook-build/templates/vars/test.yaml diff --git a/generators/gh-maven-build/index.js b/generators/gh-maven-build/index.js index 408a0ff..bac1db9 100644 --- a/generators/gh-maven-build/index.js +++ b/generators/gh-maven-build/index.js @@ -4,7 +4,7 @@ import yosay from 'yosay'; import chalk from 'chalk'; /** - * Generate the CI workflow and NR Broker intention files needed Java/Tomcat Maven builds in GitHub + * Generate the CI workflow and NR Broker intention files needed for Java/Tomcat Maven builds in GitHub */ export default class extends Generator { async prompting() { @@ -92,14 +92,14 @@ export default class extends Generator { { type: 'confirm', name: 'gitHubPackages', - message: 'Publish to GitHub Packages?', + message: 'Publish to GitHub Packages:', default: false, store: true, }, { type: 'input', name: 'gitHubOwnerPack', - message: 'GitHub Owner with repo path (e.g. bcgov-nr/edqa-war):', + message: 'GitHub Owner with repo path (e.g. bcgov-nr/results-war):', store: true, when: (answers) => answers.gitHubPackages, }, @@ -122,18 +122,48 @@ export default class extends Generator { { type: 'confirm', name: 'deployOnPrem', - message: 'Deploy on-prem?', + message: 'Deploy on-prem:', default: false, store: true, }, { type: 'input', name: 'playbookPath', - message: 'Playbook path: (playbooks)', + message: 'Playbook path:', default: 'playbooks', store: true, when: (answers) => answers.deployOnPrem, }, + { + type: 'input', + name: 'tomcatContext', + message: 'Tomcat Context (e.g. ext#results):', + store: true, + when: (answers) => answers.deployOnPrem, + }, + { + type: 'confirm', + name: 'useAltAppDirName', + message: 'Use alternative webapp directory:', + default: false, + store: true, + when: (answers) => answers.deployOnPrem, + }, + { + type: 'input', + name: 'altAppDirName', + message: 'Alternative webapp directory name:', + store: true, + when: (answers) => answers.useAltAppDirName, + }, + { + type: 'confirm', + name: 'addWebadeConfig', + message: 'Add Webade configuration:', + default: false, + store: true, + when: (answers) => answers.deployOnPrem, + } ]); this.props = answers; @@ -189,8 +219,11 @@ export default class extends Generator { serviceName: this.props.serviceName, }, ); - const playbook_args = [this.props.projectName, this.props.serviceName, this.props.playbookPath] - this.composeWith('nr-repository-composer:playbook-build', playbook_args) + const playbook_args = [this.props.projectName, this.props.serviceName, this.props.playbookPath, + this.props.tomcatContext, this.props.altAppDirName + ] + const playbook_options = { addWebadeConfig: this.props.addWebadeConfig, altAppDirName: this.props.altAppDirName } + this.composeWith('nr-repository-composer:pd-ansible-playbook', playbook_args, playbook_options) } this.config.save(); diff --git a/generators/playbook-build/index.js b/generators/pd-ansible-playbook/index.js similarity index 51% rename from generators/playbook-build/index.js rename to generators/pd-ansible-playbook/index.js index f500b11..3bd973c 100644 --- a/generators/playbook-build/index.js +++ b/generators/pd-ansible-playbook/index.js @@ -3,9 +3,10 @@ import Generator from 'yeoman-generator'; import yosay from 'yosay'; import chalk from 'chalk'; import path from 'path'; +import * as fs from 'node:fs'; /** - * Generate the CI workflow and NR Broker intention files needed Java/Tomcat Maven builds in GitHub + * Generate the Ansible playbook and variable files needed for Tomcat webapp deployments */ export default class extends Generator { constructor(args, opts) { @@ -26,6 +27,19 @@ export default class extends Generator { required: true, description: 'Playbook Path', }); + this.argument('tomcatContext', { + type: String, + required: true, + description: 'Tomcat Context', + }); + this.option('altAppDirName', { + type: String, + description: 'Alternative webapp directory name', + }); + this.option('addWebadeConfig', { + type: String, + description: 'Add Webade configuration', + }); } // Generate GitHub workflows and NR Broker intention files @@ -40,14 +54,27 @@ export default class extends Generator { }, ); this.fs.copyTpl( - this.templatePath('vars/**'), - this.destinationPath(`${this.options.playbookPath}/vars`), + this.templatePath('vars/standard/**'), + this.destinationPath(`${this.options.playbookPath}/vars/standard`), { projectName: this.options.projectName, serviceName: this.options.serviceName, projectNameUpperCase: this.options.projectName.toUpperCase(), + tomcatContext: this.options.tomcatContext, + altAppDirName: this.options.altAppDirName, + addWebadeConfig: this.options.addWebadeConfig, }, ); + // Initialize empty files that can be used for custom variables + // Skip copying templates if any custom files already exist + if (!fs.existsSync(this.destinationPath(`${this.options.playbookPath}/vars/custom`))) { + this.fs.copyTpl( + this.templatePath('vars/custom/**'), + this.destinationPath(`${this.options.playbookPath}/vars/custom`), + {}, + ); + } + this.config.save(); } } diff --git a/generators/playbook-build/templates/playbook.yaml b/generators/pd-ansible-playbook/templates/playbook.yaml similarity index 57% rename from generators/playbook-build/templates/playbook.yaml rename to generators/pd-ansible-playbook/templates/playbook.yaml index 608c4c3..a031c49 100644 --- a/generators/playbook-build/templates/playbook.yaml +++ b/generators/pd-ansible-playbook/templates/playbook.yaml @@ -1,20 +1,20 @@ --- - name: <%= projectName %>/<%= serviceName %> - hosts: "{{ tomcat_server_hosts }}" + hosts: tomcat-servers collections: - polaris.deploy vars_files: - - "vars/all.yaml" - - "vars/{{env_vars}}.yaml" + - "vars/standard/all.yaml" + - "vars/standard/{{env_vars}}.yaml" + - "vars/custom/all.yaml" + - "vars/custom/{{env_vars}}.yaml" roles: # Establish the port number - name: port_manager - become: yes - become_user: 'wwwadm' # prepare the installation environment by creating the necessary folders - - name: cd_prepare + - name: create_project_directories # individual JDK installation - name: jdk @@ -28,7 +28,7 @@ cacerts_path: 'jre/lib/security/cacerts' use_proxy: false - # create a self signed certificate to allow for HTTPS + # create a self signed certificate to allow for HTTPS - name: self_signed_cert # install & configure the Tomcat container @@ -39,45 +39,36 @@ vars: webapp_war: context: "{{ context }}" - jndi_resources: - - "{{ webade_bootstrap_jdbc }}" - webapp_root_log_level: "{{ log_level_root | default('INFO') }}" proxy_env: "{{ env_vars }}" # create a WebADE connection jar for the container - name: webade_connection_jar - vars: - webade_install_dir: "{{ cd_app_install }}/webapps/{{ alt_app_dir_name }}/WEB-INF/lib" - webade_datastore: "ca.bc.gov.webade.mof.MOFOrganizationDatastore" + # Uncomment the following line if using the MOF Webade datastore + # vars: + # webade_datastore: "ca.bc.gov.webade.mof.MOFOrganizationDatastore" become: yes become_user: "{{ install_user }}" tasks: + # The following task is an example for adding custom webapp configuration files + # You can modify it according to your needs or remove it if custom configuration is not needed - name: configure nonstandard files template: src: "{{ playbook_dir }}/templates/{{ item.src }}" dest: "{{ item.dest }}" - mode: 0775 + mode: "0775" become: yes become_user: "{{ install_user }}" with_items: - { src: "web.xml.j2", - dest: "{{ cd_app_install }}/webapps/{{ context }}/WEB-INF/web.xml" + dest: "{{ pd_prop_service_install_directory }}/webapps/{{ alt_app_dir_name or context }}/WEB-INF/web.xml" } - { src: "JMSConfig.xml.j2", - dest: "{{ cd_app_install }}/webapps/{{ context }}/WEB-INF/classes/JMSConfig.xml" + dest: "{{ pd_prop_service_install_directory }}/webapps/{{ alt_app_dir_name or context }}/WEB-INF/classes/JMSConfig.xml" } - { src: "tasks.xml.j2", - dest: "{{ cd_app_install }}/webapps/{{ context }}/WEB-INF/classes/tasks.xml" + dest: "{{ pd_prop_service_install_directory }}/webapps/{{ alt_app_dir_name or context }}/WEB-INF/classes/tasks.xml" } - - - name: "set version {{ pd_prop_project_version }} as current" - file: - path: "{{ cd_app_home }}/current" - src: "{{ cd_app_install }}" - state: link - become: yes - become_user: "{{ install_user }}" \ No newline at end of file diff --git a/generators/pd-ansible-playbook/templates/vars/custom/all.yaml b/generators/pd-ansible-playbook/templates/vars/custom/all.yaml new file mode 100644 index 0000000..209a278 --- /dev/null +++ b/generators/pd-ansible-playbook/templates/vars/custom/all.yaml @@ -0,0 +1 @@ +# Use this file for custom variables related to your webapp diff --git a/generators/pd-ansible-playbook/templates/vars/custom/dev.yaml b/generators/pd-ansible-playbook/templates/vars/custom/dev.yaml new file mode 100644 index 0000000..209a278 --- /dev/null +++ b/generators/pd-ansible-playbook/templates/vars/custom/dev.yaml @@ -0,0 +1 @@ +# Use this file for custom variables related to your webapp diff --git a/generators/pd-ansible-playbook/templates/vars/custom/prod.yaml b/generators/pd-ansible-playbook/templates/vars/custom/prod.yaml new file mode 100644 index 0000000..209a278 --- /dev/null +++ b/generators/pd-ansible-playbook/templates/vars/custom/prod.yaml @@ -0,0 +1 @@ +# Use this file for custom variables related to your webapp diff --git a/generators/pd-ansible-playbook/templates/vars/custom/test.yaml b/generators/pd-ansible-playbook/templates/vars/custom/test.yaml new file mode 100644 index 0000000..209a278 --- /dev/null +++ b/generators/pd-ansible-playbook/templates/vars/custom/test.yaml @@ -0,0 +1 @@ +# Use this file for custom variables related to your webapp diff --git a/generators/playbook-build/templates/vars/all.yaml b/generators/pd-ansible-playbook/templates/vars/standard/all.yaml similarity index 57% rename from generators/playbook-build/templates/vars/all.yaml rename to generators/pd-ansible-playbook/templates/vars/standard/all.yaml index eade5af..51813d7 100644 --- a/generators/playbook-build/templates/vars/all.yaml +++ b/generators/pd-ansible-playbook/templates/vars/standard/all.yaml @@ -1,3 +1,4 @@ +# The following properties are required by all services # Ansible connection properties ssh_user: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_USER') }}" ssh_pass: "{{ lookup('ansible.builtin.env', 'PODMAN_CD_PASS') }}" @@ -14,15 +15,15 @@ pd_prop_artifact_sha256: "{{ lookup('ansible.builtin.env', 'PODMAN_ARTIFACT_SHA2 pd_prop_build_number: "{{ lookup('ansible.builtin.env', 'PODMAN_BUILD_NUMBER') }}" pd_prop_project_version_run: "{{ pd_prop_project_version }}-{{ pd_prop_build_number }}" -# Properties for creating directories -pd_prop_project_home: "/apps_ux/<%= projectNameUpperCase %>" -pd_prop_service_home: "/apps_ux/<%= projectNameUpperCase %>/<%= serviceName %>" -pd_prop_service_install_directory: "/apps_ux/<%= projectNameUpperCase %>/<%= serviceName %>/{{ pd_prop_project_version_run }}" -pd_prop_service_current_version: "/apps_ux/<%= projectNameUpperCase %>/<%= serviceName %>/current" -pd_prop_service_data: "/apps_data/<%= projectNameUpperCase %>/<%= serviceName %>" -pd_prop_service_logs: "/apps_ux/logs/<%= projectNameUpperCase %>/<%= serviceName %>" -pd_prop_service_s6_path: "/apps_ux/s6_services/<%= serviceName %>" +# The following properties are custom to each particular service +context: <%= tomcatContext %> +<% if (altAppDirName) { -%> +alt_app_dir_name: <%= altAppDirName %> +<% } -%> -# Tomcat properties +# By default, the Tomcat port is set dynamically by using the port_manager role +# If you need to set a static port, replace the dynamic port assignment value with your static value +tomcat_https_port: "{{ portmanager_assignments[ansible_host] }}" -# Webapp properties +# If you need to use a particular version of Tomcat, set the version here +tomcat_version_number: "8.5.51" diff --git a/generators/pd-ansible-playbook/templates/vars/standard/dev.yaml b/generators/pd-ansible-playbook/templates/vars/standard/dev.yaml new file mode 100644 index 0000000..7c8dbb5 --- /dev/null +++ b/generators/pd-ansible-playbook/templates/vars/standard/dev.yaml @@ -0,0 +1,7 @@ +# Use this file for properties specific to the development (integration, delivery) environment +<% if (addWebadeConfig === 'true') { -%> +webade_jdbc_url: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_jdbc_url') }}" +webade_db_user: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_username') }}" +webade_db_pass: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_password') }}" +webade_env: DEV +<% } -%> diff --git a/generators/pd-ansible-playbook/templates/vars/standard/prod.yaml b/generators/pd-ansible-playbook/templates/vars/standard/prod.yaml new file mode 100644 index 0000000..3a4805e --- /dev/null +++ b/generators/pd-ansible-playbook/templates/vars/standard/prod.yaml @@ -0,0 +1,7 @@ +# Use this file for properties specific to the production environment +<% if (addWebadeConfig === 'true') { -%> +webade_jdbc_url: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_jdbc_url') }}" +webade_db_user: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_username') }}" +webade_db_pass: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_password') }}" +webade_env: PROD +<% } -%> diff --git a/generators/pd-ansible-playbook/templates/vars/standard/test.yaml b/generators/pd-ansible-playbook/templates/vars/standard/test.yaml new file mode 100644 index 0000000..96bee18 --- /dev/null +++ b/generators/pd-ansible-playbook/templates/vars/standard/test.yaml @@ -0,0 +1,7 @@ +# Use this file for properties specific to the test environment +<% if (addWebadeConfig === 'true') { -%> +webade_jdbc_url: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_jdbc_url') }}" +webade_db_user: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_username') }}" +webade_db_pass: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_password') }}" +webade_env: TEST +<% } -%> diff --git a/generators/playbook-build/templates/vars/dev.yaml b/generators/playbook-build/templates/vars/dev.yaml deleted file mode 100644 index 3bdddf2..0000000 --- a/generators/playbook-build/templates/vars/dev.yaml +++ /dev/null @@ -1,8 +0,0 @@ -# Webade connection properties -# webade_jdbc_url: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_jdbc_url') }}" -# webade_datastore: "ca.bc.gov.webade.mof.MOFOrganizationDatastore" -# webade_min_connections: 0 -# webade_max_connections: 10 -# webade_db_user: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_username') }}" -# webade_db_pass: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_password') }}" -# webade_env: DEV diff --git a/generators/playbook-build/templates/vars/prod.yaml b/generators/playbook-build/templates/vars/prod.yaml deleted file mode 100644 index c6b2861..0000000 --- a/generators/playbook-build/templates/vars/prod.yaml +++ /dev/null @@ -1,8 +0,0 @@ -# Webade connection properties -# webade_jdbc_url: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_jdbc_url') }}" -# webade_datastore: "ca.bc.gov.webade.mof.MOFOrganizationDatastore" -# webade_min_connections: 0 -# webade_max_connections: 10 -# webade_db_user: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_username') }}" -# webade_db_pass: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_password') }}" -# webade_env: PROD diff --git a/generators/playbook-build/templates/vars/test.yaml b/generators/playbook-build/templates/vars/test.yaml deleted file mode 100644 index c6e109f..0000000 --- a/generators/playbook-build/templates/vars/test.yaml +++ /dev/null @@ -1,8 +0,0 @@ -# Webade connection properties -# webade_jdbc_url: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_jdbc_url') }}" -# webade_datastore: "ca.bc.gov.webade.mof.MOFOrganizationDatastore" -# webade_min_connections: 0 -# webade_max_connections: 10 -# webade_db_user: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_username') }}" -# webade_db_pass: "{{ lookup('ansible.builtin.env', 'PODMAN_webade_password') }}" -# webade_env: TEST