@docupace/pipeline 1.0.4-4.8 → 1.0.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/bin/next-changeset-validate.sh +8 -8
- package/next/changeset.sh +75 -75
- package/next/copy.sh +34 -34
- package/next/deploy.sh +40 -40
- package/next/execute.sh +117 -117
- package/next/sonar.sh +23 -23
- package/package.json +4 -21
- package/src/changeset/cli.js +245 -334
- package/src/changeset/validate.js +44 -47
- package/src/next/cli.js +31 -182
- package/src/next/copy.js +27 -55
- package/src/next/deploy.js +72 -484
- package/src/next/publish.js +46 -48
- package/src/next/pull.js +7 -7
- package/src/next/sonar.js +23 -23
- package/.prettierrc.cjs +0 -12
- package/bin/azuread_update_callbacks_for_app.sh +0 -58
- package/eslint.config.js +0 -26
- package/src/auth0/alias.js +0 -72
- package/src/auth0/cli.js +0 -76
- package/src/auth0/configure.js +0 -783
- package/src/auth0/export.js +0 -43
- package/src/auth0/metadata.js +0 -132
- package/src/auth0/vault.js +0 -107
- package/src/jenkins/setParams.groovy +0 -59
- package/src/next/alias.js +0 -53
- package/src/next/apache.js +0 -73
- package/src/next/config.js +0 -100
- package/src/next/connect.js +0 -224
- package/src/next/haproxy.js +0 -71
- package/src/next/jenkins.js +0 -123
- package/src/next/jira.js +0 -83
- package/src/next/pipline.js +0 -114
- package/src/next/vault.js +0 -43
- package/terraform/apply.sh +0 -37
- package/terraform/init.sh +0 -72
- package/terraform/plan.sh +0 -76
- package/terraform/validate.sh +0 -17
package/src/next/connect.js
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import 'zx/globals'; // npm i zx
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { $ } from 'zx';
|
|
5
|
-
|
|
6
|
-
import { getVaultSecrets } from '../auth0/vault.js';
|
|
7
|
-
|
|
8
|
-
process.env.COMMON_VAULT_PATH =
|
|
9
|
-
process.env.COMMON_VAULT_PATH || 'secret/data/common/config';
|
|
10
|
-
process.env.VAULT_SKIP_VERIFY = process.env.VAULT_SKIP_VERIFY || 'true';
|
|
11
|
-
process.env.CONNECT_DIR = process.env.CONNECT_DIR || 'connect';
|
|
12
|
-
const vaultToken = process.env.VAULT_TOKEN;
|
|
13
|
-
const vaultAddr = process.env.VAULT_ADDR;
|
|
14
|
-
|
|
15
|
-
const connectUIEnvMap = {
|
|
16
|
-
dev: 'dev',
|
|
17
|
-
qa: 'preprod',
|
|
18
|
-
stage: 'stg',
|
|
19
|
-
uat: 'uat',
|
|
20
|
-
prod: 'prod-www3',
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const siteSettingsEnvMap = {
|
|
25
|
-
dev: 'dev',
|
|
26
|
-
preprod: 'preprod',
|
|
27
|
-
qa: 'preprod',
|
|
28
|
-
stage: 'staging',
|
|
29
|
-
stg: 'staging',
|
|
30
|
-
uat: 'uat',
|
|
31
|
-
prd: 'prod',
|
|
32
|
-
prod: 'prod',
|
|
33
|
-
'prod-www3': 'prod',
|
|
34
|
-
'prod-las': 'prod',
|
|
35
|
-
'prod-lax': 'prod',
|
|
36
|
-
'prod-athene': 'prod',
|
|
37
|
-
'prod-staging': 'prod',
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const idpEnvMap = {
|
|
41
|
-
dev: 'dev',
|
|
42
|
-
preprod: 'qa',
|
|
43
|
-
qa: 'qa',
|
|
44
|
-
stage: 'stage',
|
|
45
|
-
stg: 'stage',
|
|
46
|
-
uat: 'uat',
|
|
47
|
-
prd: 'prod',
|
|
48
|
-
prod: 'prod',
|
|
49
|
-
'prod-www3': 'prod',
|
|
50
|
-
'prod-las': 'prod',
|
|
51
|
-
'prod-lax': 'prod',
|
|
52
|
-
'prod-athene': 'prod',
|
|
53
|
-
'prod-staging': 'prod',
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
function log(msg) {
|
|
57
|
-
console.log(`[*] ${msg}`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/* --------------------------------
|
|
61
|
-
* 1. GIT CHECKOUT
|
|
62
|
-
* -------------------------------- */
|
|
63
|
-
async function gitCheckout(repository, destDir, branch = 'master') {
|
|
64
|
-
if (!(await fs.pathExists(destDir))) {
|
|
65
|
-
log(`Directory ${destDir} does not exist. Cloning repository...`);
|
|
66
|
-
} else {
|
|
67
|
-
log(`Directory ${destDir} exists. Removing it...`);
|
|
68
|
-
await fs.remove(destDir);
|
|
69
|
-
log(`Cloning ${destDir} repository...`);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const username = process.env.BITBUCKET_USERNAME;
|
|
73
|
-
const password = process.env.BITBUCKET_APP_PASSWORD;
|
|
74
|
-
|
|
75
|
-
// Construct clone command
|
|
76
|
-
const cloneUrl = `https://${username}:${password}@bitbucket.org/dp-cloud/${repository}.git`;
|
|
77
|
-
|
|
78
|
-
log(`Perform cloning`);
|
|
79
|
-
await $`git clone --branch=${branch} --depth 1 ${cloneUrl} ${destDir}`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export async function connectClone() {
|
|
83
|
-
// const connectFromEnv = connectUIEnvMap[process.env.FROM_BUILD_ENVIRONMENT];
|
|
84
|
-
const connectFromEnv = process.env.FROM_BUILD_ENVIRONMENT;
|
|
85
|
-
const connectToEnv = process.env.BUILD_ENVIRONMENT;
|
|
86
|
-
|
|
87
|
-
if (!vaultToken || !vaultAddr) {
|
|
88
|
-
console.error('Error: VAULT_TOKEN and VAULT_ADDR must be set.');
|
|
89
|
-
throw new Error('VAULT_TOKEN and VAULT_ADDR must be set.');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const site = process.env.BUILD_SITE;
|
|
93
|
-
if (!site) {
|
|
94
|
-
log('Error: BUILD_SITE is not set');
|
|
95
|
-
process.exit(1);
|
|
96
|
-
}
|
|
97
|
-
const siteCommonVaultPath = `secret/data/${site}/common/config`;
|
|
98
|
-
|
|
99
|
-
// 2) getVaultSecrets
|
|
100
|
-
const secretsJson = await getVaultSecrets(siteCommonVaultPath);
|
|
101
|
-
if (!secretsJson.AUTH0_CLIENT_ID) {
|
|
102
|
-
log('Failed to retrieve secret data.');
|
|
103
|
-
process.exit(1);
|
|
104
|
-
}
|
|
105
|
-
const siteCommonSecrets = secretsJson;
|
|
106
|
-
|
|
107
|
-
// 3) Export secrets as environment variables
|
|
108
|
-
process.env.AUTH0_CLIENT_ID = siteCommonSecrets.AUTH0_CLIENT_ID;
|
|
109
|
-
process.env.AUTH0_CLIENT_SECRET = siteCommonSecrets.AUTH0_CLIENT_SECRET;
|
|
110
|
-
|
|
111
|
-
process.env.AUTH0_REGION_DOMAIN = 'us.auth0.com';
|
|
112
|
-
|
|
113
|
-
log(`BUILD_ENVIRONMENT: ${connectToEnv}`);
|
|
114
|
-
log(`BUILD_SITE: ${process.env.BUILD_SITE}`);
|
|
115
|
-
log(`AUTH0_SUBDOMAIN: ${process.env.AUTH0_SUBDOMAIN}`);
|
|
116
|
-
log(`AUTH0_REGION_DOMAIN: ${process.env.AUTH0_REGION_DOMAIN}`);
|
|
117
|
-
log(`AUTH0_CLIENT_ID: ${process.env.AUTH0_CLIENT_ID}`);
|
|
118
|
-
|
|
119
|
-
process.env.AUTH0_DOMAIN = `docupace-${idpEnvMap[process.env.BUILD_ENVIRONMENT]}-${process.env.BUILD_SITE}.${process.env.AUTH0_REGION_DOMAIN}`;
|
|
120
|
-
|
|
121
|
-
const projectRoot = process.cwd();
|
|
122
|
-
// 4) Clone 'connect-deploy' into CONNECT_DIR
|
|
123
|
-
|
|
124
|
-
await gitCheckout('connect-deploy', process.env.CONNECT_DIR);
|
|
125
|
-
|
|
126
|
-
await gitCheckout(
|
|
127
|
-
`${siteSettingsEnvMap[connectToEnv]}-site-settings`,
|
|
128
|
-
`${process.env.CONNECT_DIR}/${siteSettingsEnvMap[connectToEnv]}-site-settings`,
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
// 5) Create site clone (emulating the dock.sh call)
|
|
132
|
-
const cloneFrom = path.join(
|
|
133
|
-
projectRoot,
|
|
134
|
-
process.env.CONNECT_DIR,
|
|
135
|
-
`envs`,
|
|
136
|
-
`${connectFromEnv}/${process.env.FROM_BUILD_SITE}`,
|
|
137
|
-
);
|
|
138
|
-
const cloneTo = path.join(
|
|
139
|
-
projectRoot,
|
|
140
|
-
process.env.CONNECT_DIR,
|
|
141
|
-
`envs`,
|
|
142
|
-
`${connectToEnv}/${process.env.BUILD_SITE}`,
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
if (!(await fs.pathExists(cloneFrom))) {
|
|
146
|
-
log('Clone template directory not found:');
|
|
147
|
-
process.exit(1);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if (!(await fs.pathExists(cloneTo))) {
|
|
151
|
-
log('New site does not exist. Performing cloning...');
|
|
152
|
-
|
|
153
|
-
process.env.IMAGE_VERSION =
|
|
154
|
-
await $`cd ${cloneFrom} && grep -E '^IMAGE_VERSION=' dock.sh | cut -f2 -d=`;
|
|
155
|
-
log(`Image version: ${process.env.IMAGE_VERSION}`);
|
|
156
|
-
//await $`cd ${cloneFrom} && bash dock.sh clone ${process.env.BUILD_ENVIRONMENT} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
|
|
157
|
-
await (async () => {
|
|
158
|
-
try {
|
|
159
|
-
// Execute the shell command
|
|
160
|
-
const result =
|
|
161
|
-
await $`cd ${cloneFrom} && bash dock.sh clone ${connectToEnv} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
|
|
162
|
-
await $`cd ${cloneTo} && git checkout master && git pull --ff-only`;
|
|
163
|
-
await $`cd ${cloneTo} && git remote -v`;
|
|
164
|
-
await $`cd ${cloneTo} && git branch`;
|
|
165
|
-
await $`cd ${cloneTo} && git status`;
|
|
166
|
-
await $`cd ${cloneTo} && git add . ../sites.sh`;
|
|
167
|
-
|
|
168
|
-
console.log('Command succeeded:');
|
|
169
|
-
console.log('stdout:', result.stdout); // Standard output
|
|
170
|
-
console.log('stderr:', result.stderr); // Standard error
|
|
171
|
-
} catch (error) {
|
|
172
|
-
console.error('Command failed:');
|
|
173
|
-
console.error('Exit Code:', error._code); // Exit code of the command
|
|
174
|
-
console.error('Signal:', error._signal); // Signal that caused termination (if any)
|
|
175
|
-
console.error('stdout:', error._stdout); // Standard output
|
|
176
|
-
console.error('stderr:', error._stderr); // Standard error
|
|
177
|
-
}
|
|
178
|
-
})();
|
|
179
|
-
} else {
|
|
180
|
-
log('Site already exists. Continuing Auth0 setup...');
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
await (async () => {
|
|
184
|
-
try {
|
|
185
|
-
// Execute the shell command
|
|
186
|
-
const result = await $`cd ${cloneTo} && bash dock.sh getAuth0Metadata`;
|
|
187
|
-
console.log('Command succeeded:');
|
|
188
|
-
console.log('stdout:', result.stdout); // Standard output
|
|
189
|
-
console.log('stderr:', result.stderr); // Standard error
|
|
190
|
-
} catch (error) {
|
|
191
|
-
console.error('Command failed:');
|
|
192
|
-
console.error('Exit Code:', error._code); // Exit code of the command
|
|
193
|
-
console.error('Signal:', error._signal); // Signal that caused termination (if any)
|
|
194
|
-
console.error('stdout:', error._stdout); // Standard output
|
|
195
|
-
console.error('stderr:', error._stderr); // Standard error
|
|
196
|
-
}
|
|
197
|
-
})();
|
|
198
|
-
|
|
199
|
-
// 7) Check conf files, print logs
|
|
200
|
-
await $`grep "auth0" ${path.join(cloneTo, 'conf/application.conf')}`;
|
|
201
|
-
await $`ls -all ${path.join(cloneTo, 'conf')}`;
|
|
202
|
-
await $`ls -all ${path.join(cloneTo, 'conf/saml')}`;
|
|
203
|
-
await $`cat ${path.join(cloneTo, 'conf/saml/auth0.xml')}`;
|
|
204
|
-
|
|
205
|
-
// 8) Git add, commit, push
|
|
206
|
-
await $`cd ${cloneTo} && git add ./conf/application.conf ./conf/saml/auth0.xml`;
|
|
207
|
-
await $`cd ${cloneTo} && git status`;
|
|
208
|
-
|
|
209
|
-
const numChanges = (await $`cd ${cloneTo} && git diff-index HEAD`).stdout
|
|
210
|
-
.split('\n')
|
|
211
|
-
.filter(Boolean).length;
|
|
212
|
-
|
|
213
|
-
if (numChanges > 0) {
|
|
214
|
-
const jiraTicket = process.env.JIRA_TICKET || 'NO_JIRA';
|
|
215
|
-
const message = `${jiraTicket} usdoc-s-builui job download_auth0_metadata for ${connectToEnv}/${process.env.BUILD_SITE}`;
|
|
216
|
-
log('About to commit changes to git');
|
|
217
|
-
await $`cd ${cloneTo} && git commit -m ${message}`;
|
|
218
|
-
await $`cd ${cloneTo} && git push -u origin master`;
|
|
219
|
-
} else {
|
|
220
|
-
log(
|
|
221
|
-
'No changes have been made. The site likely already has the correct configuration.',
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
}
|
package/src/next/haproxy.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { $ } from 'zx';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
export async function haproxySync() {
|
|
6
|
-
const cluster = process.env.HAPROXY_CLUSTER;
|
|
7
|
-
if (cluster !== 'preprod' && cluster !== 'stage' && cluster !== 'prod-www3') {
|
|
8
|
-
console.log('Error: Cluster must be preprod or stage');
|
|
9
|
-
process.exit(1);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const repoPath = '/root/repo/docupace-ansible';
|
|
13
|
-
const inventory = path.join(repoPath, `inventories/${cluster}/inventory`);
|
|
14
|
-
|
|
15
|
-
// Create haproxy.sh
|
|
16
|
-
const cluserHostMap = {
|
|
17
|
-
preprod: {
|
|
18
|
-
host: '10.10.28.198',
|
|
19
|
-
branch: 'master',
|
|
20
|
-
},
|
|
21
|
-
stage: {
|
|
22
|
-
host: '10.12.28.10',
|
|
23
|
-
branch: 'INFP-6565-haproxy-prod-implementation',
|
|
24
|
-
},
|
|
25
|
-
'prod-www3': {
|
|
26
|
-
host: '10.13.28.45',
|
|
27
|
-
branch: 'INFP-6565-haproxy-prod-implementation',
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const scriptContent = `
|
|
32
|
-
#!/bin/bash
|
|
33
|
-
|
|
34
|
-
[[ ! -f ${inventory} ]] && ( echo "Alert: no inventory file: ${inventory}" ; exit 1 )
|
|
35
|
-
cd ${repoPath}
|
|
36
|
-
pwd
|
|
37
|
-
git stash
|
|
38
|
-
git fetch --all
|
|
39
|
-
git pull origin master
|
|
40
|
-
git checkout ${cluserHostMap[cluster].branch}
|
|
41
|
-
git submodule update --remote
|
|
42
|
-
git submodule foreach --recursive git checkout master
|
|
43
|
-
git submodule foreach --recursive git pull origin master
|
|
44
|
-
|
|
45
|
-
ansible-playbook -i inventories/${cluster}/inventory haproxy.yml -e "cluster=${cluster} -e build=true"
|
|
46
|
-
|
|
47
|
-
echo "proceeding"
|
|
48
|
-
echo "committing changes"
|
|
49
|
-
git add ${cluster}-haproxy.cfg
|
|
50
|
-
git commit -m "Sync haproxy"
|
|
51
|
-
git push origin master
|
|
52
|
-
`;
|
|
53
|
-
|
|
54
|
-
await fs.writeFile('haproxy.sh', scriptContent);
|
|
55
|
-
|
|
56
|
-
// Private key
|
|
57
|
-
const haproxyPrivateKey = process.env.HAPROXY_PRIVATE_KEY;
|
|
58
|
-
if (!haproxyPrivateKey) {
|
|
59
|
-
console.log('Error: HAPROXY_PRIVATE_KEY not set.');
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
await fs.writeFile('private.key', Buffer.from(haproxyPrivateKey, 'base64'));
|
|
64
|
-
await fs.chmod('private.key', 0o600);
|
|
65
|
-
|
|
66
|
-
// Copy script to remote
|
|
67
|
-
await $`scp -i private.key -o StrictHostKeyChecking=no haproxy.sh root@${cluserHostMap[cluster].host}:/tmp/haproxy.sh`;
|
|
68
|
-
|
|
69
|
-
// Execute script on remote
|
|
70
|
-
await $`ssh -i private.key -o StrictHostKeyChecking=no root@${cluserHostMap[cluster].host} "bash /tmp/haproxy.sh"`;
|
|
71
|
-
}
|
package/src/next/jenkins.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
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/jira.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
// Create preconfigured axios instance for Jira
|
|
4
|
-
const jiraClient = axios.create({
|
|
5
|
-
baseURL: 'https://docupacellc.atlassian.net',
|
|
6
|
-
auth: {
|
|
7
|
-
username: process.env.JIRA_API_EMAIL,
|
|
8
|
-
password: process.env.JIRA_API_KEY,
|
|
9
|
-
},
|
|
10
|
-
headers: {
|
|
11
|
-
'Content-Type': 'application/json',
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const packageComponents = {
|
|
16
|
-
'docupace-ui': 'next-ui',
|
|
17
|
-
'docupace-graphql-server': 'graphql-server',
|
|
18
|
-
'@docupace/template': 'template',
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Updates the component version custom field in Jira
|
|
22
|
-
* @param {string} issueKey - The Jira issue key
|
|
23
|
-
* @param {string} component - The component name
|
|
24
|
-
* @param {string} version - The version to set
|
|
25
|
-
*/
|
|
26
|
-
export async function updateComponentVersion(issueKey, packageName, version) {
|
|
27
|
-
const component = packageComponents[packageName] ?? packageName;
|
|
28
|
-
console.log(
|
|
29
|
-
`Updating ${issueKey} for package ${packageName} translated to component ${component} with version ${version}`,
|
|
30
|
-
);
|
|
31
|
-
try {
|
|
32
|
-
// First get current field value
|
|
33
|
-
const response = await jiraClient.get(
|
|
34
|
-
`/rest/api/2/issue/${issueKey}?fields=customfield_10458`,
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
let currentValue = response.data.fields.customfield_10458 || '';
|
|
38
|
-
let components = new Map();
|
|
39
|
-
|
|
40
|
-
// Parse existing components
|
|
41
|
-
if (currentValue) {
|
|
42
|
-
currentValue.split(';').forEach((entry) => {
|
|
43
|
-
const [comp, ver] = entry.split(':');
|
|
44
|
-
components.set(comp, ver);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Update or add new component version
|
|
49
|
-
components.set(component, version);
|
|
50
|
-
|
|
51
|
-
// Convert back to string format
|
|
52
|
-
const newValue = Array.from(components.entries())
|
|
53
|
-
.map(([comp, ver]) => `${comp}:${ver}`)
|
|
54
|
-
.join(';');
|
|
55
|
-
|
|
56
|
-
// Update the field
|
|
57
|
-
await jiraClient.put(`/rest/api/2/issue/${issueKey}`, {
|
|
58
|
-
fields: {
|
|
59
|
-
customfield_10458: newValue,
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
console.log(`Updated component versions for ${issueKey}: ${newValue}`);
|
|
64
|
-
} catch (error) {
|
|
65
|
-
console.error(`Error updating Jira component version: ${error.message}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Makes a request to the Jira API using preconfigured client
|
|
71
|
-
* @param {string} endpoint - The API endpoint (starting with /)
|
|
72
|
-
* @param {Object} options - Request options (method, body, etc)
|
|
73
|
-
* @returns {Promise<any>} The response data
|
|
74
|
-
*/
|
|
75
|
-
export async function makeJiraRequest(endpoint, options = {}) {
|
|
76
|
-
try {
|
|
77
|
-
const response = await jiraClient.get(endpoint, options);
|
|
78
|
-
return response.data;
|
|
79
|
-
} catch (error) {
|
|
80
|
-
console.error(`Error making Jira request: ${error.message}`);
|
|
81
|
-
throw error;
|
|
82
|
-
}
|
|
83
|
-
}
|
package/src/next/pipline.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
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
|
-
}
|
package/src/next/vault.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
|
|
3
|
-
export async function vaultAddSiteData(SITE, SITE_CONFIG_REMOTE_PATH) {
|
|
4
|
-
const AUTH0_CLIENT_ID = process.env.AUTH0_CLIENT_ID;
|
|
5
|
-
const AUTH0_CLIENT_SECRET = process.env.AUTH0_CLIENT_SECRET;
|
|
6
|
-
const VAULT_ADDR = process.env.VAULT_ADDR; // Vault host URL from environment variables
|
|
7
|
-
const VAULT_TOKEN = process.env.VAULT_TOKEN; // Vault token from environment variables
|
|
8
|
-
|
|
9
|
-
if (!VAULT_ADDR || !VAULT_TOKEN) {
|
|
10
|
-
throw new Error('Missing VAULT_ADDR or VAULT_TOKEN environment variable.');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const vaultApiUrl = `${VAULT_ADDR}/v1/secret/data/${SITE}/common/config`;
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
|
|
17
|
-
if (process.env.VAULT_SKIP_VERIFY === 'true') {
|
|
18
|
-
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const response = await axios.post(
|
|
22
|
-
vaultApiUrl,
|
|
23
|
-
{
|
|
24
|
-
data: {
|
|
25
|
-
AUTH0_CLIENT_ID: AUTH0_CLIENT_ID,
|
|
26
|
-
AUTH0_CLIENT_SECRET: AUTH0_CLIENT_SECRET,
|
|
27
|
-
SITE_CONFIG_REMOTE_PATH: SITE_CONFIG_REMOTE_PATH,
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
headers: {
|
|
32
|
-
'X-Vault-Token': VAULT_TOKEN,
|
|
33
|
-
'Content-Type': 'application/json',
|
|
34
|
-
},
|
|
35
|
-
}
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
console.log('Data added to Vault successfully:', response.data);
|
|
39
|
-
} catch (error) {
|
|
40
|
-
console.error('Error adding data to Vault:', error.response?.data || error.message);
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
}
|
package/terraform/apply.sh
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
set -e
|
|
3
|
-
|
|
4
|
-
PROJECT=$1
|
|
5
|
-
export ROLE_NAME="${2:-atlassian-bitbucket-pipelines-runner-eks-role}"
|
|
6
|
-
|
|
7
|
-
if [[ -z "$PROJECT" ]]; then
|
|
8
|
-
echo "Error: Project name is required."
|
|
9
|
-
echo "Usage: $0 <project-name>"
|
|
10
|
-
exit 1
|
|
11
|
-
fi
|
|
12
|
-
|
|
13
|
-
if [ "$CURRENT_ENVIRONMENT" == "prd" ]; then
|
|
14
|
-
export EKS_CLUSTER_NAME="connect-next-prd-eks-cluster"
|
|
15
|
-
CURRENT_ENVIRONMENT="prod"
|
|
16
|
-
elif [ "$CURRENT_ENVIRONMENT" == "stg" ]; then
|
|
17
|
-
export EKS_CLUSTER_NAME="connect-next-stg-eks-cluster"
|
|
18
|
-
CURRENT_ENVIRONMENT="stage"
|
|
19
|
-
else
|
|
20
|
-
export EKS_CLUSTER_NAME="connect-next-${CURRENT_ENVIRONMENT}-eks-cluster"
|
|
21
|
-
fi
|
|
22
|
-
|
|
23
|
-
echo "Using EKS cluster: $EKS_CLUSTER_NAME"
|
|
24
|
-
|
|
25
|
-
export SESSION_NAME="EKSAdminSession"
|
|
26
|
-
export ROLE_ARN="arn:aws:iam::$(aws sts get-caller-identity | jq -r '.Account'):role/$ROLE_NAME"
|
|
27
|
-
export ASSUME_ROLE_OUTPUT=$(aws sts assume-role --role-arn $ROLE_ARN --role-session-name $SESSION_NAME)
|
|
28
|
-
export AWS_ACCESS_KEY_ID=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.AccessKeyId')
|
|
29
|
-
export AWS_SECRET_ACCESS_KEY=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SecretAccessKey')
|
|
30
|
-
export AWS_SESSION_TOKEN=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SessionToken')
|
|
31
|
-
export TF_IN_AUTOMATION=1
|
|
32
|
-
|
|
33
|
-
aws sts get-caller-identity
|
|
34
|
-
|
|
35
|
-
cd "$BITBUCKET_CLONE_DIR/${PROJECT}"
|
|
36
|
-
|
|
37
|
-
terraform apply -input=false .tfplan
|