@docupace/pipeline 1.0.5-alpha.0 โ 1.0.5-alpha.10
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.
- package/package.json +5 -1
- package/src/jenkins/setParams.groovy +59 -0
- package/src/next/cli.js +9 -1
- package/src/next/deploy.js +2 -6
- package/src/next/jenkins.js +87 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docupace/pipeline",
|
|
3
|
-
"version": "1.0.5-alpha.
|
|
3
|
+
"version": "1.0.5-alpha.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@changesets/cli": "^2.27.10",
|
|
18
|
+
"axios": "^1.7.9",
|
|
18
19
|
"commander": "^12.1.0",
|
|
19
20
|
"dotenv": "^16.4.7",
|
|
20
21
|
"js-yaml": "^4.1.0",
|
|
@@ -31,5 +32,8 @@
|
|
|
31
32
|
"eslint-plugin-prettier": "^5.2.1",
|
|
32
33
|
"globals": "^15.14.0",
|
|
33
34
|
"prettier": "^3.4.2"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"test-deploy-from-site": "dp-next-cli deploy-from-site --from-env dev --to-env dev --from-site financialdev --to-site template"
|
|
34
38
|
}
|
|
35
39
|
}
|
|
@@ -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
|
+
|
package/src/next/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ 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 {
|
|
7
|
+
import { deployFromSite } from './deploy.js';
|
|
8
8
|
import { deployTemplate } from './deploy.js';
|
|
9
9
|
import { copy } from './copy.js';
|
|
10
10
|
import dotenv from 'dotenv';
|
|
@@ -15,6 +15,7 @@ const program = new Command();
|
|
|
15
15
|
|
|
16
16
|
// GIT SHA computation
|
|
17
17
|
import { $ } from 'zx';
|
|
18
|
+
import { deployCore } from './jenkins.js';
|
|
18
19
|
const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
|
|
19
20
|
|
|
20
21
|
program
|
|
@@ -57,6 +58,13 @@ program
|
|
|
57
58
|
await deployTemplate(site);
|
|
58
59
|
});
|
|
59
60
|
|
|
61
|
+
program
|
|
62
|
+
.command('deploy-core <env> <site>')
|
|
63
|
+
.description('Deploy Core')
|
|
64
|
+
.action(async (env, site) => {
|
|
65
|
+
await deployCore(env, site);
|
|
66
|
+
});
|
|
67
|
+
|
|
60
68
|
program
|
|
61
69
|
.command('copy')
|
|
62
70
|
.description('Copy a Docker image between registries')
|
package/src/next/deploy.js
CHANGED
|
@@ -6,8 +6,6 @@ import lodash from 'lodash';
|
|
|
6
6
|
import { appInfo, getBitbucketInfo } from './config.js';
|
|
7
7
|
import { copy } from './copy.js';
|
|
8
8
|
|
|
9
|
-
const GITOPS_BRANCH = 'master';
|
|
10
|
-
|
|
11
9
|
/**
|
|
12
10
|
* Clone the repository, read the YAML file, and return the parsed data and file paths.
|
|
13
11
|
* @param {string} application - The application name.
|
|
@@ -94,8 +92,6 @@ export function setTag(deployConfig, tag) {
|
|
|
94
92
|
*/
|
|
95
93
|
|
|
96
94
|
export async function pushDeployConfig(repoPath, commitMessage) {
|
|
97
|
-
return;
|
|
98
|
-
|
|
99
95
|
console.log('๐ Checking for updates to commit...');
|
|
100
96
|
// Check if there are any changes to commit
|
|
101
97
|
const status = (
|
|
@@ -111,8 +107,8 @@ export async function pushDeployConfig(repoPath, commitMessage) {
|
|
|
111
107
|
console.log('๐ Committing changes to the repository...');
|
|
112
108
|
await $`cd ${repoPath} && git config user.email "gitops@docupace.com"`;
|
|
113
109
|
await $`cd ${repoPath} && git add .`;
|
|
114
|
-
await $`cd ${repoPath} && git commit -m
|
|
115
|
-
await $`cd ${repoPath} && git push
|
|
110
|
+
await $`cd ${repoPath} && git commit -m ${commitMessage}`;
|
|
111
|
+
await $`cd ${repoPath} && git push`;
|
|
116
112
|
console.log('โ
Changes pushed to the remote repository.');
|
|
117
113
|
|
|
118
114
|
console.log('๐งน Cleaning up...');
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
const JENKINS_URL = 'http://devops.corp.docupace.com';
|
|
4
|
+
const JOB_NAME = 'auto-deploy-site';
|
|
5
|
+
const USERNAME = process.env.CORE_JENKINS_USERNAME;
|
|
6
|
+
const API_TOKEN = process.env.CORE_JENKINS_API_TOKEN;
|
|
7
|
+
|
|
8
|
+
export async function deployCore(env, site) {
|
|
9
|
+
const parameters = {
|
|
10
|
+
environment: env,
|
|
11
|
+
site: site,
|
|
12
|
+
runLiquibase: 'true',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
// Trigger the job
|
|
17
|
+
console.log('Triggering Jenkins job...');
|
|
18
|
+
const buildResponse = await axios.post(
|
|
19
|
+
`${JENKINS_URL}/job/${JOB_NAME}/buildWithParameters`,
|
|
20
|
+
new URLSearchParams(parameters),
|
|
21
|
+
{
|
|
22
|
+
auth: { username: USERNAME, password: API_TOKEN },
|
|
23
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
24
|
+
validateStatus: (status) => status === 201 || status === 302, // Accept 201 and 302 as valid statuses
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const queueUrl = buildResponse.headers.location;
|
|
29
|
+
console.log(`Job queued at: ${queueUrl}`);
|
|
30
|
+
|
|
31
|
+
// Poll queue for executable URL
|
|
32
|
+
let jobUrl = null;
|
|
33
|
+
while (!jobUrl) {
|
|
34
|
+
const queueResponse = await axios.get(`${queueUrl}api/json`, {
|
|
35
|
+
auth: { username: USERNAME, password: API_TOKEN },
|
|
36
|
+
});
|
|
37
|
+
jobUrl = queueResponse.data.executable?.url || null;
|
|
38
|
+
|
|
39
|
+
if (!jobUrl) {
|
|
40
|
+
console.log('Waiting for job to start...');
|
|
41
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
jobUrl = jobUrl.replaceAll('https', 'http');
|
|
46
|
+
|
|
47
|
+
console.log(`Job started at: ${jobUrl}`);
|
|
48
|
+
|
|
49
|
+
// Stream console output
|
|
50
|
+
const consoleUrl = `${jobUrl}consoleText`;
|
|
51
|
+
let lastSize = 0;
|
|
52
|
+
|
|
53
|
+
console.log('Streaming job output...');
|
|
54
|
+
while (true) {
|
|
55
|
+
const consoleResponse = await axios.get(consoleUrl, {
|
|
56
|
+
auth: { username: USERNAME, password: API_TOKEN },
|
|
57
|
+
responseType: 'text',
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const consoleText = consoleResponse.data;
|
|
61
|
+
const newOutput = consoleText.slice(lastSize);
|
|
62
|
+
process.stdout.write(newOutput); // Write new output to console
|
|
63
|
+
lastSize = consoleText.length;
|
|
64
|
+
|
|
65
|
+
// Check job status
|
|
66
|
+
const jobResponse = await axios.get(`${jobUrl}api/json`, {
|
|
67
|
+
auth: { username: USERNAME, password: API_TOKEN },
|
|
68
|
+
});
|
|
69
|
+
const result = jobResponse.data.result;
|
|
70
|
+
|
|
71
|
+
if (result) {
|
|
72
|
+
console.log(`\nJob completed with result: ${result}`);
|
|
73
|
+
if (result === 'SUCCESS') {
|
|
74
|
+
process.exit(0);
|
|
75
|
+
} else {
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Wait before polling again
|
|
81
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
82
|
+
}
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error('Error:', error.message);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
}
|