@docupace/pipeline 1.0.7-alpha.8 → 1.0.7-alpha.ervins1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.7-alpha.8",
3
+ "version": "1.0.7-alpha.ervins1.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  "lodash": "^4.17.21",
25
25
  "openai": "^4.76.3",
26
26
  "zod": "^3.24.1",
27
- "zx": "^8.2.4"
27
+ "zx": "^8.3.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@eslint/js": "^9.17.0",
package/src/auth0/cli.js CHANGED
@@ -15,10 +15,10 @@ dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
15
15
  const program = new Command();
16
16
 
17
17
  program
18
- .command('configureFromSite <fromSite> <toSite> <env> <deployUI> <deployGraphQLServer> <deployClientCredentials> <useNewDomain>')
18
+ .command('configureFromSite <fromSite> <toSite> <env> <deployUI> <deployGraphQLServer> <useNewDomain>')
19
19
  .description('Configure the Auth0 tenants in env for the given site')
20
- .action(async (fromSite, toSite, env, deployUI, deployGraphQLServer, deployClientCredentials, useNewDomain) => {
21
- await configureFromSite(fromSite, toSite, env, deployUI, deployGraphQLServer, deployClientCredentials, useNewDomain);
20
+ .action(async (fromSite, toSite, env, deployUI, deployGraphQLServer, useNewDomain) => {
21
+ await configureFromSite(fromSite, toSite, env, deployUI, deployGraphQLServer, useNewDomain);
22
22
  });
23
23
 
24
24
  program
@@ -32,6 +32,38 @@ async function ensureDirectoryExists(dirPath) {
32
32
  }
33
33
  }
34
34
 
35
+ async function addApplicationToApi ({application, auth0Domain, auth0AuthToken, coreApiIdentifier}){
36
+ console.log("Adding application to API authorized applications...");
37
+
38
+ try {
39
+ const auth0Response = await axios.get(`https://${auth0Domain}/api/v2/clients`, {
40
+ headers: {authorization: `Bearer ${auth0AuthToken}`},
41
+ });
42
+
43
+ const appAuth0ClientIdData = auth0Response.data.find(client => client.name === `${application}`);
44
+ const appAuth0ClientId = appAuth0ClientIdData.client_id;
45
+
46
+ await axios.post(
47
+ `https://${auth0Domain}/api/v2/client-grants`,
48
+ {
49
+ client_id: appAuth0ClientId,
50
+ audience: `${coreApiIdentifier}`,
51
+ scope: [],
52
+ },
53
+ {
54
+ headers: {
55
+ Authorization: `Bearer ${auth0AuthToken}`,
56
+ "Content-Type": "application/json",
57
+ },
58
+ }
59
+ );
60
+ console.log(`Application (${appAuth0ClientId}) authorized for API: ${coreApiIdentifier}`);
61
+ } catch (err) {
62
+ console.error(`Failed to add application: ${application}: ${err.message}`);
63
+ }
64
+
65
+ }
66
+
35
67
  async function initializeAuth0Configuration({
36
68
  initConfiguration,
37
69
  auth0Domain,
@@ -42,7 +74,6 @@ async function initializeAuth0Configuration({
42
74
  try {
43
75
  // Create a new resource server in Auth0
44
76
  console.log("Creating resource server in Auth0...");
45
- console.log(`Secret => ${coreApiIdentifier}`);
46
77
 
47
78
  const resourceServerResponse = await axios.post(
48
79
  `https://${auth0Domain}/api/v2/resource-servers`,
@@ -64,7 +95,6 @@ async function initializeAuth0Configuration({
64
95
  );
65
96
 
66
97
  const apiId = resourceServerResponse.data.id;
67
- console.log(`API ID: ${apiId}`);
68
98
 
69
99
  // Update tenant settings with the default audience
70
100
  console.log("Updating tenant settings...");
@@ -80,7 +110,6 @@ async function initializeAuth0Configuration({
80
110
  },
81
111
  }
82
112
  );
83
- console.log(`coreApiIdentifier => ${coreApiIdentifier}`)
84
113
  console.log("Tenant settings updated successfully.");
85
114
  } catch (error) {
86
115
  console.error("Error during Auth0 configuration:", error.response?.data || error.message);
@@ -124,7 +153,7 @@ async function replaceInFile(filePath, replacements) {
124
153
  await fs.promises.writeFile(filePath, content);
125
154
  }
126
155
 
127
- async function templateAuth0(siteUrl, coreApiContext, env, filePaths, deployUI, deployGraphQLServer, deployClientCredentials, commonSecrets) {
156
+ async function templateAuth0(siteUrl, coreApiContext, env, filePaths, deployUI, deployGraphQLServer, commonSecrets) {
128
157
  try {
129
158
  let uiAllowedCallbacksUrls,
130
159
  uiAllowedLogoutUrls;
@@ -373,7 +402,7 @@ externalConnectService:
373
402
  }
374
403
  }
375
404
 
376
- async function configureGraphQLServer(siteHost, coreURL, docupaceHost, site, env, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, vaultSiteSecretsPath, imageTag, shortTemplateLatestCommitId, repoPath, commonSecrets) {
405
+ async function configureGraphQLServer(siteHost, coreURL, docupaceHost, site, env, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, vaultSiteSecretsPath, imageTag, standardConfigRemoteBranch, repoPath, commonSecrets) {
377
406
  console.log(`Configuring GraphQL Server for site: ${site} Host: ${siteHost} in env: ${env}`);
378
407
 
379
408
  try {
@@ -382,15 +411,22 @@ async function configureGraphQLServer(siteHost, coreURL, docupaceHost, site, env
382
411
  });
383
412
 
384
413
  const graphQLServerClient = auth0Response.data.find(client => client.name === "docupace-graphql");
414
+ const graphQLServerClientCredentials = auth0Response.data.find(client => client.name === "docupace-graphql-client-credentials");
415
+
385
416
  const graphQLServerAuth0ClientId = graphQLServerClient.client_id;
386
417
  const graphQLServerAuth0ClientSecret = graphQLServerClient.client_secret;
387
418
 
419
+ const graphQLServerCCAuth0ClientId = graphQLServerClientCredentials.client_id;
420
+ const graphQLServerCCAuth0ClientSecret = graphQLServerClientCredentials.client_secret;
421
+
388
422
  // Prepare data payload
389
423
  console.log("Preparing Vault GraphQL Server data payload...");
390
424
  const graphQLServerSecretData = JSON.stringify({
391
425
  data: {
392
426
  AUTH0_CLIENT_ID: graphQLServerAuth0ClientId,
393
427
  AUTH0_CLIENT_SECRET: graphQLServerAuth0ClientSecret,
428
+ AUTH0_CC_CLIENT_ID: graphQLServerCCAuth0ClientId,
429
+ AUTH0_CC_CLIENT_SECRET: graphQLServerCCAuth0ClientSecret,
394
430
  CORE_PASSWORD: commonSecrets.CORE_PASSWORD,
395
431
  REMOTE_CONFIG_PATH: commonSecrets.REMOTE_CONFIG_PATH,
396
432
  STANDARD_CONFIG_REMOTE_PATH: commonSecrets.STANDARD_CONFIG_REMOTE_PATH,
@@ -402,7 +438,7 @@ async function configureGraphQLServer(siteHost, coreURL, docupaceHost, site, env
402
438
  // Prepare ui.app.yaml
403
439
  const graphQLServerAppYaml = `
404
440
  repo: docupace-graphql-server
405
- revision: master
441
+ revision: ${standardConfigRemoteBranch}
406
442
  `.trim();
407
443
 
408
444
  // Prepare ui.values.yaml
@@ -414,13 +450,13 @@ graphqlServer:
414
450
  baseUrl: https://${siteHost}/api/graphql
415
451
  coreUrl: https://${coreURL}
416
452
  integrationHubUrl: "https://${commonSecrets.INTEGRATION_HUB_URL}"
417
- standardConfigRemoteBranch: ${shortTemplateLatestCommitId}
453
+ standardConfigRemoteBranch: ${standardConfigRemoteBranch}
418
454
  apiLevel: "2"
419
455
  env:
420
456
  AUTH0_CLIENT_SECRET: vault:secret/data/${site}/graphql-server/config#AUTH0_CLIENT_SECRET
421
- CORE_PASSWORD: vault:secret/data/common/config#CORE_PASSWORD
422
- REMOTE_CONFIG_PATH: vault:secret/data/common/config#REMOTE_CONFIG_PATH
423
457
  STANDARD_CONFIG_REMOTE_PATH: vault:secret/data/common/config#STANDARD_CONFIG_REMOTE_PATH
458
+ AUTH0_CC_CLIENT_ID: vault:secret/data/${site}/graphql-server/config#AUTH0_CC_CLIENT_ID
459
+ AUTH0_CC_CLIENT_SECRET: vault:secret/data/${site}/graphql-server/config#AUTH0_CC_CLIENT_SECRET
424
460
  image:
425
461
  repository: registry.paperout.com/docupace-graphql-server-dev-docker-local/docupace-graphql-server
426
462
  tag: ${imageTag}
@@ -506,6 +542,7 @@ export async function configureFromSite(fromSite, toSite, env, deployUI, deployG
506
542
 
507
543
  const { deployConfig: deployGraphQLServerConfig} = await readDeployConfig('graphql-server', env, fromSite);
508
544
  const graphqlImageTag = deployGraphQLServerConfig.image.tag;
545
+ const graphqlStandardConfigRemoteBranch = deployGraphQLServerConfig.graphqlServer.standardConfigRemoteBranch;
509
546
 
510
547
  // File paths
511
548
  const filePaths = {
@@ -559,16 +596,15 @@ export async function configureFromSite(fromSite, toSite, env, deployUI, deployG
559
596
  CONNECT_URL = `${oldUrl}_ui`;
560
597
  }
561
598
 
562
- await templateAuth0(SITE_HOST, CORE_API_CONTEXT, env, filePaths, deployUI, deployGraphQLServer, false, commonSecrets);
599
+ await templateAuth0(SITE_HOST, CORE_API_CONTEXT, env, filePaths, deployUI, deployGraphQLServer, commonSecrets);
563
600
  await importAuth0Templates('./auth0-site-setup/template', auth0Domain, auth0ClientId, auth0ClientSecret);
564
601
 
565
602
  if (deployUI === 'true') {
566
- await configureUI(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, env, true, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, uiSecretsPath, uiImageTag, repoPath);
603
+ await configureUI(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, env, useNewDomain, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, uiSecretsPath, uiImageTag, repoPath);
567
604
  }
568
-
569
- await configureGraphQLServer(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, env, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, graphqlSecretsPath, graphqlImageTag, shortCommitId, repoPath, commonSecrets);
570
- await pushDeployConfig(repoPath, `Config update for ${toSite} from ${fromSite} with UI: ${uiImageTag} and GraphQL: ${graphqlImageTag}`);
571
605
 
606
+ await configureGraphQLServer(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, env, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, graphqlSecretsPath, graphqlImageTag, graphqlStandardConfigRemoteBranch, repoPath, commonSecrets);
607
+ await pushDeployConfig(repoPath, `Config update for ${toSite} from ${fromSite} with UI: ${uiImageTag} and GraphQL: ${graphqlImageTag}`);
572
608
 
573
609
  await initializeAuth0Configuration({
574
610
  initConfiguration: "true",
@@ -576,4 +612,11 @@ export async function configureFromSite(fromSite, toSite, env, deployUI, deployG
576
612
  auth0AuthToken: auth0Token,
577
613
  coreApiIdentifier: commonSecrets.CORE_API_IDENTIFIER,
578
614
  });
615
+
616
+ await addApplicationToApi({
617
+ application: 'docupace-graphql-client-credentials',
618
+ auth0Domain: auth0Domain,
619
+ auth0AuthToken: auth0Token,
620
+ coreApiIdentifier: commonSecrets.CORE_API_IDENTIFIER
621
+ })
579
622
  }
@@ -105,21 +105,3 @@ export async function updateVaultSecrets(vaultPath, secretData) {
105
105
  // throw error;
106
106
  }
107
107
  }
108
-
109
- // Example usage
110
- // (async () => {
111
- // try {
112
- // const secretPath = 'secret/data/common/config';
113
- // const secretData = {
114
- // data: {
115
- // key1: 'value1',
116
- // key2: 'value2',
117
- // },
118
- // };
119
- //
120
- // const result = await updateVaultSecret(secretPath, secretData);
121
- // console.log('Secret updated successfully:', result);
122
- // } catch (err) {
123
- // console.error(err.message);
124
- // }
125
- // })();
@@ -0,0 +1,36 @@
1
+ import { $ } from 'zx';
2
+
3
+ export async function addApacheSite() {
4
+ if (
5
+ !process.env.ENVIRONMENT ||
6
+ (process.env.ENVIRONMENT !== 'dev' && process.env.ENVIRONMENT !== 'qa')
7
+ ) {
8
+ log("Error: ENVIRONMENT must be either 'dev' or 'qa'.");
9
+ process.exit(1);
10
+ }
11
+ if (!process.env.SITE) {
12
+ log('Error: SITE cannot be empty.');
13
+ process.exit(1);
14
+ }
15
+
16
+ // Save private key from base64
17
+ const haproxyPrivateKey = process.env.HAPROXY_PRIVATE_KEY;
18
+ if (!haproxyPrivateKey) {
19
+ log('Error: HAPROXY_PRIVATE_KEY not set.');
20
+ process.exit(1);
21
+ }
22
+
23
+ await fs.writeFile('private.key', Buffer.from(haproxyPrivateKey, 'base64'));
24
+ await fs.chmod('private.key', 0o600);
25
+
26
+ const server = `${process.env.ENVIRONMENT}-apalb01a.corp.docupace.com`;
27
+ console.log("Running command");
28
+ const sshCmd = (script) =>
29
+ $`ssh -i private.key -o StrictHostKeyChecking=no root@${server} ${script}`;
30
+
31
+ // The script is run twice in the Bash version
32
+ await sshCmd(`/root/repo/iis-preprod/scripts/addsite/add_core_site.sh ${process.env.ENVIRONMENT} ${process.env.SITE}`);
33
+ //await sshCmd(`/root/repo/iis-preprod/scripts/addsite/add_core_site.sh ${process.env.ENVIRONMENT} ${process.env.SITE}`);
34
+ }
35
+
36
+
package/src/next/cli.js CHANGED
@@ -7,6 +7,10 @@ import { publish } from './publish.js';
7
7
  import { deployFromSite } from './deploy.js';
8
8
  import { deployTemplate } from './deploy.js';
9
9
  import { copy } from './copy.js';
10
+ import { vaultAddSiteData } from './vault.js';
11
+ import { addApacheSite } from './apache.js';
12
+ import { haproxySync } from './haproxy.js';
13
+ import { connectClone } from './connect.js';
10
14
  import dotenv from 'dotenv';
11
15
 
12
16
  dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
@@ -17,6 +21,7 @@ const program = new Command();
17
21
  import { $ } from 'zx';
18
22
  import { deployCore } from './jenkins.js';
19
23
  import { runPipeline } from './pipline.js';
24
+
20
25
  const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
21
26
 
22
27
  program
@@ -33,6 +38,39 @@ program
33
38
  await sonar(GIT_SHA);
34
39
  });
35
40
 
41
+ program
42
+ .command('addApacheSite')
43
+ .description('Add site to apache')
44
+ .action(async () => {
45
+ await addApacheSite();
46
+ });
47
+
48
+ program
49
+ .command('connectClone')
50
+ .description('Clone connect site')
51
+ .action(async () => {
52
+ await connectClone();
53
+ });
54
+
55
+
56
+ program
57
+ .command('haproxySync')
58
+ .description('Sync haproxy config')
59
+ .action(async () => {
60
+ await haproxySync();
61
+ });
62
+
63
+
64
+
65
+ program
66
+ .command('vaultAddSiteData')
67
+ .description('Add m2m auth0 data to vault')
68
+ .requiredOption('-s, --site-name <siteName>', 'Site name')
69
+ .action(async (options) => {
70
+ const { siteName, } = options;
71
+ await vaultAddSiteData(siteName);
72
+ });
73
+
36
74
  program
37
75
  .command('publish')
38
76
  .description('Publish a Docker image')
@@ -83,7 +121,8 @@ program
83
121
  });
84
122
  });
85
123
 
86
- program
124
+
125
+ program
87
126
  .command('copy')
88
127
  .description('Copy a Docker image between registries')
89
128
  .requiredOption('-a, --application <application>', 'Application name')
@@ -0,0 +1,167 @@
1
+ import 'zx/globals'; // npm i zx
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import axios from 'axios';
5
+ import { $ } from 'zx';
6
+
7
+
8
+
9
+ import {
10
+ cloneEnvRepository,
11
+ cloneRepository
12
+ } from './deploy.js';
13
+
14
+
15
+ import { getVaultSecrets } from '../auth0/vault.js';
16
+
17
+ import {
18
+ getVaultSecretsConfigs,
19
+ environmentConfig
20
+ } from './config.js';
21
+
22
+ process.env.COMMON_VAULT_PATH = process.env.COMMON_VAULT_PATH || 'secret/data/common/config';
23
+ process.env.VAULT_SKIP_VERIFY = process.env.VAULT_SKIP_VERIFY || 'true';
24
+ process.env.CONNECT_DIR = process.env.CONNECT_DIR || 'connect';
25
+
26
+
27
+ function log(msg) {
28
+ console.log(`[*] ${msg}`);
29
+ }
30
+
31
+ /* --------------------------------
32
+ * 1. GIT CHECKOUT
33
+ * -------------------------------- */
34
+ async function gitCheckout(repository, destDir, branch = 'master') {
35
+ if (!(await fs.pathExists(destDir))) {
36
+ log(`Directory ${destDir} does not exist. Cloning repository...`);
37
+ } else {
38
+ log(`Directory ${destDir} exists. Removing it...`);
39
+ await fs.remove(destDir);
40
+ log(`Cloning ${destDir} repository...`);
41
+ }
42
+
43
+ // Since we use zx, the environment variables can be read from process.env
44
+ // e.g. $BITBUCKET_USERNAME, $BITBUCKET_APP_PASSWORD
45
+ const username = process.env.BITBUCKET_USERNAME;
46
+ const password = process.env.BITBUCKET_APP_PASSWORD;
47
+
48
+ // Construct clone command
49
+ const cloneUrl = `https://${username}:${password}@bitbucket.org/dp-cloud/${repository}.git`;
50
+
51
+ // Perform the clone
52
+ await $`git clone --branch=${branch} --depth 1 ${cloneUrl} ${destDir}`;
53
+ }
54
+
55
+
56
+
57
+ const vaultToken = process.env.VAULT_TOKEN;
58
+ const vaultAddr = process.env.VAULT_ADDR;
59
+
60
+
61
+ export async function connectClone() {
62
+
63
+
64
+ if (!vaultToken || !vaultAddr) {
65
+ console.error("Error: VAULT_TOKEN and VAULT_ADDR must be set.");
66
+ throw new Error("VAULT_TOKEN and VAULT_ADDR must be set.");
67
+ }
68
+
69
+ const site = process.env.BUILD_SITE;
70
+ if (!site) {
71
+ log('Error: BUILD_SITE is not set');
72
+ process.exit(1);
73
+ }
74
+ const siteCommonVaultPath = `secret/data/${site}/common/config`;
75
+
76
+
77
+ // 2) getVaultSecrets
78
+ const secretsJson = await getVaultSecrets(siteCommonVaultPath);
79
+ if (!secretsJson.AUTH0_CLIENT_ID) {
80
+ log('Failed to retrieve secret data.');
81
+ process.exit(1);
82
+ }
83
+ const siteCommonSecrets = secretsJson;
84
+
85
+ // 3) Export secrets as environment variables
86
+ process.env.AUTH0_CLIENT_ID = siteCommonSecrets.AUTH0_CLIENT_ID;
87
+ process.env.AUTH0_CLIENT_SECRET = siteCommonSecrets.AUTH0_CLIENT_SECRET;
88
+
89
+ process.env.AUTH0_SUBDOMAIN="docupace-${BUILD_ENVIRONMENT}-${BUILD_SITE}"
90
+ process.env.AUTH0_REGION_DOMAIN="us.auth0.com"
91
+
92
+ log(`BUILD_ENVIRONMENT: ${process.env.BUILD_ENVIRONMENT}`);
93
+ log(`BUILD_SITE: ${process.env.BUILD_SITE}`);
94
+ log(`AUTH0_SUBDOMAIN: ${process.env.AUTH0_SUBDOMAIN}`);
95
+ log(`AUTH0_REGION_DOMAIN: ${process.env.AUTH0_REGION_DOMAIN}`);
96
+ log(`AUTH0_CLIENT_ID: ${process.env.AUTH0_CLIENT_ID}`);
97
+
98
+ process.env.AUTH0_DOMAIN = `${process.env.AUTH0_SUBDOMAIN}.${process.env.AUTH0_REGION_DOMAIN}`;
99
+
100
+ // 4) Clone 'connect-deploy' into CONNECT_DIR
101
+ await gitCheckout('connect-deploy', process.env.CONNECT_DIR);
102
+
103
+ // 5) Create site clone (emulating the dock.sh call)
104
+ const cloneFrom = `${process.env.FROM_BUILD_ENVIRONMENT}/${process.env.FROM_BUILD_SITE}`;
105
+ const projectHome = path.resolve(process.env.CONNECT_DIR);
106
+
107
+ const cloneFromPath = path.join(projectHome, 'envs', cloneFrom);
108
+ if (!(await fs.pathExists(cloneFromPath))) {
109
+ log('Clone template directory not found');
110
+ process.exit(1);
111
+ }
112
+
113
+ const newSitePath = path.join(
114
+ projectHome,
115
+ 'envs',
116
+ process.env.BUILD_ENVIRONMENT,
117
+ process.env.BUILD_SITE
118
+ );
119
+
120
+ if (!(await fs.pathExists(newSitePath))) {
121
+ log('New site does not exist. Performing cloning...');
122
+ // This is where the bash script does: bash dock.sh clone ...
123
+ // We'll replicate with zx:
124
+ process.env.IMAGE_VERSION=$`cd ${cloneFromPath} && grep -E '^IMAGE_VERSION=' dock.sh | cut -f2 -d=`
125
+ await $`bash dock.sh clone ${process.env.BUILD_ENVIRONMENT} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
126
+ } else {
127
+ log('Site already exists. Continuing Auth0 setup...');
128
+ }
129
+
130
+ // 6) Retrieve Auth0 metadata
131
+ const targetSitePath = path.join(
132
+ projectHome,
133
+ 'envs',
134
+ process.env.BUILD_ENVIRONMENT,
135
+ process.env.BUILD_SITE
136
+ );
137
+ await $`cd ${targetSitePath} && bash dock.sh getAuth0Metadata`;
138
+
139
+ // 7) Check conf files, print logs
140
+ await $`grep "auth0" ${path.join(targetSitePath, 'conf/application.conf')}`;
141
+ await $`ls -all ${path.join(targetSitePath, 'conf')}`;
142
+ await $`ls -all ${path.join(targetSitePath, 'conf/saml')}`;
143
+ await $`cat ${path.join(targetSitePath, 'conf/saml/auth0.xml')}`;
144
+
145
+ // 8) Git add, commit, push
146
+ await $`cd ${targetSitePath} && git checkout master && git pull --ff-only`;
147
+ await $`cd ${targetSitePath} && git remote -v`;
148
+ await $`cd ${targetSitePath} && git branch`;
149
+ await $`cd ${targetSitePath} && git status`;
150
+ await $`cd ${targetSitePath} && git add . ../sites.sh`;
151
+ await $`cd ${targetSitePath} && git status`;
152
+
153
+ const numChanges = (
154
+ await $`cd ${targetSitePath} && git diff-index HEAD`
155
+ ).stdout.split('\n').filter(Boolean).length;
156
+
157
+ if (numChanges > 0) {
158
+ const jiraTicket = process.env.JIRA_TICKET || 'NO_JIRA';
159
+ const message = `${jiraTicket} usdoc-s-builui job download_auth0_metadata for ${process.env.BUILD_ENVIRONMENT}/${process.env.BUILD_SITE}`;
160
+ log('About to commit changes to git');
161
+ await $`cd ${targetSitePath} && git commit -m ${message}`;
162
+ await $`cd ${targetSitePath} && git push -u origin master`;
163
+ } else {
164
+ log('No changes have been made. The site likely already has the correct configuration.');
165
+ }
166
+ }
167
+
@@ -0,0 +1,50 @@
1
+ import { $ } from 'zx';
2
+
3
+
4
+ export async function haproxySync() {
5
+ const repoPath = '/root/repo/docupace-ansible';
6
+ const inventory = path.join(repoPath, 'inventories/preprod/inventory');
7
+
8
+ // Create haproxy.sh
9
+ const scriptContent = `
10
+ #!/bin/bash
11
+
12
+ [[ ! -f ${inventory} ]] && ( echo "Alert: no inventory file: ${inventory}" ; exit 1 )
13
+ cd ${repoPath}
14
+ pwd
15
+ git stash
16
+ git pull origin master
17
+ git checkout master
18
+ git submodule update --remote
19
+ git submodule foreach --recursive git checkout master
20
+ git submodule foreach --recursive git pull origin master
21
+
22
+ ansible-playbook -i inventories/preprod/inventory haproxy.yml -e "cluster=preprod"
23
+
24
+ echo "proceeding"
25
+ echo "committing changes"
26
+ git add preprod-haproxy.cfg
27
+ git commit -m "Sync haproxy"
28
+ git push origin master
29
+ `;
30
+
31
+ await fs.writeFile('haproxy.sh', scriptContent);
32
+
33
+ // Private key
34
+ const haproxyPrivateKey = process.env.HAPROXY_PRIVATE_KEY;
35
+ if (!haproxyPrivateKey) {
36
+ log('Error: HAPROXY_PRIVATE_KEY not set.');
37
+ process.exit(1);
38
+ }
39
+
40
+ await fs.writeFile('private.key', Buffer.from(haproxyPrivateKey, 'base64'));
41
+ await fs.chmod('private.key', 0o600);
42
+
43
+ await $`cat private.key`; // Just to mimic the script's behavior
44
+
45
+ // Copy script to remote
46
+ await $`scp -i private.key -o StrictHostKeyChecking=no haproxy.sh root@10.10.28.198:/tmp/haproxy.sh`;
47
+
48
+ // Execute script on remote
49
+ await $`ssh -i private.key -o StrictHostKeyChecking=no root@10.10.28.198 "bash /tmp/haproxy.sh"`;
50
+ }
@@ -0,0 +1,13 @@
1
+ import { $ } from 'zx';
2
+
3
+
4
+ export async function vaultAddSiteData(SITE) {
5
+ const AUTH0_CLIENT_ID = `${process.env.AUTH0_CLIENT_ID}`;
6
+ const AUTH0_CLIENT_SECRET = `${process.env.AUTH0_CLIENT_SECRET}`;
7
+ await $`export VAULT_SKIP_VERIFY=true`;
8
+ await $`vault kv put secret/dp-${SITE}/common/config AUTH0_CLIENT_ID="${AUTH0_CLIENT_ID}" AUTH0_CLIENT_SECRET="${AUTH0_CLIENT_SECRET}"`
9
+ }
10
+
11
+
12
+
13
+