@docupace/pipeline 1.0.24 โ†’ 1.0.26-alpha-2

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.
@@ -4,9 +4,10 @@ import yaml from 'js-yaml';
4
4
  import { $ } from 'zx';
5
5
  import lodash from 'lodash';
6
6
  import { appInfo, environmentConfig, getRepUrl } from './config.js';
7
- import { copy2 } from './copy.js';
7
+ import { copy } from './copy.js';
8
8
  import axios from 'axios';
9
- import { deployCore, deployConnect } from './jenkins.js';
9
+ import { runPipeline } from './pipline.js';
10
+ import { deployCore } from './jenkins.js';
10
11
 
11
12
  /**
12
13
  * Clone the repository, read the YAML file, and return the parsed data and file paths.
@@ -21,66 +22,6 @@ function getRepoLocalPath(env) {
21
22
  return { repoPath, repoName };
22
23
  }
23
24
 
24
- async function updateAndCommitConnectVersion(
25
- toEnv,
26
- toSite,
27
- getComparedVersion,
28
- connectDeployPath,
29
- ) {
30
- const filePath = path.join(
31
- connectDeployPath,
32
- 'envs',
33
- toEnv,
34
- toSite,
35
- 'dock.sh',
36
- );
37
-
38
- try {
39
- let content = fs.readFileSync(filePath, 'utf8');
40
- content = content.replace(
41
- /IMAGE_VERSION=.*/,
42
- `IMAGE_VERSION=git-commit-${getComparedVersion}`,
43
- );
44
- fs.writeFileSync(filePath, content, 'utf8');
45
-
46
- // Git commands to stage, commit and push changes
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.');
55
- } catch (error) {
56
- console.error('Error updating Connect version:', error);
57
- throw error;
58
- }
59
- }
60
-
61
- async function compareGetConnectSiteVersions(fromEnv, fromSite, toEnv, toSite) {
62
- try {
63
- const fromResponse = await axios.get(
64
- `https://${fromSite}.${fromEnv}.dpai.tech/connect/loginFooter`,
65
- );
66
- const toResponse = await axios.get(
67
- `https://${toSite}.${toEnv}.dpai.tech/connect/loginFooter`,
68
- );
69
-
70
- const fromMatch = fromResponse.data.match(/UI Build: ([a-f0-9]*)/);
71
- const toMatch = toResponse.data.match(/UI Build: ([a-f0-9]*)/);
72
-
73
- if (fromMatch && fromMatch[1] && toMatch && toMatch[1]) {
74
- if (fromMatch[1] !== toMatch[1]) {
75
- return fromMatch[1];
76
- }
77
- }
78
- return false;
79
- } catch (error) {
80
- console.error('Error fetching Connect versions:', error);
81
- throw error;
82
- }
83
- }
84
25
  function getRepoLocalPathByRepoSlug(repoSlug) {
85
26
  const repoName = `${repoSlug}`;
86
27
  const repoPath = path.join(process.cwd(), repoName);
@@ -93,7 +34,7 @@ function cleanUpRepoPath(repoPath) {
93
34
  console.log(`${repoPath} directory exists. Removing it...`);
94
35
  fs.rmSync(repoPath, {
95
36
  recursive: true,
96
- force: true,
37
+ force: true
97
38
  });
98
39
  }
99
40
  }
