@docupace/pipeline 1.0.7-beta.2 → 1.0.8-6.xray
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/README.md +136 -0
- package/bin/azuread_update_callbacks_for_app.sh +58 -0
- package/bin/xray.sh +273 -0
- package/bitbucket-pipelines.yml +142 -0
- package/eslint.config.js +25 -2
- package/jest.config.js +15 -0
- package/next/execute.sh +8 -2
- package/package.json +23 -7
- package/src/auth0/alias.js +79 -0
- package/src/auth0/alias.test.js +172 -0
- package/src/auth0/cli.js +82 -0
- package/src/auth0/configure.js +902 -0
- package/src/auth0/configure.test.js +167 -0
- package/src/auth0/export.js +48 -0
- package/src/auth0/export.test.js +103 -0
- package/src/auth0/metadata.js +141 -0
- package/src/auth0/metadata.test.js +186 -0
- package/src/auth0/vault.js +60 -0
- package/src/auth0/vault.test.js +134 -0
- package/src/changeset/changelog-wiki.js +328 -0
- package/src/changeset/changeset-config.js +34 -0
- package/src/changeset/cli.js +151 -195
- package/src/changeset/create.js +215 -0
- package/src/changeset/package-util.js +87 -0
- package/src/changeset/util.js +43 -0
- package/src/changeset/validate.js +45 -1
- package/src/changeset/version.js +102 -0
- package/src/jenkins/setParams.groovy +1 -2
- package/src/jfrog/xray-scan.yaml +29 -0
- package/src/lib/merge-driver.js +204 -0
- package/src/merge/cli-merge-all.js +521 -0
- package/src/merge/cli-merge.js +572 -0
- package/src/merge/cli-resolve.js +399 -0
- package/src/merge/cli.js +38 -0
- package/src/merge/common.js +7 -0
- package/src/merge/merge-changelog.js +87 -0
- package/src/merge/merge-package.js +106 -0
- package/src/merge/merge-types.js +82 -0
- package/src/merge/pr.js +231 -0
- package/src/micro/cli.js +51 -0
- package/src/micro/ms-deploy.js +451 -0
- package/src/micro/ms-publish.js +186 -0
- package/src/next/alias.js +53 -0
- package/src/next/apache.js +81 -0
- package/src/next/cli.js +111 -15
- package/src/next/config.js +72 -7
- package/src/next/connect.js +226 -0
- package/src/next/copy.js +32 -1
- package/src/next/deploy.js +514 -75
- package/src/next/git-to-semver.js +79 -0
- package/src/next/haproxy.js +76 -0
- package/src/next/jenkins.js +3 -2
- package/src/next/jira.js +84 -0
- package/src/next/logger.js +17 -0
- package/src/next/pipline.js +0 -1
- package/src/next/publish.js +53 -30
- package/src/next/test.js +5 -0
- package/src/next/util.js +95 -0
- package/src/next/vault.js +45 -0
- package/terraform/apply.sh +41 -0
- package/terraform/import.sh +111 -0
- package/terraform/init.sh +78 -0
- package/terraform/plan.sh +95 -0
- package/terraform/validate.sh +17 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts git describe output to semantic versioning format
|
|
3
|
+
*
|
|
4
|
+
* Logic based on dash count:
|
|
5
|
+
* - 2 dashes: Released version with commits (v1.2.3-4-g1234567 -> 1.2.3+4.g1234567)
|
|
6
|
+
* - 3 dashes: Pre-release with commits (v1.2.3-rc.1-4-g1234567 -> 1.2.3-rc.1+4.g1234567)
|
|
7
|
+
* - 1 dash: Pre-release tag only (v1.2.3-rc.1 -> 1.2.3-rc.1)
|
|
8
|
+
* - 0 dashes: Clean tag (v1.2.3 -> 1.2.3)
|
|
9
|
+
*
|
|
10
|
+
* @param {string} gitDescribe - The output from git describe
|
|
11
|
+
* @return {string} Semver compatible version string
|
|
12
|
+
*/
|
|
13
|
+
export function gitDescribeToSemver(gitDescribe) {
|
|
14
|
+
if (!gitDescribe || typeof gitDescribe !== 'string') {
|
|
15
|
+
throw new Error('Invalid input: git describe string required');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Remove leading 'v' if present
|
|
19
|
+
let version = gitDescribe.trim();
|
|
20
|
+
if (version.startsWith('v') || version.startsWith('V')) {
|
|
21
|
+
version = version.substring(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Count dashes to determine format
|
|
25
|
+
const dashCount = (version.match(/-/g) || []).length;
|
|
26
|
+
|
|
27
|
+
switch (dashCount) {
|
|
28
|
+
case 0:
|
|
29
|
+
// Clean tag: 1.2.3
|
|
30
|
+
return version;
|
|
31
|
+
|
|
32
|
+
case 1:
|
|
33
|
+
// Pre-release tag only: 1.2.3-rc.1
|
|
34
|
+
return version;
|
|
35
|
+
|
|
36
|
+
case 2: {
|
|
37
|
+
// Released version with commits: 1.2.3-4-g1234567
|
|
38
|
+
// Split: [1.2.3, 4, g1234567]
|
|
39
|
+
const parts = version.split('-');
|
|
40
|
+
const baseVersion = parts[0];
|
|
41
|
+
const commits = parts[1];
|
|
42
|
+
const hash = parts[2];
|
|
43
|
+
return `${baseVersion}+${commits}.${hash}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
case 3: {
|
|
47
|
+
// Pre-release with commits: 1.2.3-rc.1-4-g1234567
|
|
48
|
+
// Split: [1.2.3, rc.1, 4, g1234567]
|
|
49
|
+
const parts = version.split('-');
|
|
50
|
+
const baseVersion = parts[0];
|
|
51
|
+
const prerelease = parts[1];
|
|
52
|
+
const commits = parts[2];
|
|
53
|
+
const hash = parts[3];
|
|
54
|
+
return `${baseVersion}-${prerelease}+${commits}.${hash}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
default: {
|
|
58
|
+
// More than 3 dashes - handle complex pre-release tags
|
|
59
|
+
// e.g., 1.2.3-rc-1-beta-4-g1234567
|
|
60
|
+
// Assume last two parts are commits-hash
|
|
61
|
+
const parts = version.split('-');
|
|
62
|
+
if (
|
|
63
|
+
parts.length >= 3 &&
|
|
64
|
+
/^\d+$/.test(parts[parts.length - 2]) &&
|
|
65
|
+
/^g[a-f0-9]+$/.test(parts[parts.length - 1])
|
|
66
|
+
) {
|
|
67
|
+
// Has commits and hash at the end
|
|
68
|
+
const commits = parts[parts.length - 2];
|
|
69
|
+
const hash = parts[parts.length - 1];
|
|
70
|
+
const versionParts = parts.slice(0, -2);
|
|
71
|
+
const baseVersion = versionParts[0];
|
|
72
|
+
const prerelease = versionParts.slice(1).join('-');
|
|
73
|
+
return `${baseVersion}-${prerelease}+${commits}.${hash}`;
|
|
74
|
+
}
|
|
75
|
+
// No commits/hash pattern found, treat as complex pre-release
|
|
76
|
+
return version;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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: 'master',
|
|
24
|
+
},
|
|
25
|
+
'prod-www2': {
|
|
26
|
+
host: ' 10.13.28.43',
|
|
27
|
+
branch: 'master',
|
|
28
|
+
},
|
|
29
|
+
'prod-www3': {
|
|
30
|
+
host: '10.13.28.45',
|
|
31
|
+
branch: 'master',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const scriptContent = `
|
|
36
|
+
#!/bin/bash
|
|
37
|
+
|
|
38
|
+
[[ ! -f ${inventory} ]] && ( echo "Alert: no inventory file: ${inventory}" ; exit 1 )
|
|
39
|
+
cd ${repoPath}
|
|
40
|
+
pwd
|
|
41
|
+
git reset --hard
|
|
42
|
+
git clean -fd
|
|
43
|
+
git fetch --all
|
|
44
|
+
git pull origin master
|
|
45
|
+
git checkout ${cluserHostMap[cluster].branch}
|
|
46
|
+
git submodule update --remote
|
|
47
|
+
git submodule foreach --recursive git checkout master
|
|
48
|
+
git submodule foreach --recursive git pull origin master
|
|
49
|
+
|
|
50
|
+
ansible-playbook -i inventories/${cluster}/inventory haproxy.yml -e "cluster=${cluster} -e build=true"
|
|
51
|
+
|
|
52
|
+
echo "proceeding"
|
|
53
|
+
echo "committing changes"
|
|
54
|
+
git add ${cluster}-haproxy.cfg
|
|
55
|
+
git commit -m "Sync haproxy"
|
|
56
|
+
git push origin master
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
await fs.writeFile('haproxy.sh', scriptContent);
|
|
60
|
+
|
|
61
|
+
// Private key
|
|
62
|
+
const haproxyPrivateKey = process.env.HAPROXY_PRIVATE_KEY;
|
|
63
|
+
if (!haproxyPrivateKey) {
|
|
64
|
+
console.log('Error: HAPROXY_PRIVATE_KEY not set.');
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
await fs.writeFile('private.key', Buffer.from(haproxyPrivateKey, 'base64'));
|
|
69
|
+
await fs.chmod('private.key', 0o600);
|
|
70
|
+
|
|
71
|
+
// Copy script to remote
|
|
72
|
+
await $`scp -i private.key -o StrictHostKeyChecking=no haproxy.sh root@${cluserHostMap[cluster].host}:/tmp/haproxy.sh`;
|
|
73
|
+
|
|
74
|
+
// Execute script on remote
|
|
75
|
+
await $`ssh -i private.key -o StrictHostKeyChecking=no root@${cluserHostMap[cluster].host} "bash /tmp/haproxy.sh"`;
|
|
76
|
+
}
|
package/src/next/jenkins.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
|
|
3
|
-
const CORE_JENKINS_URL =
|
|
4
|
-
const CORE_JOB_NAME =
|
|
3
|
+
const CORE_JENKINS_URL = process.env.CORE_JENKINS_URL;
|
|
4
|
+
const CORE_JOB_NAME = process.env.CORE_JENKINS_JOB_NAME;
|
|
5
5
|
const CORE_USERNAME = process.env.CORE_JENKINS_USERNAME;
|
|
6
6
|
const CORE_API_TOKEN = process.env.CORE_JENKINS_API_TOKEN;
|
|
7
7
|
|
|
@@ -26,6 +26,7 @@ export async function deployCore(env, site, liquibase, gitBranch) {
|
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
// eslint-disable-next-line no-unused-vars
|
|
29
30
|
export async function deployConnect(env, site, liquibase, branch) {
|
|
30
31
|
const parameters = {
|
|
31
32
|
BUILD_ENVIRONMENT: env,
|
package/src/next/jira.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
/**
|
|
16
|
+
* Updates the component version custom field in Jira
|
|
17
|
+
* @param {string} issueKey - The Jira issue key
|
|
18
|
+
* @param {string} packageName - The package name
|
|
19
|
+
* @param {string} version - The version to set
|
|
20
|
+
*/
|
|
21
|
+
export async function updateComponentVersion(issueKey, packageName, version) {
|
|
22
|
+
const component = packageName.includes('/')
|
|
23
|
+
? packageName.split('/')[1]
|
|
24
|
+
: packageName;
|
|
25
|
+
console.log(
|
|
26
|
+
`Updating ${issueKey} for package ${packageName} translated to component ${component} with version ${version}`,
|
|
27
|
+
);
|
|
28
|
+
try {
|
|
29
|
+
// First get current field value
|
|
30
|
+
const response = await jiraClient.get(
|
|
31
|
+
`/rest/api/2/issue/${issueKey}?fields=customfield_10458`,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
let currentValue = response.data.fields.customfield_10458 || '';
|
|
35
|
+
let components = new Map();
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
// Parse existing components
|
|
39
|
+
if (currentValue) {
|
|
40
|
+
currentValue.split(';').forEach((entry) => {
|
|
41
|
+
const [comp, ver] = entry.split(':');
|
|
42
|
+
components.set(comp, ver);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
// Update or add new component version
|
|
46
|
+
} catch {
|
|
47
|
+
console.log('Patch version has incorrect data overriding');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
components.set(component, version);
|
|
51
|
+
|
|
52
|
+
// Convert back to string format
|
|
53
|
+
const newValue = Array.from(components.entries())
|
|
54
|
+
.map(([comp, ver]) => `${comp}:${ver}`)
|
|
55
|
+
.join(';');
|
|
56
|
+
|
|
57
|
+
// Update the field
|
|
58
|
+
await jiraClient.put(`/rest/api/2/issue/${issueKey}`, {
|
|
59
|
+
fields: {
|
|
60
|
+
customfield_10458: newValue,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
console.log(`Updated component versions for ${issueKey}: ${newValue}`);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error(`Error updating Jira component version: ${error.message}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Makes a request to the Jira API using preconfigured client
|
|
72
|
+
* @param {string} endpoint - The API endpoint (starting with /)
|
|
73
|
+
* @param {Object} options - Request options (method, body, etc)
|
|
74
|
+
* @returns {Promise<any>} The response data
|
|
75
|
+
*/
|
|
76
|
+
export async function makeJiraRequest(endpoint, options = {}) {
|
|
77
|
+
try {
|
|
78
|
+
const response = await jiraClient.get(endpoint, options);
|
|
79
|
+
return response.data;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error(`Error making Jira request: ${error.message}`);
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { $ as original$ } from 'zx';
|
|
2
|
+
|
|
3
|
+
// Wrapped version of $
|
|
4
|
+
export const $ = async (strings, ...values) => {
|
|
5
|
+
const command = strings.reduce(
|
|
6
|
+
(acc, str, i) => acc + str + (values[i] ?? ''),
|
|
7
|
+
'',
|
|
8
|
+
);
|
|
9
|
+
console.log(`Executing: ${command}`);
|
|
10
|
+
try {
|
|
11
|
+
const result = await original$(strings, ...values);
|
|
12
|
+
return result;
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.error(`Error executing: ${command}`, error);
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
};
|
package/src/next/pipline.js
CHANGED
package/src/next/publish.js
CHANGED
|
@@ -1,48 +1,71 @@
|
|
|
1
|
-
import { $ } from '
|
|
1
|
+
import { $ } from './logger.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const {
|
|
4
|
+
JF_REGISTRY_URL,
|
|
5
|
+
JF_REGISTRY_REPO_NAME,
|
|
6
|
+
JF_REGISTRY_PASSWORD_DEV,
|
|
7
|
+
JF_REGISTRY_USER_DEV,
|
|
8
|
+
BITBUCKET_REPO_SLUG,
|
|
9
|
+
BITBUCKET_BUILD_NUMBER,
|
|
10
|
+
APP_NAME,
|
|
11
|
+
} = process.env;
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
const JF_REGISTRY_FULL_URL = `${JF_REGISTRY_URL}/${JF_REGISTRY_REPO_NAME}`;
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
await $`echo ${
|
|
15
|
+
async function loginRegistry() {
|
|
16
|
+
await $`echo ${JF_REGISTRY_PASSWORD_DEV} | docker login --username ${JF_REGISTRY_USER_DEV} --password-stdin ${JF_REGISTRY_URL}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function logoutRegistry() {
|
|
20
|
+
await $`docker logout ${JF_REGISTRY_URL}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function publish(gitSha) {
|
|
24
|
+
process.env.DOCKER_HOST = '';
|
|
25
|
+
|
|
26
|
+
console.log(JSON.stringify(process.env));
|
|
27
|
+
|
|
28
|
+
const IMAGE_PREFIX = APP_NAME ?? BITBUCKET_REPO_SLUG;
|
|
29
|
+
const BUILD_IMAGE_NAME = `${IMAGE_PREFIX}:build-${BITBUCKET_BUILD_NUMBER}`;
|
|
30
|
+
const IMAGE_NAME = `${IMAGE_PREFIX}:sha-${gitSha}`;
|
|
31
|
+
|
|
32
|
+
console.log(`Publishing Docker image ${IMAGE_NAME}...`);
|
|
13
33
|
|
|
14
|
-
|
|
34
|
+
await loginRegistry();
|
|
35
|
+
|
|
36
|
+
let manifestExists = false;
|
|
15
37
|
try {
|
|
38
|
+
$.verbose = false; // Silence output temporarily
|
|
16
39
|
await $`docker manifest inspect ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
|
|
40
|
+
manifestExists = true;
|
|
41
|
+
} catch {
|
|
42
|
+
manifestExists = false;
|
|
43
|
+
} finally {
|
|
44
|
+
$.verbose = true; // Restore normal output
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (manifestExists) {
|
|
17
48
|
console.log(
|
|
18
|
-
`Tag sha-${
|
|
49
|
+
`Tag sha-${gitSha} already exists in the remote repository. Skipping push.`,
|
|
19
50
|
);
|
|
20
|
-
}
|
|
51
|
+
} else {
|
|
21
52
|
await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
|
|
22
53
|
await $`docker push ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
|
|
23
54
|
}
|
|
24
55
|
|
|
25
|
-
// Tag and push build image
|
|
26
56
|
await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
|
|
27
57
|
await $`docker push ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
|
|
28
58
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
console.log(`Tagging and pushing Docker image for Git tag: ${gitTag}`);
|
|
39
|
-
await $`docker tag ${IMAGE_NAME} ${dockerTag}`;
|
|
40
|
-
await $`docker push ${dockerTag}`;
|
|
41
|
-
}
|
|
42
|
-
} else {
|
|
43
|
-
console.log('No Git tags found pointing to the current HEAD.');
|
|
59
|
+
const gitTags = (await $`git tag --points-at HEAD`).stdout
|
|
60
|
+
.trim()
|
|
61
|
+
.split('\n')
|
|
62
|
+
.filter(Boolean);
|
|
63
|
+
for (const gitTag of gitTags) {
|
|
64
|
+
const version = gitTag.includes('@') ? 'v' + gitTag.split('@')[1] : gitTag;
|
|
65
|
+
const tagName = `${IMAGE_PREFIX}:${version}`;
|
|
66
|
+
await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${tagName}`;
|
|
67
|
+
await $`docker push ${JF_REGISTRY_FULL_URL}/${tagName}`;
|
|
44
68
|
}
|
|
45
69
|
|
|
46
|
-
|
|
47
|
-
await $`docker logout ${process.env.JF_REGISTRY_URL}`;
|
|
70
|
+
await logoutRegistry();
|
|
48
71
|
}
|
package/src/next/test.js
ADDED
package/src/next/util.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import path, { join } from 'path';
|
|
3
|
+
import { $ } from 'zx';
|
|
4
|
+
|
|
5
|
+
export function isMonoRepo() {
|
|
6
|
+
// Check for the presence of turbo.json which indicates a Turborepo monorepo
|
|
7
|
+
return existsSync(join(process.cwd(), 'turbo.json'));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Gets the packages that have changed between two git references (branches or tags)
|
|
12
|
+
* @param {string} fromRef - The starting git reference (branch or tag)
|
|
13
|
+
* @param {string} toRef - The ending git reference (branch or tag)
|
|
14
|
+
* @returns {Promise<Array<{name: string, path: string}>>} - Array of changed packages with name and path
|
|
15
|
+
*/
|
|
16
|
+
export async function getChangedPackagesInternal(fromRef, toRef) {
|
|
17
|
+
try {
|
|
18
|
+
console.log(process.cwd());
|
|
19
|
+
// Run the turbo command to get changed packages between branches
|
|
20
|
+
const filterArg = `[${fromRef}...${toRef}]`;
|
|
21
|
+
const turboDryOutput =
|
|
22
|
+
await $`turbo run build --filter=${filterArg} --dry=json`;
|
|
23
|
+
|
|
24
|
+
const dryRunJson = turboDryOutput.stdout.trim();
|
|
25
|
+
|
|
26
|
+
const dryRun = JSON.parse(dryRunJson);
|
|
27
|
+
|
|
28
|
+
const packages = dryRun.tasks.map((task) => ({
|
|
29
|
+
name: task.package,
|
|
30
|
+
directory: task.directory,
|
|
31
|
+
path: path.resolve(process.cwd(), task.directory),
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
return packages;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error('Error getting changed packages:', error);
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function getAllPackages() {
|
|
42
|
+
try {
|
|
43
|
+
const turboDryOutput = await $`turbo run build --dry=json`;
|
|
44
|
+
const dryRunJson = turboDryOutput.stdout.trim();
|
|
45
|
+
const dryRun = JSON.parse(dryRunJson);
|
|
46
|
+
|
|
47
|
+
const packages = dryRun.tasks.map((task) => ({
|
|
48
|
+
name: task.package,
|
|
49
|
+
directory: task.directory,
|
|
50
|
+
path: path.resolve(process.cwd(), task.directory),
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
return packages;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error('Error getting changed packages:', error);
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function getAllAppPackages() {
|
|
61
|
+
const changedPackages = await getAllPackages();
|
|
62
|
+
const appPackages = changedPackages.filter((appPackage) =>
|
|
63
|
+
appPackage.directory.startsWith('apps'),
|
|
64
|
+
);
|
|
65
|
+
return appPackages;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function getChangedPackages() {
|
|
69
|
+
const branch = process.env.BITBUCKET_BRANCH;
|
|
70
|
+
const destBranch = process.env.BITBUCKET_PR_DESTINATION_BRANCH;
|
|
71
|
+
|
|
72
|
+
await $`git fetch origin ${destBranch}:${destBranch}`;
|
|
73
|
+
console.log(`Getting changed packages for [${destBranch}...${branch}]`);
|
|
74
|
+
const changedPackages = await getChangedPackagesInternal(destBranch, branch);
|
|
75
|
+
console.log('Changed Packages:\n', JSON.stringify(changedPackages, null, 2));
|
|
76
|
+
return changedPackages;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function getChangedAppPackages() {
|
|
80
|
+
const changedPackages = await getChangedPackages();
|
|
81
|
+
const appPackages = changedPackages.filter((appPackage) =>
|
|
82
|
+
appPackage.directory.startsWith('apps'),
|
|
83
|
+
);
|
|
84
|
+
return appPackages;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function setGitInfo() {
|
|
88
|
+
if (!process.env.IS_DEV) {
|
|
89
|
+
await $`git config --global user.email "gitops@docupace.com"`;
|
|
90
|
+
await $`git config --global user.name "Gitops"`;
|
|
91
|
+
const repoUrl = `git@bitbucket.org:dp-cloud/${process.env.BITBUCKET_REPO_SLUG}.git`;
|
|
92
|
+
console.log(`Setting new origin: ${repoUrl}`);
|
|
93
|
+
await $`git remote set-url origin ${repoUrl}`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
if (process.env.VAULT_SKIP_VERIFY === 'true') {
|
|
17
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const response = await axios.post(
|
|
21
|
+
vaultApiUrl,
|
|
22
|
+
{
|
|
23
|
+
data: {
|
|
24
|
+
AUTH0_CLIENT_ID: AUTH0_CLIENT_ID,
|
|
25
|
+
AUTH0_CLIENT_SECRET: AUTH0_CLIENT_SECRET,
|
|
26
|
+
SITE_CONFIG_REMOTE_PATH: SITE_CONFIG_REMOTE_PATH,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
headers: {
|
|
31
|
+
'X-Vault-Token': VAULT_TOKEN,
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
console.log('Data added to Vault successfully:', response.data);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error(
|
|
40
|
+
'Error adding data to Vault:',
|
|
41
|
+
error.response?.data || error.message,
|
|
42
|
+
);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
PROJECT=$1
|
|
5
|
+
export ROLE_NAME="${2:-atlassian-bitbucket-pipelines-runner-eks-role}"
|
|
6
|
+
CLUSTER_NAME="${3:-}"
|
|
7
|
+
|
|
8
|
+
if [[ -z "$PROJECT" ]]; then
|
|
9
|
+
echo "Error: Project name is required."
|
|
10
|
+
echo "Usage: $0 <project-name>"
|
|
11
|
+
exit 1
|
|
12
|
+
fi
|
|
13
|
+
|
|
14
|
+
if [ -n "$CLUSTER_NAME" ]; then
|
|
15
|
+
export EKS_CLUSTER_NAME="$CLUSTER_NAME"
|
|
16
|
+
elif [ "$CURRENT_ENVIRONMENT" == "prd" ]; then
|
|
17
|
+
export EKS_CLUSTER_NAME="connect-next-prd-eks-cluster"
|
|
18
|
+
CURRENT_ENVIRONMENT="prod"
|
|
19
|
+
elif [ "$CURRENT_ENVIRONMENT" == "stg" ]; then
|
|
20
|
+
export EKS_CLUSTER_NAME="connect-next-stg-eks-cluster"
|
|
21
|
+
CURRENT_ENVIRONMENT="stage"
|
|
22
|
+
else
|
|
23
|
+
export EKS_CLUSTER_NAME="connect-next-${CURRENT_ENVIRONMENT}-eks-cluster"
|
|
24
|
+
fi
|
|
25
|
+
|
|
26
|
+
echo "Using EKS cluster: $EKS_CLUSTER_NAME"
|
|
27
|
+
echo "Current environment: $CURRENT_ENVIRONMENT"
|
|
28
|
+
|
|
29
|
+
export SESSION_NAME="EKSAdminSession"
|
|
30
|
+
export ROLE_ARN="arn:aws:iam::$(aws sts get-caller-identity | jq -r '.Account'):role/$ROLE_NAME"
|
|
31
|
+
export ASSUME_ROLE_OUTPUT=$(aws sts assume-role --role-arn $ROLE_ARN --role-session-name $SESSION_NAME)
|
|
32
|
+
export AWS_ACCESS_KEY_ID=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.AccessKeyId')
|
|
33
|
+
export AWS_SECRET_ACCESS_KEY=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SecretAccessKey')
|
|
34
|
+
export AWS_SESSION_TOKEN=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SessionToken')
|
|
35
|
+
export TF_IN_AUTOMATION=1
|
|
36
|
+
|
|
37
|
+
aws sts get-caller-identity
|
|
38
|
+
|
|
39
|
+
cd "$BITBUCKET_CLONE_DIR/${PROJECT}"
|
|
40
|
+
|
|
41
|
+
terraform apply -input=false .tfplan
|