@docupace/pipeline 1.0.7-alpha.ervins1.19 → 1.0.7-alpha.ervins1.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.
- package/package.json +1 -1
- package/src/next/connect.js +50 -54
package/package.json
CHANGED
package/src/next/connect.js
CHANGED
|
@@ -22,8 +22,7 @@ import {
|
|
|
22
22
|
process.env.COMMON_VAULT_PATH = process.env.COMMON_VAULT_PATH || 'secret/data/common/config';
|
|
23
23
|
process.env.VAULT_SKIP_VERIFY = process.env.VAULT_SKIP_VERIFY || 'true';
|
|
24
24
|
process.env.CONNECT_DIR = process.env.CONNECT_DIR || 'connect';
|
|
25
|
-
|
|
26
|
-
const vaultAddr = process.env.VAULT_ADDR;
|
|
25
|
+
|
|
27
26
|
|
|
28
27
|
function log(msg) {
|
|
29
28
|
console.log(`[*] ${msg}`);
|
|
@@ -41,19 +40,22 @@ function log(msg) {
|
|
|
41
40
|
log(`Cloning ${destDir} repository...`);
|
|
42
41
|
}
|
|
43
42
|
|
|
43
|
+
// Since we use zx, the environment variables can be read from process.env
|
|
44
|
+
// e.g. $BITBUCKET_USERNAME, $BITBUCKET_APP_PASSWORD
|
|
44
45
|
const username = process.env.BITBUCKET_USERNAME;
|
|
45
46
|
const password = process.env.BITBUCKET_APP_PASSWORD;
|
|
46
47
|
|
|
47
48
|
// Construct clone command
|
|
48
49
|
const cloneUrl = `https://${username}:${password}@bitbucket.org/dp-cloud/${repository}.git`;
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
// Perform the clone
|
|
51
52
|
await $`git clone --branch=${branch} --depth 1 ${cloneUrl} ${destDir}`;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
const vaultToken = process.env.VAULT_TOKEN;
|
|
58
|
+
const vaultAddr = process.env.VAULT_ADDR;
|
|
57
59
|
|
|
58
60
|
|
|
59
61
|
export async function connectClone() {
|
|
@@ -94,80 +96,74 @@ export async function connectClone() {
|
|
|
94
96
|
log(`AUTH0_CLIENT_ID: ${process.env.AUTH0_CLIENT_ID}`);
|
|
95
97
|
|
|
96
98
|
process.env.AUTH0_DOMAIN = `${process.env.AUTH0_SUBDOMAIN}.${process.env.AUTH0_REGION_DOMAIN}`;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const projectRoot = process.cwd();
|
|
99
|
+
|
|
100
100
|
// 4) Clone 'connect-deploy' into CONNECT_DIR
|
|
101
|
-
|
|
102
|
-
|
|
103
101
|
await gitCheckout('connect-deploy', process.env.CONNECT_DIR);
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
|
|
106
103
|
// 5) Create site clone (emulating the dock.sh call)
|
|
107
|
-
const cloneFrom =
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
const cloneFrom = `${process.env.FROM_BUILD_ENVIRONMENT}/${process.env.FROM_BUILD_SITE}`;
|
|
105
|
+
const projectRoot = path;
|
|
106
|
+
console.log(projectRoot);
|
|
107
|
+
console.log($`find .`);
|
|
108
|
+
const projectHome = path.resolve(process.env.CONNECT_DIR);
|
|
109
|
+
console.log(projectHome);
|
|
110
|
+
|
|
111
|
+
const cloneFromPath = path.join(projectHome, 'envs', cloneFrom);
|
|
112
|
+
if (!(await fs.pathExists(cloneFromPath))) {
|
|
113
|
+
log('Clone template directory not found');
|
|
113
114
|
process.exit(1);
|
|
114
115
|
}
|
|
115
116
|
|
|
117
|
+
const newSitePath = path.join(
|
|
118
|
+
projectHome,
|
|
119
|
+
'envs',
|
|
120
|
+
process.env.BUILD_ENVIRONMENT,
|
|
121
|
+
process.env.BUILD_SITE
|
|
122
|
+
);
|
|
116
123
|
|
|
117
|
-
if (!(await fs.pathExists(
|
|
124
|
+
if (!(await fs.pathExists(newSitePath))) {
|
|
118
125
|
log('New site does not exist. Performing cloning...');
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
await (async () => {
|
|
124
|
-
try {
|
|
125
|
-
// Execute the shell command
|
|
126
|
-
const result = await $`cd ${cloneFrom} && bash dock.sh clone ${process.env.BUILD_ENVIRONMENT} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
|
|
127
|
-
console.log('Command succeeded:');
|
|
128
|
-
console.log('stdout:', result.stdout); // Standard output
|
|
129
|
-
console.log('stderr:', result.stderr); // Standard error
|
|
130
|
-
} catch (error) {
|
|
131
|
-
console.error('Command failed:');
|
|
132
|
-
console.error('Exit Code:', error._code); // Exit code of the command
|
|
133
|
-
console.error('Signal:', error._signal); // Signal that caused termination (if any)
|
|
134
|
-
console.error('stdout:', error._stdout); // Standard output
|
|
135
|
-
console.error('stderr:', error._stderr); // Standard error
|
|
136
|
-
}
|
|
137
|
-
})();
|
|
138
|
-
|
|
139
|
-
|
|
126
|
+
// This is where the bash script does: bash dock.sh clone ...
|
|
127
|
+
// We'll replicate with zx:
|
|
128
|
+
process.env.IMAGE_VERSION=$`cd ${cloneFromPath} && grep -E '^IMAGE_VERSION=' dock.sh | cut -f2 -d=`
|
|
129
|
+
await $`cd ${targetSitePath} && bash dock.sh clone ${process.env.BUILD_ENVIRONMENT} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
|
|
140
130
|
} else {
|
|
141
131
|
log('Site already exists. Continuing Auth0 setup...');
|
|
142
132
|
}
|
|
143
133
|
|
|
144
|
-
|
|
145
|
-
|
|
134
|
+
// 6) Retrieve Auth0 metadata
|
|
135
|
+
const targetSitePath = path.join(
|
|
136
|
+
projectHome,
|
|
137
|
+
'envs',
|
|
138
|
+
process.env.BUILD_ENVIRONMENT,
|
|
139
|
+
process.env.BUILD_SITE
|
|
140
|
+
);
|
|
141
|
+
await $`cd ${targetSitePath} && bash dock.sh getAuth0Metadata`;
|
|
146
142
|
|
|
147
143
|
// 7) Check conf files, print logs
|
|
148
|
-
await $`grep "auth0" ${path.join(
|
|
149
|
-
await $`ls -all ${path.join(
|
|
150
|
-
await $`ls -all ${path.join(
|
|
151
|
-
await $`cat ${path.join(
|
|
144
|
+
await $`grep "auth0" ${path.join(targetSitePath, 'conf/application.conf')}`;
|
|
145
|
+
await $`ls -all ${path.join(targetSitePath, 'conf')}`;
|
|
146
|
+
await $`ls -all ${path.join(targetSitePath, 'conf/saml')}`;
|
|
147
|
+
await $`cat ${path.join(targetSitePath, 'conf/saml/auth0.xml')}`;
|
|
152
148
|
|
|
153
149
|
// 8) Git add, commit, push
|
|
154
|
-
await $`cd ${
|
|
155
|
-
await $`cd ${
|
|
156
|
-
await $`cd ${
|
|
157
|
-
await $`cd ${
|
|
158
|
-
await $`cd ${
|
|
159
|
-
await $`cd ${
|
|
150
|
+
await $`cd ${targetSitePath} && git checkout master && git pull --ff-only`;
|
|
151
|
+
await $`cd ${targetSitePath} && git remote -v`;
|
|
152
|
+
await $`cd ${targetSitePath} && git branch`;
|
|
153
|
+
await $`cd ${targetSitePath} && git status`;
|
|
154
|
+
await $`cd ${targetSitePath} && git add . ../sites.sh`;
|
|
155
|
+
await $`cd ${targetSitePath} && git status`;
|
|
160
156
|
|
|
161
157
|
const numChanges = (
|
|
162
|
-
await $`cd ${
|
|
158
|
+
await $`cd ${targetSitePath} && git diff-index HEAD`
|
|
163
159
|
).stdout.split('\n').filter(Boolean).length;
|
|
164
160
|
|
|
165
161
|
if (numChanges > 0) {
|
|
166
162
|
const jiraTicket = process.env.JIRA_TICKET || 'NO_JIRA';
|
|
167
163
|
const message = `${jiraTicket} usdoc-s-builui job download_auth0_metadata for ${process.env.BUILD_ENVIRONMENT}/${process.env.BUILD_SITE}`;
|
|
168
164
|
log('About to commit changes to git');
|
|
169
|
-
await $`cd ${
|
|
170
|
-
await $`cd ${
|
|
165
|
+
await $`cd ${targetSitePath} && git commit -m ${message}`;
|
|
166
|
+
await $`cd ${targetSitePath} && git push -u origin master`;
|
|
171
167
|
} else {
|
|
172
168
|
log('No changes have been made. The site likely already has the correct configuration.');
|
|
173
169
|
}
|