@docupace/pipeline 1.0.5-alpha.25.ervins.21 → 1.0.5-alpha.25.ervins.3
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 +1 -1
- package/src/next/cli.js +0 -27
- package/src/next/apache.js +0 -36
- package/src/next/connect.js +0 -198
- package/src/next/haproxy.js +0 -50
package/package.json
CHANGED
package/src/next/cli.js
CHANGED
|
@@ -8,9 +8,6 @@ import { deployFromSite } from './deploy.js';
|
|
|
8
8
|
import { deployTemplate } from './deploy.js';
|
|
9
9
|
import { copy } from './copy.js';
|
|
10
10
|
import { vaultAddSiteData } from './vault.js';
|
|
11
|
-
import { addApacheSite } from './apache.js';
|
|
12
|
-
import { haproxySync } from './haproxy.js';
|
|
13
|
-
import { connectClone } from './connect.js';
|
|
14
11
|
import dotenv from 'dotenv';
|
|
15
12
|
|
|
16
13
|
dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
|
|
@@ -38,30 +35,6 @@ program
|
|
|
38
35
|
await sonar(GIT_SHA);
|
|
39
36
|
});
|
|
40
37
|
|
|
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
38
|
program
|
|
66
39
|
.command('vaultAddSiteData')
|
|
67
40
|
.description('Add m2m auth0 data to vault')
|
package/src/next/apache.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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/connect.js
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
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
|
-
process.env.COMMON_VAULT_PATH = process.env.COMMON_VAULT_PATH || 'secret/data/common/config';
|
|
9
|
-
process.env.VAULT_SKIP_VERIFY = process.env.VAULT_SKIP_VERIFY || 'true';
|
|
10
|
-
process.env.CONNECT_DIR = process.env.CONNECT_DIR || 'connect';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function log(msg) {
|
|
14
|
-
console.log(`[*] ${msg}`);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/* --------------------------------
|
|
18
|
-
* 1. GIT CHECKOUT
|
|
19
|
-
* -------------------------------- */
|
|
20
|
-
async function gitCheckout(repository, destDir, branch = 'master') {
|
|
21
|
-
if (!(await fs.pathExists(destDir))) {
|
|
22
|
-
log(`Directory ${destDir} does not exist. Cloning repository...`);
|
|
23
|
-
} else {
|
|
24
|
-
log(`Directory ${destDir} exists. Removing it...`);
|
|
25
|
-
await fs.remove(destDir);
|
|
26
|
-
log(`Cloning ${destDir} repository...`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Since we use zx, the environment variables can be read from process.env
|
|
30
|
-
// e.g. $BITBUCKET_USERNAME, $BITBUCKET_APP_PASSWORD
|
|
31
|
-
const username = process.env.BITBUCKET_USERNAME;
|
|
32
|
-
const password = process.env.BITBUCKET_APP_PASSWORD;
|
|
33
|
-
|
|
34
|
-
// Construct clone command
|
|
35
|
-
const cloneUrl = `https://${username}:${password}@bitbucket.org/dp-cloud/${repository}.git`;
|
|
36
|
-
|
|
37
|
-
// Perform the clone
|
|
38
|
-
await $`git clone --branch=${branch} --depth 1 ${cloneUrl} ${destDir}`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/* --------------------------------
|
|
43
|
-
* 3. GET VAULT SECRETS
|
|
44
|
-
* -------------------------------- */
|
|
45
|
-
async function getVaultSecrets(vaultPath) {
|
|
46
|
-
if (!vaultPath) {
|
|
47
|
-
console.error("Error: VAULT_PATH is required.");
|
|
48
|
-
throw new Error("VAULT_PATH is required.");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const vaultToken = process.env.VAULT_TOKEN;
|
|
52
|
-
const vaultAddr = process.env.VAULT_ADDR;
|
|
53
|
-
|
|
54
|
-
if (!vaultToken || !vaultAddr) {
|
|
55
|
-
console.error("Error: VAULT_TOKEN and VAULT_ADDR must be set.");
|
|
56
|
-
throw new Error("VAULT_TOKEN and VAULT_ADDR must be set.");
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
// Disable SSL verification globally by setting environment variable
|
|
61
|
-
if (process.env.VAULT_SKIP_VERIFY === 'true') {
|
|
62
|
-
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Fetch the secret from Vault
|
|
66
|
-
const response = await axios.get(`${vaultAddr}/v1/${vaultPath}`, {
|
|
67
|
-
headers: {
|
|
68
|
-
'X-Vault-Token': vaultToken,
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// Validate the response contains JSON data
|
|
73
|
-
const data = response.data;
|
|
74
|
-
if (data && typeof data === 'object') {
|
|
75
|
-
// console.log(`Secrets fetched successfully from Vault at ${JSON.stringify(data.data.data)})`);
|
|
76
|
-
return data.data.data;
|
|
77
|
-
} else {
|
|
78
|
-
console.error("Error: Invalid JSON received from Vault.");
|
|
79
|
-
throw new Error("Invalid JSON received from Vault.");
|
|
80
|
-
}
|
|
81
|
-
} catch (error) {
|
|
82
|
-
if (error.response) {
|
|
83
|
-
console.error(
|
|
84
|
-
`Error: Failed to connect to Vault server at ${vaultAddr}. Response: ${error.response.status} ${error.response.statusText}`
|
|
85
|
-
);
|
|
86
|
-
} else {
|
|
87
|
-
console.error(`Error: ${error.message}`);
|
|
88
|
-
}
|
|
89
|
-
// throw error;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export async function connectClone() {
|
|
94
|
-
console.log("Vault address:",process.env.VAULT_ADDR);
|
|
95
|
-
await $`curl -I -L ${process.env.VAULT_ADDR}`;
|
|
96
|
-
console.log('base64');
|
|
97
|
-
const out1 = await $`echo ${process.env.VAULT_TOKEN} | base64`;
|
|
98
|
-
console.log('base64:',out1);
|
|
99
|
-
|
|
100
|
-
const site = process.env.BUILD_SITE;
|
|
101
|
-
if (!site) {
|
|
102
|
-
log('Error: BUILD_SITE is not set');
|
|
103
|
-
process.exit(1);
|
|
104
|
-
}
|
|
105
|
-
const siteCommonVaultPath = `secret/data/${site}/common/config`;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
// 2) getVaultSecrets
|
|
109
|
-
const secretsJson = await getVaultSecrets(siteCommonVaultPath);
|
|
110
|
-
if (!secretsJson?.data?.data) {
|
|
111
|
-
log('Failed to retrieve secret data.');
|
|
112
|
-
process.exit(1);
|
|
113
|
-
}
|
|
114
|
-
const siteCommonSecrets = secretsJson.data.data;
|
|
115
|
-
|
|
116
|
-
// 3) Export secrets as environment variables
|
|
117
|
-
process.env.AUTH0_CLIENT_ID = siteCommonSecrets.AUTH0_CLIENT_ID;
|
|
118
|
-
process.env.AUTH0_CLIENT_SECRET = siteCommonSecrets.AUTH0_CLIENT_SECRET;
|
|
119
|
-
|
|
120
|
-
process.env.AUTH0_SUBDOMAIN="docupace-${BUILD_ENVIRONMENT}-${BUILD_SITE}"
|
|
121
|
-
process.env.AUTH0_REGION_DOMAIN="us.auth0.com"
|
|
122
|
-
|
|
123
|
-
log(`BUILD_ENVIRONMENT: ${process.env.BUILD_ENVIRONMENT}`);
|
|
124
|
-
log(`BUILD_SITE: ${process.env.BUILD_SITE}`);
|
|
125
|
-
log(`AUTH0_SUBDOMAIN: ${process.env.AUTH0_SUBDOMAIN}`);
|
|
126
|
-
log(`AUTH0_REGION_DOMAIN: ${process.env.AUTH0_REGION_DOMAIN}`);
|
|
127
|
-
log(`AUTH0_CLIENT_ID: ${process.env.AUTH0_CLIENT_ID}`);
|
|
128
|
-
|
|
129
|
-
process.env.AUTH0_DOMAIN = `${process.env.AUTH0_SUBDOMAIN}.${process.env.AUTH0_REGION_DOMAIN}`;
|
|
130
|
-
|
|
131
|
-
// 4) Clone 'connect-deploy' into CONNECT_DIR
|
|
132
|
-
await gitCheckout('connect-deploy', process.env.CONNECT_DIR);
|
|
133
|
-
|
|
134
|
-
// 5) Create site clone (emulating the dock.sh call)
|
|
135
|
-
const cloneFrom = `${process.env.FROM_BUILD_ENVIRONMENT}/${process.env.FROM_BUILD_SITE}`;
|
|
136
|
-
const projectHome = path.resolve(process.env.CONNECT_DIR);
|
|
137
|
-
|
|
138
|
-
const cloneFromPath = path.join(projectHome, 'envs', cloneFrom);
|
|
139
|
-
if (!(await fs.pathExists(cloneFromPath))) {
|
|
140
|
-
log('Clone template directory not found');
|
|
141
|
-
process.exit(1);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const newSitePath = path.join(
|
|
145
|
-
projectHome,
|
|
146
|
-
'envs',
|
|
147
|
-
process.env.BUILD_ENVIRONMENT,
|
|
148
|
-
process.env.BUILD_SITE
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
if (!(await fs.pathExists(newSitePath))) {
|
|
152
|
-
log('New site does not exist. Performing cloning...');
|
|
153
|
-
// This is where the bash script does: bash dock.sh clone ...
|
|
154
|
-
// We'll replicate with zx:
|
|
155
|
-
process.env.IMAGE_VERSION=$`cd ${cloneFromPath} && grep -E '^IMAGE_VERSION=' dock.sh | cut -f2 -d=`
|
|
156
|
-
await $`bash dock.sh clone ${process.env.BUILD_ENVIRONMENT} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
|
|
157
|
-
} else {
|
|
158
|
-
log('Site already exists. Continuing Auth0 setup...');
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// 6) Retrieve Auth0 metadata
|
|
162
|
-
const targetSitePath = path.join(
|
|
163
|
-
projectHome,
|
|
164
|
-
'envs',
|
|
165
|
-
process.env.BUILD_ENVIRONMENT,
|
|
166
|
-
process.env.BUILD_SITE
|
|
167
|
-
);
|
|
168
|
-
await $`cd ${targetSitePath} && bash dock.sh getAuth0Metadata`;
|
|
169
|
-
|
|
170
|
-
// 7) Check conf files, print logs
|
|
171
|
-
await $`grep "auth0" ${path.join(targetSitePath, 'conf/application.conf')}`;
|
|
172
|
-
await $`ls -all ${path.join(targetSitePath, 'conf')}`;
|
|
173
|
-
await $`ls -all ${path.join(targetSitePath, 'conf/saml')}`;
|
|
174
|
-
await $`cat ${path.join(targetSitePath, 'conf/saml/auth0.xml')}`;
|
|
175
|
-
|
|
176
|
-
// 8) Git add, commit, push
|
|
177
|
-
await $`cd ${targetSitePath} && git checkout master && git pull --ff-only`;
|
|
178
|
-
await $`cd ${targetSitePath} && git remote -v`;
|
|
179
|
-
await $`cd ${targetSitePath} && git branch`;
|
|
180
|
-
await $`cd ${targetSitePath} && git status`;
|
|
181
|
-
await $`cd ${targetSitePath} && git add . ../sites.sh`;
|
|
182
|
-
await $`cd ${targetSitePath} && git status`;
|
|
183
|
-
|
|
184
|
-
const numChanges = (
|
|
185
|
-
await $`cd ${targetSitePath} && git diff-index HEAD`
|
|
186
|
-
).stdout.split('\n').filter(Boolean).length;
|
|
187
|
-
|
|
188
|
-
if (numChanges > 0) {
|
|
189
|
-
const jiraTicket = process.env.JIRA_TICKET || 'NO_JIRA';
|
|
190
|
-
const message = `${jiraTicket} usdoc-s-builui job download_auth0_metadata for ${process.env.BUILD_ENVIRONMENT}/${process.env.BUILD_SITE}`;
|
|
191
|
-
log('About to commit changes to git');
|
|
192
|
-
await $`cd ${targetSitePath} && git commit -m ${message}`;
|
|
193
|
-
await $`cd ${targetSitePath} && git push -u origin master`;
|
|
194
|
-
} else {
|
|
195
|
-
log('No changes have been made. The site likely already has the correct configuration.');
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
package/src/next/haproxy.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
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
|
-
}
|