@docupace/pipeline 1.0.5-alpha.3 → 1.0.5-alpha.4
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 +2 -1
- package/src/next/cli.js +9 -1
- package/src/next/jenkins.js +85 -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.4",
|
|
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",
|
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 {deploy, deployFromSite} from './deploy.js';
|
|
7
|
+
import { deploy, 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 {triggerJenkinsJob} 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('deployCore <env> <site>')
|
|
63
|
+
.description('Deploy Core')
|
|
64
|
+
.action(async (env, site) => {
|
|
65
|
+
await triggerJenkinsJob();
|
|
66
|
+
});
|
|
67
|
+
|
|
60
68
|
program
|
|
61
69
|
.command('copy')
|
|
62
70
|
.description('Copy a Docker image between registries')
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const axios = require('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
|
+
const PARAMETERS = {
|
|
8
|
+
environment: 'dev',
|
|
9
|
+
site: 'TEMPLATE',
|
|
10
|
+
runLiquibase: 'true',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export async function triggerJenkinsJob() {
|
|
14
|
+
try {
|
|
15
|
+
// Trigger the job
|
|
16
|
+
console.log('Triggering Jenkins job...');
|
|
17
|
+
const buildResponse = await axios.post(
|
|
18
|
+
`${JENKINS_URL}/job/${JOB_NAME}/buildWithParameters`,
|
|
19
|
+
new URLSearchParams(PARAMETERS),
|
|
20
|
+
{
|
|
21
|
+
auth: { username: USERNAME, password: API_TOKEN },
|
|
22
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
23
|
+
maxRedirects: 0,
|
|
24
|
+
validateStatus: (status) => status === 302, // Jenkins responds with 302 after job is triggered
|
|
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
|
+
console.log(`Job started at: ${jobUrl}`);
|
|
46
|
+
|
|
47
|
+
// Stream console output
|
|
48
|
+
const consoleUrl = `${jobUrl}consoleText`;
|
|
49
|
+
let lastSize = 0;
|
|
50
|
+
|
|
51
|
+
console.log('Streaming job output...');
|
|
52
|
+
while (true) {
|
|
53
|
+
const consoleResponse = await axios.get(consoleUrl, {
|
|
54
|
+
auth: { username: USERNAME, password: API_TOKEN },
|
|
55
|
+
responseType: 'text',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const consoleText = consoleResponse.data;
|
|
59
|
+
const newOutput = consoleText.slice(lastSize);
|
|
60
|
+
process.stdout.write(newOutput); // Write new output to console
|
|
61
|
+
lastSize = consoleText.length;
|
|
62
|
+
|
|
63
|
+
// Check job status
|
|
64
|
+
const jobResponse = await axios.get(`${jobUrl}api/json`, {
|
|
65
|
+
auth: { username: USERNAME, password: API_TOKEN },
|
|
66
|
+
});
|
|
67
|
+
const result = jobResponse.data.result;
|
|
68
|
+
|
|
69
|
+
if (result) {
|
|
70
|
+
console.log(`\nJob completed with result: ${result}`);
|
|
71
|
+
if (result === 'SUCCESS') {
|
|
72
|
+
process.exit(0);
|
|
73
|
+
} else {
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Wait before polling again
|
|
79
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
80
|
+
}
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error('Error:', error.message);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
}
|