@docupace/pipeline 1.0.7-alpha.9 → 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 +2 -2
- package/src/auth0/configure.js +44 -8
- package/src/next/apache.js +36 -0
- package/src/next/cli.js +40 -1
- package/src/next/connect.js +167 -0
- package/src/next/haproxy.js +50 -0
- package/src/next/vault.js +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docupace/pipeline",
|
|
3
|
-
"version": "1.0.7-alpha.
|
|
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.
|
|
27
|
+
"zx": "^8.3.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@eslint/js": "^9.17.0",
|
package/src/auth0/configure.js
CHANGED
|
@@ -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,
|
|
@@ -63,7 +95,6 @@ async function initializeAuth0Configuration({
|
|
|
63
95
|
);
|
|
64
96
|
|
|
65
97
|
const apiId = resourceServerResponse.data.id;
|
|
66
|
-
console.log(`API ID: ${apiId}`);
|
|
67
98
|
|
|
68
99
|
// Update tenant settings with the default audience
|
|
69
100
|
console.log("Updating tenant settings...");
|
|
@@ -79,7 +110,6 @@ async function initializeAuth0Configuration({
|
|
|
79
110
|
},
|
|
80
111
|
}
|
|
81
112
|
);
|
|
82
|
-
console.log(`coreApiIdentifier => ${coreApiIdentifier}`)
|
|
83
113
|
console.log("Tenant settings updated successfully.");
|
|
84
114
|
} catch (error) {
|
|
85
115
|
console.error("Error during Auth0 configuration:", error.response?.data || error.message);
|
|
@@ -372,7 +402,7 @@ externalConnectService:
|
|
|
372
402
|
}
|
|
373
403
|
}
|
|
374
404
|
|
|
375
|
-
async function configureGraphQLServer(siteHost, coreURL, docupaceHost, site, env, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, vaultSiteSecretsPath, imageTag,
|
|
405
|
+
async function configureGraphQLServer(siteHost, coreURL, docupaceHost, site, env, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, vaultSiteSecretsPath, imageTag, standardConfigRemoteBranch, repoPath, commonSecrets) {
|
|
376
406
|
console.log(`Configuring GraphQL Server for site: ${site} Host: ${siteHost} in env: ${env}`);
|
|
377
407
|
|
|
378
408
|
try {
|
|
@@ -408,7 +438,7 @@ async function configureGraphQLServer(siteHost, coreURL, docupaceHost, site, env
|
|
|
408
438
|
// Prepare ui.app.yaml
|
|
409
439
|
const graphQLServerAppYaml = `
|
|
410
440
|
repo: docupace-graphql-server
|
|
411
|
-
revision:
|
|
441
|
+
revision: ${standardConfigRemoteBranch}
|
|
412
442
|
`.trim();
|
|
413
443
|
|
|
414
444
|
// Prepare ui.values.yaml
|
|
@@ -420,12 +450,10 @@ graphqlServer:
|
|
|
420
450
|
baseUrl: https://${siteHost}/api/graphql
|
|
421
451
|
coreUrl: https://${coreURL}
|
|
422
452
|
integrationHubUrl: "https://${commonSecrets.INTEGRATION_HUB_URL}"
|
|
423
|
-
standardConfigRemoteBranch: ${
|
|
453
|
+
standardConfigRemoteBranch: ${standardConfigRemoteBranch}
|
|
424
454
|
apiLevel: "2"
|
|
425
455
|
env:
|
|
426
456
|
AUTH0_CLIENT_SECRET: vault:secret/data/${site}/graphql-server/config#AUTH0_CLIENT_SECRET
|
|
427
|
-
CORE_PASSWORD: vault:secret/data/common/config#CORE_PASSWORD
|
|
428
|
-
REMOTE_CONFIG_PATH: vault:secret/data/common/config#REMOTE_CONFIG_PATH
|
|
429
457
|
STANDARD_CONFIG_REMOTE_PATH: vault:secret/data/common/config#STANDARD_CONFIG_REMOTE_PATH
|
|
430
458
|
AUTH0_CC_CLIENT_ID: vault:secret/data/${site}/graphql-server/config#AUTH0_CC_CLIENT_ID
|
|
431
459
|
AUTH0_CC_CLIENT_SECRET: vault:secret/data/${site}/graphql-server/config#AUTH0_CC_CLIENT_SECRET
|
|
@@ -514,6 +542,7 @@ export async function configureFromSite(fromSite, toSite, env, deployUI, deployG
|
|
|
514
542
|
|
|
515
543
|
const { deployConfig: deployGraphQLServerConfig} = await readDeployConfig('graphql-server', env, fromSite);
|
|
516
544
|
const graphqlImageTag = deployGraphQLServerConfig.image.tag;
|
|
545
|
+
const graphqlStandardConfigRemoteBranch = deployGraphQLServerConfig.graphqlServer.standardConfigRemoteBranch;
|
|
517
546
|
|
|
518
547
|
// File paths
|
|
519
548
|
const filePaths = {
|
|
@@ -574,7 +603,7 @@ export async function configureFromSite(fromSite, toSite, env, deployUI, deployG
|
|
|
574
603
|
await configureUI(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, env, useNewDomain, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, uiSecretsPath, uiImageTag, repoPath);
|
|
575
604
|
}
|
|
576
605
|
|
|
577
|
-
await configureGraphQLServer(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, env, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, graphqlSecretsPath, graphqlImageTag,
|
|
606
|
+
await configureGraphQLServer(SITE_HOST, CORE_URL, DOCUPACE_HOST, toSite, env, auth0Domain, auth0ClientId, auth0ClientSecret, auth0Token, graphqlSecretsPath, graphqlImageTag, graphqlStandardConfigRemoteBranch, repoPath, commonSecrets);
|
|
578
607
|
await pushDeployConfig(repoPath, `Config update for ${toSite} from ${fromSite} with UI: ${uiImageTag} and GraphQL: ${graphqlImageTag}`);
|
|
579
608
|
|
|
580
609
|
await initializeAuth0Configuration({
|
|
@@ -583,4 +612,11 @@ export async function configureFromSite(fromSite, toSite, env, deployUI, deployG
|
|
|
583
612
|
auth0AuthToken: auth0Token,
|
|
584
613
|
coreApiIdentifier: commonSecrets.CORE_API_IDENTIFIER,
|
|
585
614
|
});
|
|
615
|
+
|
|
616
|
+
await addApplicationToApi({
|
|
617
|
+
application: 'docupace-graphql-client-credentials',
|
|
618
|
+
auth0Domain: auth0Domain,
|
|
619
|
+
auth0AuthToken: auth0Token,
|
|
620
|
+
coreApiIdentifier: commonSecrets.CORE_API_IDENTIFIER
|
|
621
|
+
})
|
|
586
622
|
}
|
|
@@ -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
|
-
|
|
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
|
+
|