@docupace/pipeline 1.0.6 → 1.0.7-7.micro-cli

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.
Files changed (68) hide show
  1. package/.prettierrc.cjs +12 -12
  2. package/README.md +136 -0
  3. package/bin/azuread_update_callbacks_for_app.sh +58 -0
  4. package/bin/next-changeset-validate.sh +8 -8
  5. package/bitbucket-pipelines.yml +60 -0
  6. package/eslint.config.js +49 -26
  7. package/jest.config.js +15 -0
  8. package/next/changeset.sh +75 -75
  9. package/next/copy.sh +34 -34
  10. package/next/deploy.sh +40 -40
  11. package/next/execute.sh +123 -117
  12. package/next/sonar.sh +23 -23
  13. package/package.json +22 -7
  14. package/src/auth0/alias.js +79 -0
  15. package/src/auth0/alias.test.js +172 -0
  16. package/src/auth0/cli.js +82 -0
  17. package/src/auth0/configure.js +902 -0
  18. package/src/auth0/configure.test.js +167 -0
  19. package/src/auth0/export.js +48 -0
  20. package/src/auth0/export.test.js +103 -0
  21. package/src/auth0/metadata.js +141 -0
  22. package/src/auth0/metadata.test.js +186 -0
  23. package/src/auth0/vault.js +60 -0
  24. package/src/auth0/vault.test.js +134 -0
  25. package/src/changeset/changelog-wiki.js +328 -0
  26. package/src/changeset/changeset-config.js +34 -0
  27. package/src/changeset/cli.js +237 -281
  28. package/src/changeset/create.js +215 -0
  29. package/src/changeset/package-util.js +87 -0
  30. package/src/changeset/util.js +43 -0
  31. package/src/changeset/validate.js +91 -47
  32. package/src/changeset/version.js +102 -0
  33. package/src/jenkins/setParams.groovy +58 -59
  34. package/src/lib/merge-driver.js +204 -0
  35. package/src/merge/cli-merge-all.js +507 -0
  36. package/src/merge/cli-merge.js +492 -0
  37. package/src/merge/cli-resolve.js +399 -0
  38. package/src/merge/cli.js +38 -0
  39. package/src/merge/merge-changelog.js +87 -0
  40. package/src/merge/merge-package.js +106 -0
  41. package/src/merge/merge-types.js +82 -0
  42. package/src/merge/pr.js +231 -0
  43. package/src/micro/cli.js +71 -0
  44. package/src/micro/ms-deploy.js +273 -0
  45. package/src/micro/ms-publish.js +186 -0
  46. package/src/next/alias.js +53 -0
  47. package/src/next/apache.js +81 -0
  48. package/src/next/cli.js +111 -15
  49. package/src/next/config.js +137 -72
  50. package/src/next/connect.js +226 -0
  51. package/src/next/copy.js +61 -30
  52. package/src/next/deploy.js +633 -312
  53. package/src/next/git-to-semver.js +79 -0
  54. package/src/next/haproxy.js +76 -0
  55. package/src/next/jenkins.js +123 -88
  56. package/src/next/jira.js +84 -0
  57. package/src/next/logger.js +17 -0
  58. package/src/next/pipline.js +114 -115
  59. package/src/next/publish.js +71 -48
  60. package/src/next/pull.js +7 -7
  61. package/src/next/sonar.js +23 -23
  62. package/src/next/test.js +5 -0
  63. package/src/next/util.js +93 -0
  64. package/src/next/vault.js +45 -0
  65. package/terraform/apply.sh +37 -0
  66. package/terraform/init.sh +72 -0
  67. package/terraform/plan.sh +76 -0
  68. package/terraform/validate.sh +17 -0
