@docupace/pipeline 1.0.2 → 1.0.3-1.demo1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,43 +2,46 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
 
4
4
  export async function validateChangesets(directoryPath) {
5
- try {
6
- // Step 1: Read the directory for md files excluding README.md
7
- const allFiles = fs.readdirSync(directoryPath);
8
- const mdFiles = allFiles.filter(file => file.endsWith('.md') && file !== 'README.md');
9
-
10
- // Step 2: Check for pre.json and parse it
11
- const preJsonPath = path.join(directoryPath, 'pre.json');
12
- let preJson;
13
-
14
- if (!fs.existsSync(preJsonPath) && mdFiles.length === 0) {
15
- throw new Error("Error: No pre.json and no md files found.")
16
- }
5
+ try {
6
+ // Step 1: Read the directory for md files excluding README.md
7
+ const allFiles = fs.readdirSync(directoryPath);
8
+ const mdFiles = allFiles.filter(
9
+ (file) => file.endsWith('.md') && file !== 'README.md',
10
+ );
11
+
12
+ // Step 2: Check for pre.json and parse it
13
+ const preJsonPath = path.join(directoryPath, 'pre.json');
14
+ let preJson;
15
+
16
+ if (!fs.existsSync(preJsonPath) && mdFiles.length === 0) {
17
+ throw new Error('Error: No pre.json and no md files found.');
18
+ }
17
19
 
18
- if (fs.existsSync(preJsonPath)) {
19
- preJson = JSON.parse(fs.readFileSync(preJsonPath, 'utf-8'));
20
+ if (fs.existsSync(preJsonPath)) {
21
+ preJson = JSON.parse(fs.readFileSync(preJsonPath, 'utf-8'));
20
22
 
21
- if(preJson.mode == 'pre') {
22
- // Step 4a: Get list of changesets from pre.json
23
- const changesets = preJson.changesets || [];
24
- const changesetNames = changesets.map(change => change);
23
+ if (preJson.mode == 'pre') {
24
+ // Step 4a: Get list of changesets from pre.json
25
+ const changesets = preJson.changesets || [];
26
+ const changesetNames = changesets.map((change) => change);
25
27
 
26
- // Step 4b: Match files with the list of changesets
27
- const mdFileNamesWithoutExt = mdFiles.map(file => path.basename(file, '.md'));
28
- const unmatchedFiles = mdFileNamesWithoutExt.filter(fileName => !changesetNames.includes(fileName));
28
+ // Step 4b: Match files with the list of changesets
29
+ const mdFileNamesWithoutExt = mdFiles.map((file) =>
30
+ path.basename(file, '.md'),
31
+ );
32
+ const unmatchedFiles = mdFileNamesWithoutExt.filter(
33
+ (fileName) => !changesetNames.includes(fileName),
34
+ );
29
35
 
30
- if (unmatchedFiles.length == 0) {
31
- throw new Error("Error: No new MD files found:");
32
- }
33
- }
36
+ if (unmatchedFiles.length == 0) {
37
+ throw new Error('Error: No new MD files found:');
34
38
  }
35
-
36
- console.log("Validation successful.");
37
- } catch (error) {
38
- console.log(error.message);
39
- throw(error);
39
+ }
40
40
  }
41
- }
42
-
43
-
44
41
 
42
+ console.log('Validation successful.');
43
+ } catch (error) {
44
+ console.log(error.message);
45
+ throw error;
46
+ }
47
+ }
@@ -0,0 +1,59 @@
1
+ import groovy.json.JsonSlurper
2
+
3
+ import hudson.model.*;
4
+
5
+ def build = Thread.currentThread().executable
6
+ def params = build.getEnvironment(listener)
7
+
8
+ def site = params.get('site')
9
+ def server = "jboss7"
10
+ def environment = params.get('environment')
11
+
12
+ def buildFile=new File("D:\\Docupace\\CustomFolders\\" + environment + "\\" + site + "\\" + server + "\\buildApp.properties")
13
+
14
+ List<String> jboss7controllerResult = []
15
+
16
+ def controllersReport = new File("D:\\Docupace\\controllers_report.json")
17
+ def inputJSON = new JsonSlurper().parseText(controllersReport.text)
18
+ def props = new Properties()
19
+ buildFile.withInputStream { stream -> props.load(stream) }
20
+ def webRootContext = props["web.root.context"]
21
+ if (webRootContext == null || webRootContext =="core") webRootContext = props["docupace.config.client.id"].toLowerCase()
22
+
23
+ webRootContext = webRootContext.replaceFirst('_sso','')
24
+ def map = inputJSON.'content'
25
+
26
+ def Boolean enabled
27
+
28
+ map.each {k,v ->
29
+ v.each{vk, vv -> if (vk == webRootContext ) {
30
+ enabled = false
31
+ if(vv.deploymentsProperty.size()>0) enabled = vv.deploymentsProperty[0].isEnabled
32
+ if (enabled) jboss7controllerResult.push(k)
33
+ else jboss7controllerResult << k
34
+ }
35
+ }
36
+ }
37
+
38
+ if (jboss7controllerResult.size()>0) {
39
+ if (environment == 'preprod') {
40
+ jboss7controllerResult.remove("dev-corjbdc10.corp.docupace.com")
41
+ jboss7controllerResult.remove("usdoc-s-jbdc1.corp.docupace.com")
42
+ }
43
+ if (environment == 'dev') {
44
+ jboss7controllerResult.remove("qa-corjbdc10.corp.docupace.com")
45
+ jboss7controllerResult.remove("qa-corjbdc20.corp.docupace.com")
46
+ jboss7controllerResult.remove("usdoc-s-jbdc2.corp.docupace.com")
47
+ }
48
+ }
49
+
50
+ println jboss7controllerResult[0]
51
+
52
+ env.jboss7controller = jboss7controllerResult[0]
53
+
54
+ def serverGroup = inputJSON.'content'."${jboss7controller}"."${webRootContext}".'serverGroup'
55
+
56
+ println serverGroup
57
+
58
+ params.put("serverGroup", serverGroup)
59
+
@@ -0,0 +1,53 @@
1
+ import { BasicAuth, DomainApi } from '@docupace/core-client';
2
+
3
+ const userFilter = (userId) => {
4
+ return {
5
+ orSections: [
6
+ {
7
+ andSections: [
8
+ {
9
+ attrId: 9501,
10
+ '@type': 'string',
11
+ not: false,
12
+ orSections: [
13
+ { searchType: 'EXACT_MATCH', matchToValues: [userId] },
14
+ ],
15
+ },
16
+ ],
17
+ },
18
+ ],
19
+ };
20
+ };
21
+
22
+ /*
23
+ Example:
24
+ await createAlias(
25
+ 'https://www.dev.docupaceinc.com/financialdev',
26
+ 'docupace',
27
+ 'pw',
28
+ 'Connect',
29
+ 'qhnospjRjwUAeKFDhucHEabPsfihrGQQ@clients',
30
+ );
31
+ */
32
+ export async function createAlias(coreUrl, username, password, realm, alias) {
33
+ const coreInfo = {
34
+ url: coreUrl,
35
+ };
36
+
37
+ let auth = new BasicAuth(username, password);
38
+
39
+ const domainApi = new DomainApi(coreInfo, auth);
40
+
41
+ const userResults = await domainApi.listRecords(50, {
42
+ filter: JSON.stringify(userFilter(username)),
43
+ });
44
+
45
+ const record = {
46
+ domainId: 302,
47
+ '5001': userResults.records[0].id,
48
+ '9102': realm,
49
+ '9504': alias,
50
+ };
51
+
52
+ await domainApi.create(record);
53
+ }
@@ -0,0 +1,64 @@
1
+ import { $ } from 'zx';
2
+ import fs from 'fs/promises';
3
+
4
+ export async function addApacheSite() {
5
+ if (
6
+ !process.env.ENVIRONMENT ||
7
+ (process.env.ENVIRONMENT !== 'dev' && process.env.ENVIRONMENT !== 'qa')
8
+ ) {
9
+ console.log("Error: ENVIRONMENT must be either 'dev' or 'qa'.");
10
+ process.exit(1);
11
+ }
12
+ if (!process.env.SITE) {
13
+ console.log('Error: SITE cannot be empty.');
14
+ process.exit(1);
15
+ }
16
+
17
+ // Save private key from base64
18
+ const haproxyPrivateKey = process.env.HAPROXY_PRIVATE_KEY;
19
+ if (!haproxyPrivateKey) {
20
+ console.log('Error: HAPROXY_PRIVATE_KEY not set.');
21
+ process.exit(1);
22
+ }
23
+
24
+ await fs.writeFile('private.key', Buffer.from(haproxyPrivateKey, 'base64'));
25
+ await fs.chmod('private.key', 0o600);
26
+
27
+ console.log('Running command on apalb01a');
28
+ const sshCmd = async (server, script) => {
29
+ $.nothrow = true; // Don't throw on non-zero exit code
30
+ const result =
31
+ await $`ssh -i private.key -o StrictHostKeyChecking=no root@${server} ${script}`.stdio(
32
+ 'inherit',
33
+ );
34
+ $.nothrow = false; // Reset the flag
35
+ return result;
36
+ };
37
+
38
+ let server = `${process.env.ENVIRONMENT}-apalb01a.corp.docupace.com`;
39
+ const resultA = await sshCmd(
40
+ server,
41
+ `/root/repo/iis-preprod/scripts/addsite/add_core_site.sh ${process.env.ENVIRONMENT} ${process.env.SITE}`,
42
+ );
43
+
44
+ if (resultA.exitCode !== 0) {
45
+ console.error(`Error on ${server}:`);
46
+ console.error(resultA.stderr);
47
+ } else {
48
+ console.log(`Finished command on ${server} successfully.`);
49
+ }
50
+
51
+ console.log('Running command on apalb01b');
52
+ server = `${process.env.ENVIRONMENT}-apalb01b.corp.docupace.com`;
53
+ const resultB = await sshCmd(
54
+ server,
55
+ `/root/repo/iis-preprod/scripts/addsite/add_core_site.sh ${process.env.ENVIRONMENT} ${process.env.SITE}`,
56
+ );
57
+
58
+ if (resultB.exitCode !== 0) {
59
+ console.error(`Error on ${server}:`);
60
+ console.error(resultB.stderr);
61
+ } else {
62
+ console.log(`Finished command on ${server} successfully.`);
63
+ }
64
+ }
package/src/next/cli.js CHANGED
@@ -4,56 +4,182 @@ import { Command } from 'commander';
4
4
  import { pull } from './pull.js';
5
5
  import { sonar } from './sonar.js';
6
6
  import { publish } from './publish.js';
7
- import { deploy } from './deploy.js';
7
+ import { deployFromSite } from './deploy.js';
8
8
  import { deployTemplate } from './deploy.js';
9
9
  import { copy } from './copy.js';
10
+ import { vaultAddSiteData } from './vault.js';
11
+ import { addApacheSite } from './apache.js';
12
+ import { haproxySync } from './haproxy.js';
13
+ import { connectClone } from './connect.js';
14
+ import dotenv from 'dotenv';
15
+
16
+ dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
10
17
 
11
18
  const program = new Command();
12
19
 
13
- // GIT SHA computation
14
20
  import { $ } from 'zx';
21
+ import { deployConnect, deployCore } from './jenkins.js';
22
+ import { runPipeline } from './pipline.js';
23
+
15
24
  const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
16
25
 
17
26
  program
18
- .command('pull <imageName>')
19
- .description('Pull a Docker image from the registry')
20
- .action(async (imageName) => {
21
- await pull(imageName);
22
- });
27
+ .command('pull <imageName>')
28
+ .description('Pull a Docker image from the registry')
29
+ .action(async (imageName) => {
30
+ await pull(imageName);
31
+ });
23
32
 
24
33
  program
25
- .command('sonar')
26
- .description('Run Sonar analysis')
27
- .action(async () => {
28
- await sonar(GIT_SHA);
29
- });
34
+ .command('sonar')
35
+ .description('Run Sonar analysis')
36
+ .action(async () => {
37
+ await sonar(GIT_SHA);
38
+ });
30
39
 
31
40
  program
32
- .command('publish')
33
- .description('Publish a Docker image')
34
- .action(async () => {
35
- await publish(GIT_SHA);
36
- });
41
+ .command('addApacheSite')
42
+ .description('Add site to apache')
43
+ .action(async () => {
44
+ await addApacheSite();
45
+ });
37
46
 
38
47
  program
39
- .command('deploy <application> <site>')
40
- .description('Deploy an application for a specific site')
41
- .action(async (application, site) => {
42
- await deploy(application, site);
43
- });
48
+ .command('connectClone')
49
+ .description('Clone connect site')
50
+ .action(async () => {
51
+ await connectClone();
52
+ });
44
53
 
45
54
  program
46
- .command('deployTemplate <site>')
47
- .description('Deploy an application for a specific site')
48
- .action(async (site) => {
49
- await deployTemplate(site);
50
- });
55
+ .command('haproxySync')
56
+ .description('Sync haproxy config')
57
+ .action(async () => {
58
+ await haproxySync();
59
+ });
60
+
61
+ program
62
+ .command('vaultAddSiteData')
63
+ .description('Add m2m auth0 data to vault')
64
+ .requiredOption('-s, --site-name <siteName>', 'Site name')
65
+ .requiredOption(
66
+ '-p, --site-config-remote-path <siteConfigRemotePath>',
67
+ 'Site Config Remote Path',
68
+ )
69
+ .action(async (options) => {
70
+ const { siteName, siteConfigRemotePath } = options;
71
+ await vaultAddSiteData(siteName, siteConfigRemotePath);
72
+ });
73
+
74
+ program
75
+ .command('publish')
76
+ .description('Publish a Docker image')
77
+ .action(async () => {
78
+ await publish(GIT_SHA);
79
+ });
80
+
81
+ program
82
+ .command('deploy-from-site')
83
+ .description('Deploy an application for a specific site')
84
+ .requiredOption('-f, --from-env <fromEnv>', 'Source environment')
85
+ .requiredOption('-t, --to-env <toEnv>', 'Target environment')
86
+ .requiredOption('-F, --from-site <fromSite>', 'Source site')
87
+ .requiredOption('-T, --to-site <toSite>', 'Target site')
88
+ .option('-c, --deploy-core <deployCore>', 'Deploy Core', 'false')
89
+ .option('-C, --deploy-connect <deployConnect>', 'Deploy Connect', 'false')
90
+ .action(async (options) => {
91
+ const { fromEnv, fromSite, toEnv, toSite, deployCore, deployConnect } =
92
+ options;
93
+ await deployFromSite(
94
+ fromEnv,
95
+ fromSite,
96
+ toEnv,
97
+ toSite,
98
+ deployCore,
99
+ deployConnect,
100
+ );
101
+ });
102
+
103
+ program
104
+ .command('deployTemplate <site>')
105
+ .description('Deploy an application for a specific site')
106
+ .action(async (site) => {
107
+ await deployTemplate(site);
108
+ });
109
+
110
+ program
111
+ .command('deploy-core <env> <site>')
112
+ .description('Deploy Core')
113
+ .option('-l, --liquibase <liquibase>', 'Application name', 'true')
114
+ .option('-b, --branch <branch>', 'Branch', 'master')
115
+ .action(async (env, site, options) => {
116
+ await deployCore(env, site, options.liquibase, options.branch);
117
+ });
118
+
119
+ program
120
+ .command('deploy-connect <env> <site>')
121
+ .description('Deploy Core')
122
+ .option('-l, --liquibase <liquibase>', 'Application name', 'true')
123
+ .option('-b, --branch <branch>', 'Branch', 'master')
124
+ .action(async (env, site, options) => {
125
+ await deployConnect(env, site, options.liquibase, options.branch);
126
+ });
51
127
 
52
128
  program
53
- .command('copy')
54
- .description('Copy a Docker image between registries')
55
- .action(async () => {
56
- await copy();
129
+ .command('deploy-core-pipeline <env> <site>')
130
+ .description('Deploy Core')
131
+ .option('-l, --liquibase <liquibase>', 'Application name', 'true')
132
+ .option('-b, --branch <branch>', 'Branch', 'master')
133
+ .action(async (env, site, options) => {
134
+ await runPipeline('site-deploy', 'deploy-core', 'main', {
135
+ ENV: env,
136
+ SITE: site,
137
+ LIQUIBASE: options.liquibase,
138
+ BRANCH: options.branch,
57
139
  });
140
+ });
141
+
142
+ program
143
+ .command('copy')
144
+ .description('Copy a Docker image between registries')
145
+ .requiredOption('-a, --application <application>', 'Application name')
146
+ .requiredOption('-f, --from-env <fromEnv>', 'Source environment')
147
+ .requiredOption('-t, --to-env <toEnv>', 'Target environment')
148
+ .requiredOption('-g, --tag <tag>', 'Image tag')
149
+ .action(async (options) => {
150
+ const { application, fromEnv, toEnv, tag } = options;
151
+ await copy(application, fromEnv, toEnv, tag);
152
+ });
153
+
154
+ program
155
+ .command('run-pipeline')
156
+ .description('Trigger a pipeline by name')
157
+ .requiredOption('-r, --repository <repository>', 'Repository name')
158
+ .requiredOption('-p, --pipeline-name <pipelineName>', 'Pipeline name')
159
+ .requiredOption('-b, --branch <branch>', 'Branch name')
160
+ .option(
161
+ '-v, --variables <key=value>',
162
+ 'Pipeline variable as key=value pair',
163
+ (value, previous) => {
164
+ const [key, val] = value.split('=');
165
+ if (!key || val === undefined) {
166
+ throw new Error(`Invalid variable format: ${value}. Use key=value.`);
167
+ }
168
+ return { ...previous, [key]: val };
169
+ },
170
+ {},
171
+ )
172
+ .option('-w, --wait', 'Wait for the pipeline to complete', false) // Defaults to false
173
+ .action(async (cmdObj) => {
174
+ try {
175
+ const { repository, pipelineName, branch, variables, wait } = cmdObj;
176
+
177
+ // Call the triggerPipelineByName function
178
+ await runPipeline(repository, pipelineName, branch, variables, wait);
179
+ } catch (error) {
180
+ console.error('Error triggering pipeline:', error.message);
181
+ process.exit(1);
182
+ }
183
+ });
58
184
 
59
185
  program.parse(process.argv);
@@ -0,0 +1,84 @@
1
+ export const environments = ['dev', 'qa', 'uat', 'stage', 'prod'];
2
+
3
+ export const environmentConfig = {
4
+ dev: {
5
+ newUrl: (site) => `https://${site}.dev.dpai.tech`,
6
+ oldUrl: (site) => `https://www.dev.docupaceinc.com/${site}`,
7
+ docupaceHost: () => 'www.dev.docupaceinc.com',
8
+ },
9
+ qa: {
10
+ newUrl: (site) => `https://${site}.qa.dpai.tech`,
11
+ oldUrl: (site) => `https://www.preprod.docupaceinc.com/${site}`,
12
+ docupaceHost: () => 'www.preprod.docupaceinc.com',
13
+ },
14
+ uat: {
15
+ newUrl: (site) => `https://${site}.qa.dpai.tech`,
16
+ oldUrl: (site) => `https://www2.paperout.com/${site}_uat`,
17
+ docupaceHost: () => 'www2.paperout.com',
18
+ },
19
+ stage: {
20
+ newUrl: (site) => `https://${site}.stage.dpai.tech`,
21
+ oldUrl: (site) => `https://www2.paperout.com/${site}_staging`,
22
+ docupaceHost: () => 'www2.paperout.com',
23
+ },
24
+ prod: {
25
+ newUrl: (site) => `https://${site}.dpai.tech`,
26
+ oldUrl: (site) => `https://www2.paperout.com/${site}`,
27
+ docupaceHost: () => 'www2.paperout.com',
28
+ },
29
+ };
30
+
31
+ export const appInfo = {
32
+ 'graphql-server': {
33
+ repositoryName: 'docupace-graphql-server',
34
+ deployAttributes: [
35
+ 'image.tag',
36
+ 'graphqlServer.siteConfigRemoteBranch',
37
+ 'graphqlServer.standardConfigRemoteBranch',
38
+ ],
39
+ },
40
+ ui: {
41
+ repositoryName: 'docupace-ui-main',
42
+ deployAttributes: ['image.tag'],
43
+ },
44
+ };
45
+
46
+ export const getEnvInfo = () => {
47
+ const envInfo = Object.fromEntries(
48
+ environments.map((env) => [
49
+ env,
50
+ {
51
+ jfrog: {
52
+ username: process.env[`JF_REGISTRY_${env.toUpperCase()}_USERNAME`],
53
+ password: process.env[`JF_REGISTRY_${env.toUpperCase()}_PASSWORD`],
54
+ },
55
+ },
56
+ ]),
57
+ );
58
+
59
+ return envInfo;
60
+ };
61
+
62
+ export const getBitbucketInfo = () => {
63
+ return {
64
+ username: process.env.BITBUCKET_USERNAME,
65
+ password: process.env.BITBUCKET_APP_PASSWORD,
66
+ workspace: 'dp-cloud',
67
+ };
68
+ };
69
+
70
+ export const getRepUrl = (repoName) => {
71
+ const { username, password, workspace } = getBitbucketInfo();
72
+ return `https://${username}:${password}@bitbucket.org/${workspace}/${repoName}.git`;
73
+ };
74
+
75
+ export const jfRegistryUrl = 'registry.paperout.com';
76
+
77
+ export const getVaultSecretsConfigs = (site) => {
78
+ return {
79
+ commonSecretsPath: 'secret/data/common/config',
80
+ siteCommonSecretsPath: `secret/data/${site}/common/config`,
81
+ graphqlServerSecretsPath: `secret/data/${site}/graphql-server/config`,
82
+ uiSecretsPath: `secret/data/${site}/ui/config`,
83
+ };
84
+ };