-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from bcgov-nr/feat/addPlaybookGen
Feat/add playbook gen
- Loading branch information
Showing
11 changed files
with
260 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use strict'; | ||
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 Ansible playbook and variable files needed for Tomcat webapp deployments | ||
*/ | ||
export default class extends Generator { | ||
constructor(args, opts) { | ||
super(args, opts); | ||
|
||
this.argument('projectName', { | ||
type: String, | ||
required: true, | ||
description: 'Project Name', | ||
}); | ||
this.argument('serviceName', { | ||
type: String, | ||
required: true, | ||
description: 'Service Name', | ||
}); | ||
this.argument('playbookPath', { | ||
type: String, | ||
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 | ||
writing() { | ||
this.log('Generating playbook files'); | ||
this.fs.copyTpl( | ||
this.templatePath('playbook.yaml'), | ||
this.destinationPath(`${this.options.playbookPath}/playbook.yaml`), | ||
{ | ||
projectName: this.options.projectName, | ||
serviceName: this.options.serviceName, | ||
}, | ||
); | ||
this.fs.copyTpl( | ||
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
- name: <%= projectName %>/<%= serviceName %> | ||
hosts: tomcat-servers | ||
collections: | ||
- polaris.deploy | ||
vars_files: | ||
- "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 | ||
|
||
# prepare the installation environment by creating the necessary folders | ||
- name: create_project_directories | ||
|
||
# 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 }}" | ||
proxy_env: "{{ env_vars }}" | ||
|
||
# create a WebADE connection jar for the container | ||
- name: webade_connection_jar | ||
# 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" | ||
become: yes | ||
become_user: "{{ install_user }}" | ||
with_items: | ||
- { | ||
src: "web.xml.j2", | ||
dest: "{{ pd_prop_service_install_directory }}/webapps/{{ alt_app_dir_name or context }}/WEB-INF/web.xml" | ||
} | ||
- { | ||
src: "JMSConfig.xml.j2", | ||
dest: "{{ pd_prop_service_install_directory }}/webapps/{{ alt_app_dir_name or context }}/WEB-INF/classes/JMSConfig.xml" | ||
} | ||
- { | ||
src: "tasks.xml.j2", | ||
dest: "{{ pd_prop_service_install_directory }}/webapps/{{ alt_app_dir_name or context }}/WEB-INF/classes/tasks.xml" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Use this file for custom variables related to your webapp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Use this file for custom variables related to your webapp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Use this file for custom variables related to your webapp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Use this file for custom variables related to your webapp |
29 changes: 29 additions & 0 deletions
29
generators/pd-ansible-playbook/templates/vars/standard/all.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# 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') }}" | ||
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" | ||
|
||
# General properties | ||
pd_prop_project_name: "<%= projectNameUpperCase %>" | ||
pd_prop_service_name: "<%= serviceName %>" | ||
pd_prop_project_version: "{{ lookup('ansible.builtin.env', 'PODMAN_PROJECT_VERSION') }}" | ||
pd_prop_artifact_name: "{{ lookup('ansible.builtin.env', 'PODMAN_ARTIFACT_NAME') }}" | ||
pd_prop_artifact_sha256: "{{ lookup('ansible.builtin.env', 'PODMAN_ARTIFACT_SHA256') }}" | ||
pd_prop_build_number: "{{ lookup('ansible.builtin.env', 'PODMAN_BUILD_NUMBER') }}" | ||
pd_prop_project_version_run: "{{ pd_prop_project_version }}-{{ pd_prop_build_number }}" | ||
|
||
# The following properties are custom to each particular service | ||
context: <%= tomcatContext %> | ||
<% if (altAppDirName) { -%> | ||
alt_app_dir_name: <%= altAppDirName %> | ||
<% } -%> | ||
|
||
# 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] }}" | ||
|
||
# If you need to use a particular version of Tomcat, set the version here | ||
tomcat_version_number: "8.5.51" |
7 changes: 7 additions & 0 deletions
7
generators/pd-ansible-playbook/templates/vars/standard/dev.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
<% } -%> |
7 changes: 7 additions & 0 deletions
7
generators/pd-ansible-playbook/templates/vars/standard/prod.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
<% } -%> |
7 changes: 7 additions & 0 deletions
7
generators/pd-ansible-playbook/templates/vars/standard/test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
<% } -%> |