@@ -112,7 +53,7 @@ export async function cloneRepository(repoSlug) {
112
53
  const { repoPath, repoName } = getRepoLocalPathByRepoSlug(repoSlug);
113
54
  const repoUrl = getRepUrl(repoName);
114
55
 
115
- await cleanUpRepoPath(repoPath);
56
+ await cleanUpRepoPath(repoPath)
116
57
 
117
58
  console.log(`Cloning repository: ${repoName}`);
118
59
  await $`git clone --depth 1 ${repoUrl}`;
@@ -130,23 +71,6 @@ function getConfigPath(application, env, site, name) {
130
71
  return { repoPath, deployConfigFilePath };
131
72
  }
132
73
 
133
- function getAppTypesFromRepo(env, site) {
134
- const { repoPath } = getRepoLocalPath(env);
135
- const deployConfigFilePath = path.join(repoPath, `dp/${site}`);
136
- const applications = [];
137
- if (fs.existsSync(deployConfigFilePath)) {
138
- const files = fs.readdirSync(deployConfigFilePath);
139
- files.forEach((file) => {
140
- if (file.includes('.values.yaml')) {
141
- const appName = file.split('.')[0];
142
- applications.push(appName);
143
- }
144
- });
145
- }
146
-
147
- return { applications };
148
- }
149
-
150
74
  export async function readDeployConfig(application, env, site, name) {
151
75
  const { deployConfigFilePath } = getConfigPath(application, env, site, name);
152
76
 
@@ -342,72 +266,12 @@ async function getCoreBranchName(fromEnv, fromSite) {
342
266
  return branchName;
343
267
  }
344
268
 
345
- export async function deployApp(
346
- application,
347
- appDetails,
348
- fromEnv,
349
- fromSite,
350
- toEnv,
351
- toSite,
352
- ) {
353
- let changesMade = false;
354
- console.log(`Processing application: ${application}`);
355
-
356
- // Read the deployment configuration for the source environment and site
357
- const { deployConfig: fromDeployConfig } = await readDeployConfig(
358
- application,
359
- fromEnv,
360
- fromSite,
361
- 'values',
362
- );
363
-
364
- if (fromEnv !== toEnv) {
365
- await copy2(
366
- appDetails.repositoryName,
367
- fromEnv,
368
- toEnv,
369
- fromDeployConfig.image.tag,
370
- );
371
- }
372
-
373
- // Read the deployment configuration for the target environment and site
374
- const {
375
- deployConfig: toDeployConfig,
376
- deployConfigFilePath: toDeployConfigFilePath,
377
- } = await readDeployConfig(application, toEnv, toSite, 'values');
378
-
379
- // Update target configuration using attributes specified in appInfo
380
- for (const attribute of appDetails.deployAttributes) {
381
- const sourceValue = lodash.get(fromDeployConfig, attribute);
382
-
383
- if (sourceValue !== undefined) {
384
- // Update the target configuration with the source value
385
- lodash.set(toDeployConfig, attribute, sourceValue);
386
- changesMade = true;
387
- }
388
- }
389
-
390
- const {
391
- deployConfig: toDeployAppConfig,
392
- deployConfigFilePath: toDeployAppConfigFilePath,
393
- } = await readDeployConfig(application, toEnv, toSite, 'app');
394
-
395
- toDeployAppConfig.revision = fromDeployConfig.image.tag;
396
-
397
- // Write updated configuration to the target YAML file
398
- writeDeployConfig(toDeployConfigFilePath, toDeployConfig);
399
-
400
- writeDeployConfig(toDeployAppConfigFilePath, toDeployAppConfig);
401
- return changesMade;
402
- }
403
-
404
269
  export async function deployFromSite(
405
270
  fromEnv,
406
271
  fromSite,
407
272
  toEnv,
408
273
  toSite,
409
274
  isDeployCore,
410
- isDeployConnect,
411
275
  ) {
412
276
  if (isDeployCore === 'true') {
413
277
  const branchName = await getCoreBranchName(fromEnv, fromSite);
@@ -424,30 +288,6 @@ export async function deployFromSite(
424
288
  });*/
425
289
  }
426
290
 
427
- if (isDeployConnect === 'true') {
428
- const branch = '';
429
- const getComparedVersion = await compareGetConnectSiteVersions(
430
- fromEnv,
431
- fromSite,
432
- toEnv,
433
- toSite,
434
- );
435
- if (getComparedVersion) {
436
- console.log('Version to deploy is: ', getComparedVersion);
437
- const connectDeployPath = await cloneRepository('connect-deploy');
438
- // update target version set to git-commit-${getCommparedVersion}}
439
- await updateAndCommitConnectVersion(
440
- toEnv,
441
- toSite,
442
- getComparedVersion,
443
- connectDeployPath,
444
- );
445
- // save and deploy
446
- const runLiquibase = true;
447
- await deployConnect(toEnv, toSite, runLiquibase, branch);
448
- }
449
- }
450
-
451
291
  // Clone repositories for source and target environments
452
292
  const fromRepoPath = await cloneEnvRepository(fromEnv);
453
293
  const toRepoPath =
@@ -455,53 +295,52 @@ export async function deployFromSite(
455
295
 
456
296
  // Initialize a flag to track changes
457
297
  let changesMade = false;
458
- const applications = await getAppTypesFromRepo(toEnv, toSite);
459
- console.log(applications);
460
- // Iterate over applications in appInfo
461
298
 
462
- let appInfoLocal = Object.fromEntries(
463
- applications.applications
464
- .filter((application) =>
465
- Object.prototype.hasOwnProperty.call(appInfo, application),
466
- )
467
- .map((application) => [application, appInfo[application]]),
468
- );
469
-
470
- // let appInfoLocal = {};
471
- // for (const application of applications.applications) {
472
- // if (Object.prototype.hasOwnProperty.call(appInfo, application)) {
473
- // appInfoLocal[application] = appInfo[application];
474
- // }
475
- // }
299
+ // Iterate over applications in appInfo
300
+ for (const [application, appDetails] of Object.entries(appInfo)) {
301
+ console.log(`Processing application: ${application}`);
476
302
 
477
- if (Object.keys(appInfoLocal).length === 0) {
478
- const { deployConfig: toDeployAppConfig } = await readDeployConfig(
303
+ // Read the deployment configuration for the source environment and site
304
+ const { deployConfig: fromDeployConfig } = await readDeployConfig(
305
+ application,
306
+ fromEnv,
479
307
  fromSite,
480
- toEnv,
481
- toSite,
482
- 'app',
308
+ 'values',
483
309
  );
484
310
 
485
- appInfoLocal[fromSite] = {
486
- repositoryName: toDeployAppConfig.repo,
487
- deployAttributes: ['image.tag'],
488
- };
489
- }
311
+ if (fromEnv !== toEnv) {
312
+ await copy(application, fromEnv, toEnv, fromDeployConfig.image.tag);
313
+ }
490
314
 
491
- console.log('appinfoLocal', appInfoLocal);
315
+ // Read the deployment configuration for the target environment and site
316
+ const {
317
+ deployConfig: toDeployConfig,
318
+ deployConfigFilePath: toDeployConfigFilePath,
319
+ } = await readDeployConfig(application, toEnv, toSite, 'values');
492
320
 
493
- for (const [application, appDetails] of Object.entries(appInfoLocal)) {
494
- let cm = await deployApp(
495
- application,
496
- appDetails,
497
- fromEnv,
498
- fromSite,
499
- toEnv,
500
- toSite,
501
- );
502
- if (cm) {
503
- changesMade = true;
321
+ // Update target configuration using attributes specified in appInfo
322
+ for (const attribute of appDetails.deployAttributes) {
323
+ const sourceValue = lodash.get(fromDeployConfig, attribute);
324
+
325
+ if (sourceValue !== undefined) {
326
+ // Update the target configuration with the source value
327
+ lodash.set(toDeployConfig, attribute, sourceValue);
328
+ changesMade = true;
329
+ }
504
330
  }
331
+
332
+ const {
333
+ deployConfig: toDeployAppConfig,
334
+ deployConfigFilePath: toDeployAppConfigFilePath,
335
+ } = await readDeployConfig(application, toEnv, toSite, 'app');
336
+
337
+ toDeployAppConfig.revision = fromDeployConfig.image.tag;
338
+
339
+ // Write updated configuration to the target YAML file
340
+ writeDeployConfig(toDeployConfigFilePath, toDeployConfig);
341
+
342
+ writeDeployConfig(toDeployAppConfigFilePath, toDeployAppConfig);
343
+
505
344
  }
506
345
 
507
346
  // Push all changes if any updates were made
@@ -26,7 +26,6 @@ export async function deployCore(env, site, liquibase, gitBranch) {
26
26
  });
27
27
  }
28
28
 
29
- // eslint-disable-next-line no-unused-vars
30
29
  export async function deployConnect(env, site, liquibase, branch) {
31
30
  const parameters = {
32
31
  BUILD_ENVIRONMENT: env,
@@ -99,6 +99,7 @@ export async function runPipeline(
99
99
  return;
100
100
  }
101
101
 
102
+
102
103
  let status = '';
103
104
  do {
104
105
  console.log('Checking pipeline status...');
@@ -1,48 +1,48 @@
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 '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
+ }
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
+ }
package/src/next/vault.js CHANGED
@@ -1,43 +1,43 @@
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
- }
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
+ }
@@ -1,26 +1,26 @@
1
- #!/usr/bin/env bash
2
- set -e
3
-
4
- PROJECT=$1
5
-
6
- if [[ -z "$PROJECT" ]]; then
7
- echo "Error: Project name is required."
8
- echo "Usage: $0 <project-name>"
9
- exit 1
10
- fi
11
-
12
- export ROLE_NAME="atlassian-bitbucket-pipelines-runner-eks-role"
13
- export SESSION_NAME="EKSAdminSession"
14
- export EKS_CLUSTER_NAME="connect-next-${CURRENT_ENVIRONMENT}-eks-cluster"
15
- export ROLE_ARN="arn:aws:iam::$(aws sts get-caller-identity | jq -r '.Account'):role/$ROLE_NAME"
16
- export ASSUME_ROLE_OUTPUT=$(aws sts assume-role --role-arn $ROLE_ARN --role-session-name $SESSION_NAME)
17
- export AWS_ACCESS_KEY_ID=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.AccessKeyId')
18
- export AWS_SECRET_ACCESS_KEY=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SecretAccessKey')
19
- export AWS_SESSION_TOKEN=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SessionToken')
20
- export TF_IN_AUTOMATION=1
21
-
22
- aws sts get-caller-identity
23
-
24
- cd "$BITBUCKET_CLONE_DIR/${PROJECT}"
25
-
26
- terraform apply -input=false .tfplan
1
+ #!/usr/bin/env bash
2
+ set -e
3
+
4
+ PROJECT=$1
5
+
6
+ if [[ -z "$PROJECT" ]]; then
7
+ echo "Error: Project name is required."
8
+ echo "Usage: $0 <project-name>"
9
+ exit 1
10
+ fi
11
+
12
+ export ROLE_NAME="atlassian-bitbucket-pipelines-runner-eks-role"
13
+ export SESSION_NAME="EKSAdminSession"
14
+ export EKS_CLUSTER_NAME="connect-next-${CURRENT_ENVIRONMENT}-eks-cluster"
15
+ export ROLE_ARN="arn:aws:iam::$(aws sts get-caller-identity | jq -r '.Account'):role/$ROLE_NAME"
16
+ export ASSUME_ROLE_OUTPUT=$(aws sts assume-role --role-arn $ROLE_ARN --role-session-name $SESSION_NAME)
17
+ export AWS_ACCESS_KEY_ID=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.AccessKeyId')
18
+ export AWS_SECRET_ACCESS_KEY=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SecretAccessKey')
19
+ export AWS_SESSION_TOKEN=$(echo $ASSUME_ROLE_OUTPUT | jq -r '.Credentials.SessionToken')
20
+ export TF_IN_AUTOMATION=1
21
+
22
+ aws sts get-caller-identity
23
+
24
+ cd "$BITBUCKET_CLONE_DIR/${PROJECT}"
25
+
26
+ terraform apply -input=false .tfplan