@docupace/pipeline 1.0.7-alpha.ervins1.18 → 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 -53
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,79 +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
|
-
|
|
102
|
+
|
|
105
103
|
// 5) Create site clone (emulating the dock.sh call)
|
|
106
|
-
const cloneFrom =
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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');
|
|
112
114
|
process.exit(1);
|
|
113
115
|
}
|
|
114
116
|
|
|
117
|
+
const newSitePath = path.join(
|
|
118
|
+
projectHome,
|
|
119
|
+
'envs',
|
|
120
|
+
process.env.BUILD_ENVIRONMENT,
|
|
121
|
+
process.env.BUILD_SITE
|
|
122
|
+
);
|
|
115
123
|
|
|
116
|
-
if (!(await fs.pathExists(
|
|
124
|
+
if (!(await fs.pathExists(newSitePath))) {
|
|
117
125
|
log('New site does not exist. Performing cloning...');
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
await (async () => {
|
|
123
|
-
try {
|
|
124
|
-
// Execute the shell command
|
|
125
|
-
const result = await $`cd ${cloneFrom} && bash dock.sh clone ${process.env.BUILD_ENVIRONMENT} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
|
|
126
|
-
console.log('Command succeeded:');
|
|
127
|
-
console.log('stdout:', result.stdout); // Standard output
|
|
128
|
-
console.log('stderr:', result.stderr); // Standard error
|
|
129
|
-
} catch (error) {
|
|
130
|
-
console.error('Command failed:');
|
|
131
|
-
console.error('Exit Code:', error._code); // Exit code of the command
|
|
132
|
-
console.error('Signal:', error._signal); // Signal that caused termination (if any)
|
|
133
|
-
console.error('stdout:', error._stdout); // Standard output
|
|
134
|
-
console.error('stderr:', error._stderr); // Standard error
|
|
135
|
-
}
|
|
136
|
-
})();
|
|
137
|
-
|
|
138
|
-
|
|
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}`;
|
|
139
130
|
} else {
|
|
140
131
|
log('Site already exists. Continuing Auth0 setup...');
|
|
141
132
|
}
|
|
142
133
|
|
|
143
|
-
|
|
144
|
-
|
|
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`;
|
|
145
142
|
|
|
146
143
|
// 7) Check conf files, print logs
|
|
147
|
-
await $`grep "auth0" ${path.join(
|
|
148
|
-
await $`ls -all ${path.join(
|
|
149
|
-
await $`ls -all ${path.join(
|
|
150
|
-
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')}`;
|
|
151
148
|
|
|
152
149
|
// 8) Git add, commit, push
|
|
153
|
-
await $`cd ${
|
|
154
|
-
await $`cd ${
|
|
155
|
-
await $`cd ${
|
|
156
|
-
await $`cd ${
|
|
157
|
-
await $`cd ${
|
|
158
|
-
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`;
|
|
159
156
|
|
|
160
157
|
const numChanges = (
|
|
161
|
-
await $`cd ${
|
|
158
|
+
await $`cd ${targetSitePath} && git diff-index HEAD`
|
|
162
159
|
).stdout.split('\n').filter(Boolean).length;
|
|
163
160
|
|
|
164
161
|
if (numChanges > 0) {
|
|
165
162
|
const jiraTicket = process.env.JIRA_TICKET || 'NO_JIRA';
|
|
166
163
|
const message = `${jiraTicket} usdoc-s-builui job download_auth0_metadata for ${process.env.BUILD_ENVIRONMENT}/${process.env.BUILD_SITE}`;
|
|
167
164
|
log('About to commit changes to git');
|
|
168
|
-
await $`cd ${
|
|
169
|
-
await $`cd ${
|
|
165
|
+
await $`cd ${targetSitePath} && git commit -m ${message}`;
|
|
166
|
+
await $`cd ${targetSitePath} && git push -u origin master`;
|
|
170
167
|
} else {
|
|
171
168
|
log('No changes have been made. The site likely already has the correct configuration.');
|
|
172
169
|
}
|