@@ -1,115 +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
-
103
- let status = '';
104
- do {
105
- console.log('Checking pipeline status...');
106
- await new Promise((resolve) => setTimeout(resolve, 10000)); // Wait 10 seconds
107
- status = await getPipelineStatus(repository, pipelineUUID);
108
- console.log(`Pipeline status: ${status}`);
109
- } while (['IN_PROGRESS', 'PENDING', 'RUNNING'].includes(status));
110
-
111
- console.log(`Pipeline completed with status: ${status}`);
112
- } catch (error) {
113
- console.error('Error monitoring pipeline:', error.message);
114
- }
115
- }
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,48 +1,71 @@
1
- import { $ } from 'zx';
2
-
3
- export async function publish(GIT_SHA) {
4
- const BITBUCKET_REPO_SLUG = process.env.BITBUCKET_REPO_SLUG;
5
- const BUILD_IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:build-${process.env.BITBUCKET_BUILD_NUMBER}`;
6
- const IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}`;
7
- const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
8
-
9
- console.log(`Publishing Docker image: ${IMAGE_NAME}`);
10
-
11
- // Docker login
12
- await $`echo ${process.env.JF_REGISTRY_PASSWORD_DEV} | docker login --username ${process.env.JF_REGISTRY_USER_DEV} --password-stdin ${process.env.JF_REGISTRY_URL}`;
13
-
14
- // Check if the image already exists
15
- try {
16
- await $`docker manifest inspect ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
17
- console.log(
18
- `Tag sha-${GIT_SHA} already exists in the remote repository. Skipping push.`,
19
- );
20
- } catch {
21
- await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
22
- await $`docker push ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
23
- }
24
-
25
- // Tag and push build image
26
- await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
27
- await $`docker push ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
28
-
29
- // Fetch Git tags pointing to the current HEAD
30
- const gitTagsOutput = (await $`git tag --points-at HEAD`).stdout.trim();
31
- const gitTags = gitTagsOutput.split('\n').filter((tag) => tag);
32
-
33
- // Tag and push each Git tag as a Docker tag
34
- if (gitTags.length > 0) {
35
- console.log(`Found Git tags pointing to HEAD: ${gitTags.join(', ')}`);
36
- for (const gitTag of gitTags) {
37
- const dockerTag = `${JF_REGISTRY_FULL_URL}/${BITBUCKET_REPO_SLUG}:${gitTag}`;
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.');
44
- }
45
-
46
- // Docker logout
47
- await $`docker logout ${process.env.JF_REGISTRY_URL}`;
48
- }
1
+ import { $ } from './logger.js';
2
+
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;
12
+
13
+ const JF_REGISTRY_FULL_URL = `${JF_REGISTRY_URL}/${JF_REGISTRY_REPO_NAME}`;
14
+
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}...`);
33
+
34
+ await loginRegistry();
35
+
36
+ let manifestExists = false;
37
+ try {
38
+ $.verbose = false; // Silence output temporarily
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) {
48
+ console.log(
49
+ `Tag sha-${gitSha} already exists in the remote repository. Skipping push.`,
50
+ );
51
+ } else {
52
+ await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
53
+ await $`docker push ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
54
+ }
55
+
56
+ await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
57
+ await $`docker push ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
58
+
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}`;
68
+ }
69
+
70
+ await logoutRegistry();
71
+ }
package/src/next/pull.js CHANGED
@@ -1,7 +1,7 @@
1
- import { $ } from 'zx';
2
-
3
- export async function pull(imageName) {
4
- const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
5
- console.log(`Pulling Docker image: ${JF_REGISTRY_FULL_URL}/${imageName}`);
6
- await $`docker pull ${JF_REGISTRY_FULL_URL}/${imageName}`;
7
- }
1
+ import { $ } from 'zx';
2
+
3
+ export async function pull(imageName) {
4
+ const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
5
+ console.log(`Pulling Docker image: ${JF_REGISTRY_FULL_URL}/${imageName}`);
6
+ await $`docker pull ${JF_REGISTRY_FULL_URL}/${imageName}`;
7
+ }
package/src/next/sonar.js CHANGED
@@ -1,23 +1,23 @@
1
- import { $ } from 'zx';
2
-
3
- export async function sonar(GIT_SHA) {
4
- const IMAGE_NAME = `${process.env.BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}`;
5
- const SONAR_CONTAINER_NAME = `${process.env.BITBUCKET_REPO_SLUG}-${GIT_SHA}`;
6
-
7
- console.log(`Running Sonar analysis on Docker image: ${IMAGE_NAME}`);
8
-
9
- // Remove existing container
10
- const existingContainer = (
11
- await $`docker ps -a --filter "name=${SONAR_CONTAINER_NAME}" --format "{{.Names}}"`
12
- ).stdout.trim();
13
- if (existingContainer) {
14
- await $`docker rm -f ${SONAR_CONTAINER_NAME}`;
15
- }
16
-
17
- await $`docker run --rm \
18
- -e BRANCH=${process.env.BITBUCKET_BRANCH} \
19
- -e PR_ID=${process.env.BITBUCKET_PR_ID} \
20
- -e PR_DESTINATION_BRANCH=${process.env.BITBUCKET_PR_DESTINATION_BRANCH} \
21
- -e SONAR_TOKEN=${process.env.SONAR_TOKEN} \
22
- --name ${SONAR_CONTAINER_NAME} ${IMAGE_NAME} pnpm sonar`;
23
- }
1
+ import { $ } from 'zx';
2
+
3
+ export async function sonar(GIT_SHA) {
4
+ const IMAGE_NAME = `${process.env.BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}`;
5
+ const SONAR_CONTAINER_NAME = `${process.env.BITBUCKET_REPO_SLUG}-${GIT_SHA}`;
6
+
7
+ console.log(`Running Sonar analysis on Docker image: ${IMAGE_NAME}`);
8
+
9
+ // Remove existing container
10
+ const existingContainer = (
11
+ await $`docker ps -a --filter "name=${SONAR_CONTAINER_NAME}" --format "{{.Names}}"`
12
+ ).stdout.trim();
13
+ if (existingContainer) {
14
+ await $`docker rm -f ${SONAR_CONTAINER_NAME}`;
15
+ }
16
+
17
+ await $`docker run --rm \
18
+ -e BRANCH=${process.env.BITBUCKET_BRANCH} \
19
+ -e PR_ID=${process.env.BITBUCKET_PR_ID} \
20
+ -e PR_DESTINATION_BRANCH=${process.env.BITBUCKET_PR_DESTINATION_BRANCH} \
21
+ -e SONAR_TOKEN=${process.env.SONAR_TOKEN} \
22
+ --name ${SONAR_CONTAINER_NAME} ${IMAGE_NAME} pnpm sonar`;
23
+ }
@@ -0,0 +1,5 @@
1
+ import { getBranchNameFromVersion } from './deploy.js';
2
+
3
+ getBranchNameFromVersion('25.2.0-alpha.18-3-g4e0e088aa0');
4
+ getBranchNameFromVersion('25.1.13-0-g7798cf7138');
5
+ getBranchNameFromVersion('25.1.13-3-g7798cf7138');
@@ -0,0 +1,93 @@
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
+ await $`git remote set-url origin https://${process.env.THIS_REP_TOKEN}@bitbucket.org/${process.env.BITBUCKET_REPO_FULL_NAME}.git`;
92
+ }
93
+ }
@@ -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,37 @@
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
@@ -0,0 +1,72 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ PROJECT=$1
5
+ CURRENT_ENVIRONMENT=$2
6
+ export ROLE_NAME="${3:-atlassian-bitbucket-pipelines-runner-eks-role}"
7
+
8
+ if [[ -z "$PROJECT" ]]; then
9
+ echo "Error: Project name is required."
10
+ echo "Usage: $0 <project-name> $1 <environment>"
11
+ exit 1
12
+ fi
13
+
14
+ if [[ -z "$CURRENT_ENVIRONMENT" ]]; then
15
+ echo "Error: ENVIRONMENT is required."
16
+ echo "Usage: $0 <project-name> $1 <environment>"
17
+ exit 1
18
+ fi
19
+
20
+ if [ "$CURRENT_ENVIRONMENT" == "prd" ]; then
21
+ export EKS_CLUSTER_NAME="connect-next-prd-eks-cluster"
22
+ CURRENT_ENVIRONMENT="prod"
23
+ elif [ "$CURRENT_ENVIRONMENT" == "stg" ]; then
24
+ export EKS_CLUSTER_NAME="connect-next-stg-eks-cluster"
25
+ CURRENT_ENVIRONMENT="stage"
26
+ else
27
+ export EKS_CLUSTER_NAME="connect-next-${CURRENT_ENVIRONMENT}-eks-cluster"
28
+ fi
29
+
30
+ echo "Using EKS cluster: $EKS_CLUSTER_NAME"
31
+
32
+ export SESSION_NAME="EKSAdminSession"
33
+ export ROLE_ARN="arn:aws:iam::$(aws sts get-caller-identity | jq -r '.Account'):role/$ROLE_NAME"
34
+ export ASSUME_ROLE_OUTPUT=$(aws sts assume-role --role-arn $ROLE_ARN --role-session-name $SESSION_NAME)
35
+ export AWS_ACCESS_KEY_ID=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.AccessKeyId')
36
+ export AWS_SECRET_ACCESS_KEY=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SecretAccessKey')
37
+ export AWS_SESSION_TOKEN=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SessionToken')
38
+
39
+ aws sts get-caller-identity
40
+ cd "$BITBUCKET_CLONE_DIR/${PROJECT}"
41
+ mkdir -p ~/.ssh
42
+
43
+ echo "$atlassian_workspace_runner_ssh_key" | base64 -d > ~/.ssh/id_ed25519
44
+ chmod 600 ~/.ssh/id_ed25519
45
+ ssh-keyscan bitbucket.org > ~/.ssh/known_hosts
46
+
47
+ info () {
48
+ echo "PROJECT => $PROJECT"
49
+ echo "CURRENT_ENVIRONMENT => $CURRENT_ENVIRONMENT"
50
+ echo "SITE_NAME => $SITE_NAME"
51
+ echo "Using AWS Role: $ROLE_NAME"
52
+ }
53
+
54
+ if [[ "$PROJECT" == "s3" ]]; then
55
+ info
56
+ terraform init \
57
+ -input=false \
58
+ -reconfigure \
59
+ -backend=true \
60
+ -backend-config=./env/${CURRENT_ENVIRONMENT}/us-west-2/backend.tfvars \
61
+ -backend-config="key=us-west-2/${PROJECT}/${SITE_NAME}/${CURRENT_ENVIRONMENT}/terraform.tfstate"
62
+ elif [[ "$PROJECT" == "idp" ]]; then
63
+ info
64
+ terraform init \
65
+ -input=false \
66
+ -reconfigure \
67
+ -backend=true \
68
+ -backend-config=./env/${CURRENT_ENVIRONMENT}/us-west-2/backend.tfvars \
69
+ -backend-config="key=us-west-2/${PROJECT}/${SITE_NAME}/${CURRENT_ENVIRONMENT}/terraform.tfstate"
70
+ else
71
+ terraform init -backend-config=./env/${CURRENT_ENVIRONMENT}/us-west-2/backend.tfvars --reconfigure
72
+ fi