@docupace/pipeline 1.0.2-3.test9 → 1.0.2-5.1
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 +1 -1
- package/src/auth0/vault.js +10 -10
- package/src/next/cli.js +185 -185
- package/src/next/config.js +2 -2
- package/src/next/connect.js +7 -5
- package/src/next/copy.js +51 -51
- package/src/next/deploy.js +31 -12
- package/src/next/jenkins.js +123 -122
- package/src/next/pipline.js +114 -114
package/package.json
CHANGED
package/src/auth0/vault.js
CHANGED
|
@@ -7,16 +7,16 @@ import axios from 'axios';
|
|
|
7
7
|
*/
|
|
8
8
|
export async function getVaultSecrets(vaultPath) {
|
|
9
9
|
if (!vaultPath) {
|
|
10
|
-
console.error(
|
|
11
|
-
throw new Error(
|
|
10
|
+
console.error('Error: VAULT_PATH is required.');
|
|
11
|
+
throw new Error('VAULT_PATH is required.');
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const vaultToken = process.env.VAULT_TOKEN;
|
|
15
15
|
const vaultAddr = process.env.VAULT_ADDR;
|
|
16
16
|
|
|
17
17
|
if (!vaultToken || !vaultAddr) {
|
|
18
|
-
console.error(
|
|
19
|
-
throw new Error(
|
|
18
|
+
console.error('Error: VAULT_TOKEN and VAULT_ADDR must be set.');
|
|
19
|
+
throw new Error('VAULT_TOKEN and VAULT_ADDR must be set.');
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
try {
|
|
@@ -38,8 +38,8 @@ export async function getVaultSecrets(vaultPath) {
|
|
|
38
38
|
// console.log(`Secrets fetched successfully from Vault at ${JSON.stringify(data.data.data)})`);
|
|
39
39
|
return data.data.data;
|
|
40
40
|
} else {
|
|
41
|
-
console.error(
|
|
42
|
-
throw new Error(
|
|
41
|
+
console.error('Error: Invalid JSON received from Vault.');
|
|
42
|
+
throw new Error('Invalid JSON received from Vault.');
|
|
43
43
|
}
|
|
44
44
|
} catch (error) {
|
|
45
45
|
if (error.response) {
|
|
@@ -61,16 +61,16 @@ export async function getVaultSecrets(vaultPath) {
|
|
|
61
61
|
*/
|
|
62
62
|
export async function updateVaultSecrets(vaultPath, secretData) {
|
|
63
63
|
if (!vaultPath || !secretData) {
|
|
64
|
-
console.error(
|
|
65
|
-
throw new Error(
|
|
64
|
+
console.error('Usage: updateVaultSecret(vaultPath, secretData)');
|
|
65
|
+
throw new Error('Both vaultPath and secretData are required.');
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
const vaultToken = process.env.VAULT_TOKEN;
|
|
69
69
|
const vaultAddr = process.env.VAULT_ADDR;
|
|
70
70
|
|
|
71
71
|
if (!vaultToken || !vaultAddr) {
|
|
72
|
-
console.error(
|
|
73
|
-
throw new Error(
|
|
72
|
+
console.error('Error: VAULT_TOKEN and VAULT_ADDR must be set.');
|
|
73
|
+
throw new Error('VAULT_TOKEN and VAULT_ADDR must be set.');
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
try {
|
package/src/next/cli.js
CHANGED
|
@@ -1,185 +1,185 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { Command } from 'commander';
|
|
4
|
-
import { pull } from './pull.js';
|
|
5
|
-
import { sonar } from './sonar.js';
|
|
6
|
-
import { publish } from './publish.js';
|
|
7
|
-
import { deployFromSite } from './deploy.js';
|
|
8
|
-
import { deployTemplate } from './deploy.js';
|
|
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'] });
|
|
17
|
-
|
|
18
|
-
const program = new Command();
|
|
19
|
-
|
|
20
|
-
import { $ } from 'zx';
|
|
21
|
-
import { deployConnect, deployCore } from './jenkins.js';
|
|
22
|
-
import { runPipeline } from './pipline.js';
|
|
23
|
-
|
|
24
|
-
const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
|
|
25
|
-
|
|
26
|
-
program
|
|
27
|
-
.command('pull <imageName>')
|
|
28
|
-
.description('Pull a Docker image from the registry')
|
|
29
|
-
.action(async (imageName) => {
|
|
30
|
-
await pull(imageName);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
program
|
|
34
|
-
.command('sonar')
|
|
35
|
-
.description('Run Sonar analysis')
|
|
36
|
-
.action(async () => {
|
|
37
|
-
await sonar(GIT_SHA);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
program
|
|
41
|
-
.command('addApacheSite')
|
|
42
|
-
.description('Add site to apache')
|
|
43
|
-
.action(async () => {
|
|
44
|
-
await addApacheSite();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
program
|
|
48
|
-
.command('connectClone')
|
|
49
|
-
.description('Clone connect site')
|
|
50
|
-
.action(async () => {
|
|
51
|
-
await connectClone();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
program
|
|
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('-
|
|
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
|
-
});
|
|
127
|
-
|
|
128
|
-
program
|
|
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,
|
|
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
|
-
});
|
|
184
|
-
|
|
185
|
-
program.parse(process.argv);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import { pull } from './pull.js';
|
|
5
|
+
import { sonar } from './sonar.js';
|
|
6
|
+
import { publish } from './publish.js';
|
|
7
|
+
import { deployFromSite } from './deploy.js';
|
|
8
|
+
import { deployTemplate } from './deploy.js';
|
|
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'] });
|
|
17
|
+
|
|
18
|
+
const program = new Command();
|
|
19
|
+
|
|
20
|
+
import { $ } from 'zx';
|
|
21
|
+
import { deployConnect, deployCore } from './jenkins.js';
|
|
22
|
+
import { runPipeline } from './pipline.js';
|
|
23
|
+
|
|
24
|
+
const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
|
|
25
|
+
|
|
26
|
+
program
|
|
27
|
+
.command('pull <imageName>')
|
|
28
|
+
.description('Pull a Docker image from the registry')
|
|
29
|
+
.action(async (imageName) => {
|
|
30
|
+
await pull(imageName);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
program
|
|
34
|
+
.command('sonar')
|
|
35
|
+
.description('Run Sonar analysis')
|
|
36
|
+
.action(async () => {
|
|
37
|
+
await sonar(GIT_SHA);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
program
|
|
41
|
+
.command('addApacheSite')
|
|
42
|
+
.description('Add site to apache')
|
|
43
|
+
.action(async () => {
|
|
44
|
+
await addApacheSite();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
program
|
|
48
|
+
.command('connectClone')
|
|
49
|
+
.description('Clone connect site')
|
|
50
|
+
.action(async () => {
|
|
51
|
+
await connectClone();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
program
|
|
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
|
+
});
|
|
127
|
+
|
|
128
|
+
program
|
|
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,
|
|
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
|
+
});
|
|
184
|
+
|
|
185
|
+
program.parse(process.argv);
|
package/src/next/config.js
CHANGED
|
@@ -79,6 +79,6 @@ export const getVaultSecretsConfigs = (site) => {
|
|
|
79
79
|
commonSecretsPath: 'secret/data/common/config',
|
|
80
80
|
siteCommonSecretsPath: `secret/data/${site}/common/config`,
|
|
81
81
|
graphqlServerSecretsPath: `secret/data/${site}/graphql-server/config`,
|
|
82
|
-
uiSecretsPath: `secret/data/${site}/ui/config
|
|
83
|
-
}
|
|
82
|
+
uiSecretsPath: `secret/data/${site}/ui/config`,
|
|
83
|
+
};
|
|
84
84
|
};
|
package/src/next/connect.js
CHANGED
|
@@ -124,6 +124,12 @@ export async function connectClone() {
|
|
|
124
124
|
// Execute the shell command
|
|
125
125
|
const result =
|
|
126
126
|
await $`cd ${cloneFrom} && bash dock.sh clone ${connectToEnv} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
|
|
127
|
+
await $`cd ${cloneTo} && git checkout master && git pull --ff-only`;
|
|
128
|
+
await $`cd ${cloneTo} && git remote -v`;
|
|
129
|
+
await $`cd ${cloneTo} && git branch`;
|
|
130
|
+
await $`cd ${cloneTo} && git status`;
|
|
131
|
+
await $`cd ${cloneTo} && git add . ../sites.sh`;
|
|
132
|
+
|
|
127
133
|
console.log('Command succeeded:');
|
|
128
134
|
console.log('stdout:', result.stdout); // Standard output
|
|
129
135
|
console.log('stderr:', result.stderr); // Standard error
|
|
@@ -162,11 +168,7 @@ export async function connectClone() {
|
|
|
162
168
|
await $`cat ${path.join(cloneTo, 'conf/saml/auth0.xml')}`;
|
|
163
169
|
|
|
164
170
|
// 8) Git add, commit, push
|
|
165
|
-
await $`cd ${cloneTo} && git
|
|
166
|
-
await $`cd ${cloneTo} && git remote -v`;
|
|
167
|
-
await $`cd ${cloneTo} && git branch`;
|
|
168
|
-
await $`cd ${cloneTo} && git status`;
|
|
169
|
-
await $`cd ${cloneTo} && git add . ../sites.sh`;
|
|
171
|
+
await $`cd ${cloneTo} && git add ./conf/application.conf ./conf/saml/auth0.xml`;
|
|
170
172
|
await $`cd ${cloneTo} && git status`;
|
|
171
173
|
|
|
172
174
|
const numChanges = (await $`cd ${cloneTo} && git diff-index HEAD`).stdout
|
package/src/next/copy.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { $ } from 'zx';
|
|
2
|
-
import { appInfo, getEnvInfo, jfRegistryUrl } from './config.js';
|
|
3
|
-
|
|
4
|
-
/*
|
|
5
|
-
TARGET_ENV
|
|
6
|
-
PUBLISH_TAG
|
|
7
|
-
REPOSITORY_NAME
|
|
8
|
-
*/
|
|
9
|
-
export async function copy(application, fromEnv, toEnv, tag) {
|
|
10
|
-
const envInfo = getEnvInfo();
|
|
11
|
-
const repositoryName = appInfo[application].repositoryName;
|
|
12
|
-
const fromRegistry = `${jfRegistryUrl}/${repositoryName}-${fromEnv}-docker-local`;
|
|
13
|
-
const toRegistry = `${jfRegistryUrl}/${repositoryName}-${toEnv}-docker-local`;
|
|
14
|
-
const imageName = `${repositoryName}:${tag}`;
|
|
15
|
-
const fromFullImageName = `${fromRegistry}/${imageName}`;
|
|
16
|
-
const toFullImageName = `${toRegistry}/${imageName}`;
|
|
17
|
-
|
|
18
|
-
console.log(
|
|
19
|
-
`Copying Docker image: ${fromFullImageName} -> ${toFullImageName}`,
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
// Login to source registry
|
|
23
|
-
await $`echo ${envInfo[fromEnv].jfrog.password} | docker login --username ${envInfo[fromEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
|
|
24
|
-
await $`docker pull ${fromFullImageName}`;
|
|
25
|
-
await $`docker tag ${fromFullImageName} ${toFullImageName}`;
|
|
26
|
-
|
|
27
|
-
// Login to target registry
|
|
28
|
-
await $`echo ${envInfo[toEnv].jfrog.password} | docker login --username ${envInfo[toEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
|
|
29
|
-
await $`docker push ${toFullImageName}`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function copy2(repositoryName, fromEnv, toEnv, tag) {
|
|
33
|
-
const envInfo = getEnvInfo();
|
|
34
|
-
const fromRegistry = `${jfRegistryUrl}/${repositoryName}-${fromEnv}-docker-local`;
|
|
35
|
-
const toRegistry = `${jfRegistryUrl}/${repositoryName}-${toEnv}-docker-local`;
|
|
36
|
-
const imageName = `${repositoryName}:${tag}`;
|
|
37
|
-
const fromFullImageName = `${fromRegistry}/${imageName}`;
|
|
38
|
-
const toFullImageName = `${toRegistry}/${imageName}`;
|
|
39
|
-
|
|
40
|
-
console.log(
|
|
41
|
-
`Copying Docker image: ${fromFullImageName} -> ${toFullImageName}`,
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
// Login to source registry
|
|
45
|
-
await $`echo ${envInfo[fromEnv].jfrog.password} | docker login --username ${envInfo[fromEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
|
|
46
|
-
await $`docker pull ${fromFullImageName}`;
|
|
47
|
-
await $`docker tag ${fromFullImageName} ${toFullImageName}`;
|
|
48
|
-
|
|
49
|
-
// Login to target registry
|
|
50
|
-
await $`echo ${envInfo[toEnv].jfrog.password} | docker login --username ${envInfo[toEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
|
|
51
|
-
await $`docker push ${toFullImageName}`;
|
|
1
|
+
import { $ } from 'zx';
|
|
2
|
+
import { appInfo, getEnvInfo, jfRegistryUrl } from './config.js';
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
TARGET_ENV
|
|
6
|
+
PUBLISH_TAG
|
|
7
|
+
REPOSITORY_NAME
|
|
8
|
+
*/
|
|
9
|
+
export async function copy(application, fromEnv, toEnv, tag) {
|
|
10
|
+
const envInfo = getEnvInfo();
|
|
11
|
+
const repositoryName = appInfo[application].repositoryName;
|
|
12
|
+
const fromRegistry = `${jfRegistryUrl}/${repositoryName}-${fromEnv}-docker-local`;
|
|
13
|
+
const toRegistry = `${jfRegistryUrl}/${repositoryName}-${toEnv}-docker-local`;
|
|
14
|
+
const imageName = `${repositoryName}:${tag}`;
|
|
15
|
+
const fromFullImageName = `${fromRegistry}/${imageName}`;
|
|
16
|
+
const toFullImageName = `${toRegistry}/${imageName}`;
|
|
17
|
+
|
|
18
|
+
console.log(
|
|
19
|
+
`Copying Docker image: ${fromFullImageName} -> ${toFullImageName}`,
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// Login to source registry
|
|
23
|
+
await $`echo ${envInfo[fromEnv].jfrog.password} | docker login --username ${envInfo[fromEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
|
|
24
|
+
await $`docker pull ${fromFullImageName}`;
|
|
25
|
+
await $`docker tag ${fromFullImageName} ${toFullImageName}`;
|
|
26
|
+
|
|
27
|
+
// Login to target registry
|
|
28
|
+
await $`echo ${envInfo[toEnv].jfrog.password} | docker login --username ${envInfo[toEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
|
|
29
|
+
await $`docker push ${toFullImageName}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function copy2(repositoryName, fromEnv, toEnv, tag) {
|
|
33
|
+
const envInfo = getEnvInfo();
|
|
34
|
+
const fromRegistry = `${jfRegistryUrl}/${repositoryName}-${fromEnv}-docker-local`;
|
|
35
|
+
const toRegistry = `${jfRegistryUrl}/${repositoryName}-${toEnv}-docker-local`;
|
|
36
|
+
const imageName = `${repositoryName}:${tag}`;
|
|
37
|
+
const fromFullImageName = `${fromRegistry}/${imageName}`;
|
|
38
|
+
const toFullImageName = `${toRegistry}/${imageName}`;
|
|
39
|
+
|
|
40
|
+
console.log(
|
|
41
|
+
`Copying Docker image: ${fromFullImageName} -> ${toFullImageName}`,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// Login to source registry
|
|
45
|
+
await $`echo ${envInfo[fromEnv].jfrog.password} | docker login --username ${envInfo[fromEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
|
|
46
|
+
await $`docker pull ${fromFullImageName}`;
|
|
47
|
+
await $`docker tag ${fromFullImageName} ${toFullImageName}`;
|
|
48
|
+
|
|
49
|
+
// Login to target registry
|
|
50
|
+
await $`echo ${envInfo[toEnv].jfrog.password} | docker login --username ${envInfo[toEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
|
|
51
|
+
await $`docker push ${toFullImageName}`;
|
|
52
52
|
}
|
package/src/next/deploy.js
CHANGED
|
@@ -39,29 +39,47 @@ async function updateAndCommitConnectVersion(
|
|
|
39
39
|
let content = fs.readFileSync(filePath, 'utf8');
|
|
40
40
|
content = content.replace(
|
|
41
41
|
/IMAGE_VERSION=.*/,
|
|
42
|
-
`IMAGE_VERSION
|
|
42
|
+
`IMAGE_VERSION=git-commit-${getComparedVersion}`,
|
|
43
43
|
);
|
|
44
44
|
fs.writeFileSync(filePath, content, 'utf8');
|
|
45
45
|
|
|
46
46
|
// Git commands to stage, commit and push changes
|
|
47
|
-
await $`cd ${connectDeployPath}`;
|
|
48
|
-
await $`git add
|
|
49
|
-
await $`git commit -m "Update Connect version for ${toSite} in ${toEnv} to ${getComparedVersion}"`;
|
|
50
|
-
await $`git push`;
|
|
47
|
+
await $`cd ${connectDeployPath} && git config user.email "gitops@docupace.com"`;
|
|
48
|
+
await $`cd ${connectDeployPath} && git add .`;
|
|
49
|
+
await $`cd ${connectDeployPath} && git commit -m "Update Connect version for ${toSite} in ${toEnv} to ${getComparedVersion}"`;
|
|
50
|
+
await $`cd ${connectDeployPath} && git push`;
|
|
51
|
+
|
|
52
|
+
console.log('🧹 Cleaning up...');
|
|
53
|
+
await $`rm -rf ${connectDeployPath}`;
|
|
54
|
+
console.log('✅ Cleanup complete.');
|
|
51
55
|
} catch (error) {
|
|
52
56
|
console.error('Error updating Connect version:', error);
|
|
53
57
|
throw error;
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
|
|
61
|
+
async function fetchLoginFooter(env, site, isNewUrl) {
|
|
62
|
+
const url = isNewUrl
|
|
63
|
+
? environmentConfig[env].newUrl(site)
|
|
64
|
+
: environmentConfig[env].oldUrl(site);
|
|
65
|
+
const endpoint = isNewUrl ? '/connect/loginFooter' : '_ui/loginFooter';
|
|
66
|
+
return await axios.get(`${url}${endpoint}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
57
69
|
async function compareGetConnectSiteVersions(fromEnv, fromSite, toEnv, toSite) {
|
|
58
70
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
let fromResponse, toResponse;
|
|
72
|
+
try {
|
|
73
|
+
fromResponse = await fetchLoginFooter(fromEnv, fromSite, true);
|
|
74
|
+
} catch {
|
|
75
|
+
fromResponse = await fetchLoginFooter(fromEnv, fromSite, false);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
toResponse = await fetchLoginFooter(toEnv, toSite, true);
|
|
80
|
+
} catch {
|
|
81
|
+
toResponse = await fetchLoginFooter(toEnv, toSite, false);
|
|
82
|
+
}
|
|
65
83
|
|
|
66
84
|
const fromMatch = fromResponse.data.match(/UI Build: ([a-f0-9]*)/);
|
|
67
85
|
const toMatch = toResponse.data.match(/UI Build: ([a-f0-9]*)/);
|
|
@@ -429,6 +447,7 @@ export async function deployFromSite(
|
|
|
429
447
|
toSite,
|
|
430
448
|
);
|
|
431
449
|
if (getComparedVersion) {
|
|
450
|
+
console.log('Version to deploy is: ', getComparedVersion);
|
|
432
451
|
const connectDeployPath = await cloneRepository('connect-deploy');
|
|
433
452
|
// update target version set to git-commit-${getCommparedVersion}}
|
|
434
453
|
await updateAndCommitConnectVersion(
|
|
@@ -450,7 +469,7 @@ export async function deployFromSite(
|
|
|
450
469
|
|
|
451
470
|
// Initialize a flag to track changes
|
|
452
471
|
let changesMade = false;
|
|
453
|
-
const applications = await getAppTypesFromRepo(
|
|
472
|
+
const applications = await getAppTypesFromRepo(toEnv, toSite);
|
|
454
473
|
console.log(applications);
|
|
455
474
|
// Iterate over applications in appInfo
|
|
456
475
|
|
package/src/next/jenkins.js
CHANGED
|
@@ -1,122 +1,123 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
const CORE_JENKINS_URL = 'http://devops.corp.docupace.com';
|
|
4
|
-
const CORE_JOB_NAME = 'auto-deploy-site';
|
|
5
|
-
const CORE_USERNAME = process.env.CORE_JENKINS_USERNAME;
|
|
6
|
-
const CORE_API_TOKEN = process.env.CORE_JENKINS_API_TOKEN;
|
|
7
|
-
|
|
8
|
-
const CONNECT_JENKINS_URL = 'http://usdoc-s-buildui.corp.docupace.com/jenkins';
|
|
9
|
-
const CONNECT_JOB_NAME = 'docupace_build_and_run_site_v2';
|
|
10
|
-
const CONNECT_USERNAME = process.env.CONNECT_JENKINS_USERNAME;
|
|
11
|
-
const CONNECT_API_TOKEN = process.env.CONNECT_JENKINS_API_TOKEN;
|
|
12
|
-
|
|
13
|
-
export async function deployCore(env, site, liquibase, gitBranch) {
|
|
14
|
-
const parameters = {
|
|
15
|
-
environment: env,
|
|
16
|
-
site: site.toUpperCase(),
|
|
17
|
-
runLiquibase: liquibase,
|
|
18
|
-
gitBranch,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
return callJenkinsJob({
|
|
22
|
-
jenkinsUrl: CORE_JENKINS_URL,
|
|
23
|
-
jobName: CORE_JOB_NAME,
|
|
24
|
-
auth: { username: CORE_USERNAME, password: CORE_API_TOKEN },
|
|
25
|
-
parameters,
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
const CORE_JENKINS_URL = 'http://devops.corp.docupace.com';
|
|
4
|
+
const CORE_JOB_NAME = 'auto-deploy-site';
|
|
5
|
+
const CORE_USERNAME = process.env.CORE_JENKINS_USERNAME;
|
|
6
|
+
const CORE_API_TOKEN = process.env.CORE_JENKINS_API_TOKEN;
|
|
7
|
+
|
|
8
|
+
const CONNECT_JENKINS_URL = 'http://usdoc-s-buildui.corp.docupace.com/jenkins';
|
|
9
|
+
const CONNECT_JOB_NAME = 'docupace_build_and_run_site_v2';
|
|
10
|
+
const CONNECT_USERNAME = process.env.CONNECT_JENKINS_USERNAME;
|
|
11
|
+
const CONNECT_API_TOKEN = process.env.CONNECT_JENKINS_API_TOKEN;
|
|
12
|
+
|
|
13
|
+
export async function deployCore(env, site, liquibase, gitBranch) {
|
|
14
|
+
const parameters = {
|
|
15
|
+
environment: env,
|
|
16
|
+
site: site.toUpperCase(),
|
|
17
|
+
runLiquibase: liquibase,
|
|
18
|
+
gitBranch,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return callJenkinsJob({
|
|
22
|
+
jenkinsUrl: CORE_JENKINS_URL,
|
|
23
|
+
jobName: CORE_JOB_NAME,
|
|
24
|
+
auth: { username: CORE_USERNAME, password: CORE_API_TOKEN },
|
|
25
|
+
parameters,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line no-unused-vars
|
|
30
|
+
export async function deployConnect(env, site, liquibase, branch) {
|
|
31
|
+
const parameters = {
|
|
32
|
+
BUILD_ENVIRONMENT: env,
|
|
33
|
+
BUILD_SITE: site,
|
|
34
|
+
RUN_LIQUIBASE: liquibase,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return callJenkinsJob({
|
|
38
|
+
jenkinsUrl: CONNECT_JENKINS_URL,
|
|
39
|
+
jobName: CONNECT_JOB_NAME,
|
|
40
|
+
auth: { username: CONNECT_USERNAME, password: CONNECT_API_TOKEN },
|
|
41
|
+
parameters,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function callJenkinsJob({
|
|
46
|
+
jenkinsUrl,
|
|
47
|
+
jobName,
|
|
48
|
+
auth,
|
|
49
|
+
parameters,
|
|
50
|
+
}) {
|
|
51
|
+
try {
|
|
52
|
+
// Trigger the job
|
|
53
|
+
console.log('Triggering Jenkins job...');
|
|
54
|
+
const buildResponse = await axios.post(
|
|
55
|
+
`${jenkinsUrl}/job/${jobName}/buildWithParameters`,
|
|
56
|
+
new URLSearchParams(parameters),
|
|
57
|
+
{
|
|
58
|
+
auth,
|
|
59
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
60
|
+
validateStatus: (status) => status === 201 || status === 302, // Accept 201 and 302 as valid statuses
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const queueUrl = buildResponse.headers.location;
|
|
65
|
+
console.log(`Job queued at: ${queueUrl}`);
|
|
66
|
+
|
|
67
|
+
// Poll queue for executable URL
|
|
68
|
+
let jobUrl = null;
|
|
69
|
+
while (!jobUrl) {
|
|
70
|
+
const queueResponse = await axios.get(`${queueUrl}api/json`, {
|
|
71
|
+
auth,
|
|
72
|
+
});
|
|
73
|
+
jobUrl = queueResponse.data.executable?.url || null;
|
|
74
|
+
|
|
75
|
+
if (!jobUrl) {
|
|
76
|
+
console.log('Waiting for job to start...');
|
|
77
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
jobUrl = jobUrl.replaceAll('https', 'http');
|
|
82
|
+
|
|
83
|
+
console.log(`Job started at: ${jobUrl}`);
|
|
84
|
+
|
|
85
|
+
// Stream console output
|
|
86
|
+
const consoleUrl = `${jobUrl}consoleText`;
|
|
87
|
+
let lastSize = 0;
|
|
88
|
+
|
|
89
|
+
console.log('Streaming job output...');
|
|
90
|
+
while (true) {
|
|
91
|
+
const consoleResponse = await axios.get(consoleUrl, {
|
|
92
|
+
auth,
|
|
93
|
+
responseType: 'text',
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const consoleText = consoleResponse.data;
|
|
97
|
+
const newOutput = consoleText.slice(lastSize);
|
|
98
|
+
process.stdout.write(newOutput); // Write new output to console
|
|
99
|
+
lastSize = consoleText.length;
|
|
100
|
+
|
|
101
|
+
// Check job status
|
|
102
|
+
const jobResponse = await axios.get(`${jobUrl}api/json`, {
|
|
103
|
+
auth,
|
|
104
|
+
});
|
|
105
|
+
const result = jobResponse.data.result;
|
|
106
|
+
|
|
107
|
+
if (result) {
|
|
108
|
+
console.log(`\nJob completed with result: ${result}`);
|
|
109
|
+
if (result === 'SUCCESS') {
|
|
110
|
+
return;
|
|
111
|
+
} else {
|
|
112
|
+
throw new Error('Jenkins job failed');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Wait before polling again
|
|
117
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
118
|
+
}
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error('Error:', error.message);
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
package/src/next/pipline.js
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { getBitbucketInfo } from './config.js';
|
|
3
|
-
|
|
4
|
-
const BITBUCKET_BASE_URL = 'https://api.bitbucket.org/2.0';
|
|
5
|
-
|
|
6
|
-
const BITBUCKET_WS_URL = 'https://bitbucket.org/dp-cloud';
|
|
7
|
-
|
|
8
|
-
async function triggerPipelineByName(
|
|
9
|
-
repository,
|
|
10
|
-
pipelineName,
|
|
11
|
-
branch,
|
|
12
|
-
variables,
|
|
13
|
-
) {
|
|
14
|
-
const { username, password, workspace } = getBitbucketInfo();
|
|
15
|
-
const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/`;
|
|
16
|
-
const auth = {
|
|
17
|
-
username: username,
|
|
18
|
-
password: password,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const payload = {
|
|
22
|
-
target: {
|
|
23
|
-
type: 'pipeline_ref_target',
|
|
24
|
-
ref_type: 'branch',
|
|
25
|
-
ref_name: branch,
|
|
26
|
-
selector: {
|
|
27
|
-
type: 'custom',
|
|
28
|
-
pattern: pipelineName,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
variables: variables
|
|
32
|
-
? Object.entries(variables).map(([key, value]) => ({
|
|
33
|
-
key,
|
|
34
|
-
value,
|
|
35
|
-
secured: false, // Set to true if the variable should be secure
|
|
36
|
-
}))
|
|
37
|
-
: undefined,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
const response = await axios.post(url, payload, { auth });
|
|
42
|
-
return response.data;
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.error(
|
|
45
|
-
'Error triggering custom pipeline:',
|
|
46
|
-
error.response?.data || error.message,
|
|
47
|
-
);
|
|
48
|
-
throw error;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function getPipelineStatus(repository, pipelineUUID) {
|
|
53
|
-
const { username, password, workspace } = getBitbucketInfo();
|
|
54
|
-
const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/${pipelineUUID}`;
|
|
55
|
-
const auth = {
|
|
56
|
-
username: username,
|
|
57
|
-
password: password,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
const response = await axios.get(url, { auth });
|
|
62
|
-
return response.data.state.name;
|
|
63
|
-
} catch (error) {
|
|
64
|
-
console.error(
|
|
65
|
-
'Error fetching pipeline status:',
|
|
66
|
-
error.response?.data || error.message,
|
|
67
|
-
);
|
|
68
|
-
throw error;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export async function runPipeline(
|
|
73
|
-
repository,
|
|
74
|
-
pipelineName,
|
|
75
|
-
branch,
|
|
76
|
-
variables,
|
|
77
|
-
wait = false,
|
|
78
|
-
) {
|
|
79
|
-
try {
|
|
80
|
-
console.log(
|
|
81
|
-
`Triggering custom pipeline: ${pipelineName} for branch: ${branch}...`,
|
|
82
|
-
);
|
|
83
|
-
const pipeline = await triggerPipelineByName(
|
|
84
|
-
repository,
|
|
85
|
-
pipelineName,
|
|
86
|
-
branch,
|
|
87
|
-
variables,
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
const pipelineUUID = pipeline.uuid;
|
|
91
|
-
const buildNumber = pipeline.build_number;
|
|
92
|
-
|
|
93
|
-
console.log(`Pipeline triggered with UUID: ${pipelineUUID}`);
|
|
94
|
-
console.log(
|
|
95
|
-
`See results here: ${BITBUCKET_WS_URL}/${repository}/piplines/results/${buildNumber}`,
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
if (!wait) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
let status = '';
|
|
103
|
-
do {
|
|
104
|
-
console.log('Checking pipeline status...');
|
|
105
|
-
await new Promise((resolve) => setTimeout(resolve, 10000)); // Wait 10 seconds
|
|
106
|
-
status = await getPipelineStatus(repository, pipelineUUID);
|
|
107
|
-
console.log(`Pipeline status: ${status}`);
|
|
108
|
-
} while (['IN_PROGRESS', 'PENDING', 'RUNNING'].includes(status));
|
|
109
|
-
|
|
110
|
-
console.log(`Pipeline completed with status: ${status}`);
|
|
111
|
-
} catch (error) {
|
|
112
|
-
console.error('Error monitoring pipeline:', error.message);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { getBitbucketInfo } from './config.js';
|
|
3
|
+
|
|
4
|
+
const BITBUCKET_BASE_URL = 'https://api.bitbucket.org/2.0';
|
|
5
|
+
|
|
6
|
+
const BITBUCKET_WS_URL = 'https://bitbucket.org/dp-cloud';
|
|
7
|
+
|
|
8
|
+
async function triggerPipelineByName(
|
|
9
|
+
repository,
|
|
10
|
+
pipelineName,
|
|
11
|
+
branch,
|
|
12
|
+
variables,
|
|
13
|
+
) {
|
|
14
|
+
const { username, password, workspace } = getBitbucketInfo();
|
|
15
|
+
const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/`;
|
|
16
|
+
const auth = {
|
|
17
|
+
username: username,
|
|
18
|
+
password: password,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const payload = {
|
|
22
|
+
target: {
|
|
23
|
+
type: 'pipeline_ref_target',
|
|
24
|
+
ref_type: 'branch',
|
|
25
|
+
ref_name: branch,
|
|
26
|
+
selector: {
|
|
27
|
+
type: 'custom',
|
|
28
|
+
pattern: pipelineName,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
variables: variables
|
|
32
|
+
? Object.entries(variables).map(([key, value]) => ({
|
|
33
|
+
key,
|
|
34
|
+
value,
|
|
35
|
+
secured: false, // Set to true if the variable should be secure
|
|
36
|
+
}))
|
|
37
|
+
: undefined,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const response = await axios.post(url, payload, { auth });
|
|
42
|
+
return response.data;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error(
|
|
45
|
+
'Error triggering custom pipeline:',
|
|
46
|
+
error.response?.data || error.message,
|
|
47
|
+
);
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function getPipelineStatus(repository, pipelineUUID) {
|
|
53
|
+
const { username, password, workspace } = getBitbucketInfo();
|
|
54
|
+
const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/${pipelineUUID}`;
|
|
55
|
+
const auth = {
|
|
56
|
+
username: username,
|
|
57
|
+
password: password,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const response = await axios.get(url, { auth });
|
|
62
|
+
return response.data.state.name;
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error(
|
|
65
|
+
'Error fetching pipeline status:',
|
|
66
|
+
error.response?.data || error.message,
|
|
67
|
+
);
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function runPipeline(
|
|
73
|
+
repository,
|
|
74
|
+
pipelineName,
|
|
75
|
+
branch,
|
|
76
|
+
variables,
|
|
77
|
+
wait = false,
|
|
78
|
+
) {
|
|
79
|
+
try {
|
|
80
|
+
console.log(
|
|
81
|
+
`Triggering custom pipeline: ${pipelineName} for branch: ${branch}...`,
|
|
82
|
+
);
|
|
83
|
+
const pipeline = await triggerPipelineByName(
|
|
84
|
+
repository,
|
|
85
|
+
pipelineName,
|
|
86
|
+
branch,
|
|
87
|
+
variables,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const pipelineUUID = pipeline.uuid;
|
|
91
|
+
const buildNumber = pipeline.build_number;
|
|
92
|
+
|
|
93
|
+
console.log(`Pipeline triggered with UUID: ${pipelineUUID}`);
|
|
94
|
+
console.log(
|
|
95
|
+
`See results here: ${BITBUCKET_WS_URL}/${repository}/piplines/results/${buildNumber}`,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
if (!wait) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let status = '';
|
|
103
|
+
do {
|
|
104
|
+
console.log('Checking pipeline status...');
|
|
105
|
+
await new Promise((resolve) => setTimeout(resolve, 10000)); // Wait 10 seconds
|
|
106
|
+
status = await getPipelineStatus(repository, pipelineUUID);
|
|
107
|
+
console.log(`Pipeline status: ${status}`);
|
|
108
|
+
} while (['IN_PROGRESS', 'PENDING', 'RUNNING'].includes(status));
|
|
109
|
+
|
|
110
|
+
console.log(`Pipeline completed with status: ${status}`);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error('Error monitoring pipeline:', error.message);
|
|
113
|
+
}
|
|
114
|
+
}
|