@docupace/pipeline 1.0.1 → 1.0.2-3.tes2

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.
@@ -0,0 +1,59 @@
1
+ import groovy.json.JsonSlurper
2
+
3
+ import hudson.model.*;
4
+
5
+ def build = Thread.currentThread().executable
6
+ def params = build.getEnvironment(listener)
7
+
8
+ def site = params.get('site')
9
+ def server = "jboss7"
10
+ def environment = params.get('environment')
11
+
12
+ def buildFile=new File("D:\\Docupace\\CustomFolders\\" + environment + "\\" + site + "\\" + server + "\\buildApp.properties")
13
+
14
+ List<String> jboss7controllerResult = []
15
+
16
+ def controllersReport = new File("D:\\Docupace\\controllers_report.json")
17
+ def inputJSON = new JsonSlurper().parseText(controllersReport.text)
18
+ def props = new Properties()
19
+ buildFile.withInputStream { stream -> props.load(stream) }
20
+ def webRootContext = props["web.root.context"]
21
+ if (webRootContext == null || webRootContext =="core") webRootContext = props["docupace.config.client.id"].toLowerCase()
22
+
23
+ webRootContext = webRootContext.replaceFirst('_sso','')
24
+ def map = inputJSON.'content'
25
+
26
+ def Boolean enabled
27
+
28
+ map.each {k,v ->
29
+ v.each{vk, vv -> if (vk == webRootContext ) {
30
+ enabled = false
31
+ if(vv.deploymentsProperty.size()>0) enabled = vv.deploymentsProperty[0].isEnabled
32
+ if (enabled) jboss7controllerResult.push(k)
33
+ else jboss7controllerResult << k
34
+ }
35
+ }
36
+ }
37
+
38
+ if (jboss7controllerResult.size()>0) {
39
+ if (environment == 'preprod') {
40
+ jboss7controllerResult.remove("dev-corjbdc10.corp.docupace.com")
41
+ jboss7controllerResult.remove("usdoc-s-jbdc1.corp.docupace.com")
42
+ }
43
+ if (environment == 'dev') {
44
+ jboss7controllerResult.remove("qa-corjbdc10.corp.docupace.com")
45
+ jboss7controllerResult.remove("qa-corjbdc20.corp.docupace.com")
46
+ jboss7controllerResult.remove("usdoc-s-jbdc2.corp.docupace.com")
47
+ }
48
+ }
49
+
50
+ println jboss7controllerResult[0]
51
+
52
+ env.jboss7controller = jboss7controllerResult[0]
53
+
54
+ def serverGroup = inputJSON.'content'."${jboss7controller}"."${webRootContext}".'serverGroup'
55
+
56
+ println serverGroup
57
+
58
+ params.put("serverGroup", serverGroup)
59
+
@@ -0,0 +1,53 @@
1
+ import { BasicAuth, DomainApi } from '@docupace/core-client';
2
+
3
+ const userFilter = (userId) => {
4
+ return {
5
+ orSections: [
6
+ {
7
+ andSections: [
8
+ {
9
+ attrId: 9501,
10
+ '@type': 'string',
11
+ not: false,
12
+ orSections: [
13
+ { searchType: 'EXACT_MATCH', matchToValues: [userId] },
14
+ ],
15
+ },
16
+ ],
17
+ },
18
+ ],
19
+ };
20
+ };
21
+
22
+ /*
23
+ Example:
24
+ await createAlias(
25
+ 'https://www.dev.docupaceinc.com/financialdev',
26
+ 'docupace',
27
+ 'pw',
28
+ 'Connect',
29
+ 'qhnospjRjwUAeKFDhucHEabPsfihrGQQ@clients',
30
+ );
31
+ */
32
+ export async function createAlias(coreUrl, username, password, realm, alias) {
33
+ const coreInfo = {
34
+ url: coreUrl,
35
+ };
36
+
37
+ let auth = new BasicAuth(username, password);
38
+
39
+ const domainApi = new DomainApi(coreInfo, auth);
40
+
41
+ const userResults = await domainApi.listRecords(50, {
42
+ filter: JSON.stringify(userFilter(username)),
43
+ });
44
+
45
+ const record = {
46
+ domainId: 302,
47
+ '5001': userResults.records[0].id,
48
+ '9102': realm,
49
+ '9504': alias,
50
+ };
51
+
52
+ await domainApi.create(record);
53
+ }
@@ -0,0 +1,40 @@
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
+
27
+ console.log("Running command");
28
+ const sshCmd = (server,script) =>
29
+ $`ssh -i private.key -o StrictHostKeyChecking=no root@${server} ${script}`;
30
+
31
+ let server = `${process.env.ENVIRONMENT}-apalb01a.corp.docupace.com`;
32
+ // The script is run twice in the Bash version
33
+ await sshCmd(server, `/root/repo/iis-preprod/scripts/addsite/add_core_site.sh ${process.env.ENVIRONMENT} ${process.env.SITE}`);
34
+
35
+ server = `${process.env.ENVIRONMENT}-apalb01b.corp.docupace.com`;
36
+
37
+ await sshCmd(server,`/root/repo/iis-preprod/scripts/addsite/add_core_site.sh ${process.env.ENVIRONMENT} ${process.env.SITE}`);
38
+ }
39
+
40
+
package/src/next/cli.js CHANGED
@@ -4,56 +4,173 @@ import { Command } from 'commander';
4
4
  import { pull } from './pull.js';
5
5
  import { sonar } from './sonar.js';
6
6
  import { publish } from './publish.js';
7
- import { deploy } from './deploy.js';
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';
14
+ import dotenv from 'dotenv';
15
+
16
+ dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
10
17
 
11
18
  const program = new Command();
12
19
 
13
- // GIT SHA computation
14
20
  import { $ } from 'zx';
21
+ import { deployConnect, deployCore } from './jenkins.js';
22
+ import { runPipeline } from './pipline.js';
23
+
15
24
  const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
16
25
 
17
26
  program
18
- .command('pull <imageName>')
19
- .description('Pull a Docker image from the registry')
20
- .action(async (imageName) => {
21
- await pull(imageName);
22
- });
27
+ .command('pull <imageName>')
28
+ .description('Pull a Docker image from the registry')
29
+ .action(async (imageName) => {
30
+ await pull(imageName);
31
+ });
23
32
 
24
33
  program
25
- .command('sonar')
26
- .description('Run Sonar analysis')
27
- .action(async () => {
28
- await sonar(GIT_SHA);
29
- });
34
+ .command('sonar')
35
+ .description('Run Sonar analysis')
36
+ .action(async () => {
37
+ await sonar(GIT_SHA);
38
+ });
30
39
 
31
40
  program
32
- .command('publish')
33
- .description('Publish a Docker image')
34
- .action(async () => {
35
- await publish(GIT_SHA);
36
- });
41
+ .command('addApacheSite')
42
+ .description('Add site to apache')
43
+ .action(async () => {
44
+ await addApacheSite();
45
+ });
37
46
 
38
47
  program
39
- .command('deploy <application> <site>')
40
- .description('Deploy an application for a specific site')
41
- .action(async (application, site) => {
42
- await deploy(application, site);
43
- });
48
+ .command('connectClone')
49
+ .description('Clone connect site')
50
+ .action(async () => {
51
+ await connectClone();
52
+ });
44
53
 
45
54
  program
46
- .command('deployTemplate <site>')
47
- .description('Deploy an application for a specific site')
48
- .action(async (site) => {
49
- await deployTemplate(site);
50
- });
55
+ .command('haproxySync')
56
+ .description('Sync haproxy config')
57
+ .action(async () => {
58
+ await haproxySync();
59
+ });
60
+
61
+ program
62
+ .command('vaultAddSiteData')
63
+ .description('Add m2m auth0 data to vault')
64
+ .requiredOption('-s, --site-name <siteName>', 'Site name')
65
+ .requiredOption(
66
+ '-p, --site-config-remote-path <siteConfigRemotePath>',
67
+ 'Site Config Remote Path',
68
+ )
69
+ .action(async (options) => {
70
+ const { siteName, siteConfigRemotePath } = options;
71
+ await vaultAddSiteData(siteName, siteConfigRemotePath);
72
+ });
73
+
74
+ program
75
+ .command('publish')
76
+ .description('Publish a Docker image')
77
+ .action(async () => {
78
+ await publish(GIT_SHA);
79
+ });
80
+
81
+ program
82
+ .command('deploy-from-site')
83
+ .description('Deploy an application for a specific site')
84
+ .requiredOption('-f, --from-env <fromEnv>', 'Source environment')
85
+ .requiredOption('-t, --to-env <toEnv>', 'Target environment')
86
+ .requiredOption('-F, --from-site <fromSite>', 'Source site')
87
+ .requiredOption('-T, --to-site <toSite>', 'Target site')
88
+ .option('-c, --deploy-core <deployCore>', 'Deploy Core', 'false')
89
+ .action(async (options) => {
90
+ const { fromEnv, fromSite, toEnv, toSite, deployCore } = options;
91
+ await deployFromSite(fromEnv, fromSite, toEnv, toSite, deployCore);
92
+ });
93
+
94
+ program
95
+ .command('deployTemplate <site>')
96
+ .description('Deploy an application for a specific site')
97
+ .action(async (site) => {
98
+ await deployTemplate(site);
99
+ });
100
+
101
+ program
102
+ .command('deploy-core <env> <site>')
103
+ .description('Deploy Core')
104
+ .option('-l, --liquibase <liquibase>', 'Application name', 'true')
105
+ .option('-b, --branch <branch>', 'Branch', 'master')
106
+ .action(async (env, site, options) => {
107
+ await deployCore(env, site, options.liquibase, options.branch);
108
+ });
109
+
110
+ program
111
+ .command('deploy-connect <env> <site>')
112
+ .description('Deploy Core')
113
+ .option('-l, --liquibase <liquibase>', 'Application name', 'true')
114
+ .option('-b, --branch <branch>', 'Branch', 'master')
115
+ .action(async (env, site, options) => {
116
+ await deployConnect(env, site, options.liquibase, options.branch);
117
+ });
51
118
 
52
119
  program
53
- .command('copy')
54
- .description('Copy a Docker image between registries')
55
- .action(async () => {
56
- await copy();
120
+ .command('deploy-core-pipeline <env> <site>')
121
+ .description('Deploy Core')
122
+ .option('-l, --liquibase <liquibase>', 'Application name', 'true')
123
+ .option('-b, --branch <branch>', 'Branch', 'master')
124
+ .action(async (env, site, options) => {
125
+ await runPipeline('site-deploy', 'deploy-core', 'main', {
126
+ ENV: env,
127
+ SITE: site,
128
+ LIQUIBASE: options.liquibase,
129
+ BRANCH: options.branch,
57
130
  });
131
+ });
132
+
133
+ program
134
+ .command('copy')
135
+ .description('Copy a Docker image between registries')
136
+ .requiredOption('-a, --application <application>', 'Application name')
137
+ .requiredOption('-f, --from-env <fromEnv>', 'Source environment')
138
+ .requiredOption('-t, --to-env <toEnv>', 'Target environment')
139
+ .requiredOption('-g, --tag <tag>', 'Image tag')
140
+ .action(async (options) => {
141
+ const { application, fromEnv, toEnv, tag } = options;
142
+ await copy(application, fromEnv, toEnv, tag);
143
+ });
144
+
145
+ program
146
+ .command('run-pipeline')
147
+ .description('Trigger a pipeline by name')
148
+ .requiredOption('-r, --repository <repository>', 'Repository name')
149
+ .requiredOption('-p, --pipeline-name <pipelineName>', 'Pipeline name')
150
+ .requiredOption('-b, --branch <branch>', 'Branch name')
151
+ .option(
152
+ '-v, --variables <key=value>',
153
+ 'Pipeline variable as key=value pair',
154
+ (value, previous) => {
155
+ const [key, val] = value.split('=');
156
+ if (!key || val === undefined) {
157
+ throw new Error(`Invalid variable format: ${value}. Use key=value.`);
158
+ }
159
+ return { ...previous, [key]: val };
160
+ },
161
+ {},
162
+ )
163
+ .option('-w, --wait', 'Wait for the pipeline to complete', false) // Defaults to false
164
+ .action(async (cmdObj) => {
165
+ try {
166
+ const { repository, pipelineName, branch, variables, wait } = cmdObj;
167
+
168
+ // Call the triggerPipelineByName function
169
+ await runPipeline(repository, pipelineName, branch, variables, wait);
170
+ } catch (error) {
171
+ console.error('Error triggering pipeline:', error.message);
172
+ process.exit(1);
173
+ }
174
+ });
58
175
 
59
176
  program.parse(process.argv);
@@ -0,0 +1,84 @@
1
+ export const environments = ['dev', 'qa', 'uat', 'stage', 'prod'];
2
+
3
+ export const environmentConfig = {
4
+ dev: {
5
+ newUrl: (site) => `https://${site}.dev.dpai.tech`,
6
+ oldUrl: (site) => `https://www.dev.docupaceinc.com/${site}`,
7
+ docupaceHost: () => 'www.dev.docupaceinc.com',
8
+ },
9
+ qa: {
10
+ newUrl: (site) => `https://${site}.qa.dpai.tech`,
11
+ oldUrl: (site) => `https://www.preprod.docupaceinc.com/${site}`,
12
+ docupaceHost: () => 'www.preprod.docupaceinc.com',
13
+ },
14
+ uat: {
15
+ newUrl: (site) => `https://${site}.qa.dpai.tech`,
16
+ oldUrl: (site) => `https://www2.paperout.com/${site}_uat`,
17
+ docupaceHost: () => 'www2.paperout.com',
18
+ },
19
+ stage: {
20
+ newUrl: (site) => `https://${site}.stage.dpai.tech`,
21
+ oldUrl: (site) => `https://www2.paperout.com/${site}_staging`,
22
+ docupaceHost: () => 'www2.paperout.com',
23
+ },
24
+ prod: {
25
+ newUrl: (site) => `https://${site}.dpai.tech`,
26
+ oldUrl: (site) => `https://www2.paperout.com/${site}`,
27
+ docupaceHost: () => 'www2.paperout.com',
28
+ },
29
+ };
30
+
31
+ export const appInfo = {
32
+ 'graphql-server': {
33
+ repositoryName: 'docupace-graphql-server',
34
+ deployAttributes: [
35
+ 'image.tag',
36
+ 'graphqlServer.siteConfigRemoteBranch',
37
+ 'graphqlServer.standardConfigRemoteBranch',
38
+ ],
39
+ },
40
+ ui: {
41
+ repositoryName: 'docupace-ui-main',
42
+ deployAttributes: ['image.tag'],
43
+ },
44
+ };
45
+
46
+ export const getEnvInfo = () => {
47
+ const envInfo = Object.fromEntries(
48
+ environments.map((env) => [
49
+ env,
50
+ {
51
+ jfrog: {
52
+ username: process.env[`JF_REGISTRY_${env.toUpperCase()}_USERNAME`],
53
+ password: process.env[`JF_REGISTRY_${env.toUpperCase()}_PASSWORD`],
54
+ },
55
+ },
56
+ ]),
57
+ );
58
+
59
+ return envInfo;
60
+ };
61
+
62
+ export const getBitbucketInfo = () => {
63
+ return {
64
+ username: process.env.BITBUCKET_USERNAME,
65
+ password: process.env.BITBUCKET_APP_PASSWORD,
66
+ workspace: 'dp-cloud',
67
+ };
68
+ };
69
+
70
+ export const getRepUrl = (repoName) => {
71
+ const { username, password, workspace } = getBitbucketInfo();
72
+ return `https://${username}:${password}@bitbucket.org/${workspace}/${repoName}.git`;
73
+ };
74
+
75
+ export const jfRegistryUrl = 'registry.paperout.com';
76
+
77
+ export const getVaultSecretsConfigs = (site) => {
78
+ return {
79
+ commonSecretsPath: 'secret/data/common/config',
80
+ siteCommonSecretsPath: `secret/data/${site}/common/config`,
81
+ graphqlServerSecretsPath: `secret/data/${site}/graphql-server/config`,
82
+ uiSecretsPath: `secret/data/${site}/ui/config`
83
+ }
84
+ };
@@ -0,0 +1,199 @@
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
+ const vaultToken = process.env.VAULT_TOKEN;
26
+ const vaultAddr = process.env.VAULT_ADDR;
27
+
28
+ const connectUIEnvMap= {
29
+ 'dev': 'dev',
30
+ 'qa': 'preprod',
31
+ 'stg': 'stg',
32
+ 'uat': 'uat',
33
+ 'prd': 'prod-las'
34
+ };
35
+
36
+ function log(msg) {
37
+ console.log(`[*] ${msg}`);
38
+ }
39
+
40
+ /* --------------------------------
41
+ * 1. GIT CHECKOUT
42
+ * -------------------------------- */
43
+ async function gitCheckout(repository, destDir, branch = 'master') {
44
+ if (!(await fs.pathExists(destDir))) {
45
+ log(`Directory ${destDir} does not exist. Cloning repository...`);
46
+ } else {
47
+ log(`Directory ${destDir} exists. Removing it...`);
48
+ await fs.remove(destDir);
49
+ log(`Cloning ${destDir} repository...`);
50
+ }
51
+
52
+ const username = process.env.BITBUCKET_USERNAME;
53
+ const password = process.env.BITBUCKET_APP_PASSWORD;
54
+
55
+ // Construct clone command
56
+ const cloneUrl = `https://${username}:${password}@bitbucket.org/dp-cloud/${repository}.git`;
57
+
58
+ log(`Perform cloning`);
59
+ await $`git clone --branch=${branch} --depth 1 ${cloneUrl} ${destDir}`;
60
+ }
61
+
62
+
63
+
64
+
65
+
66
+
67
+ export async function connectClone() {
68
+ const connectFromEnv = connectUIEnvMap[process.env.BUILD_ENVIRONMENT];
69
+ const connectToEnv = connectUIEnvMap[process.env.BUILD_ENVIRONMENT];
70
+ if (!vaultToken || !vaultAddr) {
71
+ console.error("Error: VAULT_TOKEN and VAULT_ADDR must be set.");
72
+ throw new Error("VAULT_TOKEN and VAULT_ADDR must be set.");
73
+ }
74
+
75
+ const site = process.env.BUILD_SITE;
76
+ if (!site) {
77
+ log('Error: BUILD_SITE is not set');
78
+ process.exit(1);
79
+ }
80
+ const siteCommonVaultPath = `secret/data/${site}/common/config`;
81
+
82
+
83
+ // 2) getVaultSecrets
84
+ const secretsJson = await getVaultSecrets(siteCommonVaultPath);
85
+ if (!secretsJson.AUTH0_CLIENT_ID) {
86
+ log('Failed to retrieve secret data.');
87
+ process.exit(1);
88
+ }
89
+ const siteCommonSecrets = secretsJson;
90
+
91
+ // 3) Export secrets as environment variables
92
+ process.env.AUTH0_CLIENT_ID = siteCommonSecrets.AUTH0_CLIENT_ID;
93
+ process.env.AUTH0_CLIENT_SECRET = siteCommonSecrets.AUTH0_CLIENT_SECRET;
94
+
95
+
96
+ process.env.AUTH0_REGION_DOMAIN="us.auth0.com";
97
+
98
+ log(`BUILD_ENVIRONMENT: ${connectToEnv}`);
99
+ log(`BUILD_SITE: ${process.env.BUILD_SITE}`);
100
+ log(`AUTH0_SUBDOMAIN: ${process.env.AUTH0_SUBDOMAIN}`);
101
+ log(`AUTH0_REGION_DOMAIN: ${process.env.AUTH0_REGION_DOMAIN}`);
102
+ log(`AUTH0_CLIENT_ID: ${process.env.AUTH0_CLIENT_ID}`);
103
+
104
+ process.env.AUTH0_DOMAIN = `docupace-${process.env.BUILD_ENVIRONMENT}-${process.env.BUILD_SITE}.${process.env.AUTH0_REGION_DOMAIN}`;
105
+
106
+
107
+ const projectRoot = process.cwd();
108
+ // 4) Clone 'connect-deploy' into CONNECT_DIR
109
+
110
+
111
+ await gitCheckout('connect-deploy', process.env.CONNECT_DIR);
112
+
113
+ await gitCheckout(`${connectToEnv}-site-settings`, `${process.env.CONNECT_DIR}/${connectToEnv}-site-settings`);
114
+
115
+ // 5) Create site clone (emulating the dock.sh call)
116
+ const cloneFrom = path.join(projectRoot,process.env.CONNECT_DIR,`envs`,`${connectFromEnv}/${process.env.FROM_BUILD_SITE}`);
117
+ const cloneTo = path.join(projectRoot,process.env.CONNECT_DIR,`envs`,`${connectToEnv}/${process.env.BUILD_SITE}`);
118
+
119
+ const connectHome = path.join(projectRoot,process.env.CONNECT_DIR);
120
+ if (!(await fs.pathExists(cloneFrom))) {
121
+ log('Clone template directory not found:');
122
+ process.exit(1);
123
+ }
124
+
125
+
126
+ if (!(await fs.pathExists(cloneTo))) {
127
+ log('New site does not exist. Performing cloning...');
128
+
129
+ process.env.IMAGE_VERSION=await $`cd ${cloneFrom} && grep -E '^IMAGE_VERSION=' dock.sh | cut -f2 -d=`
130
+ log(`Image version: ${process.env.IMAGE_VERSION}` );
131
+ //await $`cd ${cloneFrom} && bash dock.sh clone ${process.env.BUILD_ENVIRONMENT} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
132
+ await (async () => {
133
+ try {
134
+ // Execute the shell command
135
+ const result = await $`cd ${cloneFrom} && bash dock.sh clone ${connectToEnv} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
136
+ console.log('Command succeeded:');
137
+ console.log('stdout:', result.stdout); // Standard output
138
+ console.log('stderr:', result.stderr); // Standard error
139
+ } catch (error) {
140
+ console.error('Command failed:');
141
+ console.error('Exit Code:', error._code); // Exit code of the command
142
+ console.error('Signal:', error._signal); // Signal that caused termination (if any)
143
+ console.error('stdout:', error._stdout); // Standard output
144
+ console.error('stderr:', error._stderr); // Standard error
145
+ }
146
+ })();
147
+
148
+
149
+ } else {
150
+ log('Site already exists. Continuing Auth0 setup...');
151
+ }
152
+
153
+
154
+ await (async () => {
155
+ try {
156
+ // Execute the shell command
157
+ const result = await $`cd ${cloneTo} && bash dock.sh getAuth0Metadata`;
158
+ console.log('Command succeeded:');
159
+ console.log('stdout:', result.stdout); // Standard output
160
+ console.log('stderr:', result.stderr); // Standard error
161
+ } catch (error) {
162
+ console.error('Command failed:');
163
+ console.error('Exit Code:', error._code); // Exit code of the command
164
+ console.error('Signal:', error._signal); // Signal that caused termination (if any)
165
+ console.error('stdout:', error._stdout); // Standard output
166
+ console.error('stderr:', error._stderr); // Standard error
167
+ }
168
+ })();
169
+
170
+
171
+ // 7) Check conf files, print logs
172
+ await $`grep "auth0" ${path.join(cloneTo, 'conf/application.conf')}`;
173
+ await $`ls -all ${path.join(cloneTo, 'conf')}`;
174
+ await $`ls -all ${path.join(cloneTo, 'conf/saml')}`;
175
+ await $`cat ${path.join(cloneTo, 'conf/saml/auth0.xml')}`;
176
+
177
+ // 8) Git add, commit, push
178
+ await $`cd ${cloneTo} && git checkout master && git pull --ff-only`;
179
+ await $`cd ${cloneTo} && git remote -v`;
180
+ await $`cd ${cloneTo} && git branch`;
181
+ await $`cd ${cloneTo} && git status`;
182
+ await $`cd ${cloneTo} && git add . ../sites.sh`;
183
+ await $`cd ${cloneTo} && git status`;
184
+
185
+ const numChanges = (
186
+ await $`cd ${cloneTo} && git diff-index HEAD`
187
+ ).stdout.split('\n').filter(Boolean).length;
188
+
189
+ if (numChanges > 0) {
190
+ const jiraTicket = process.env.JIRA_TICKET || 'NO_JIRA';
191
+ const message = `${jiraTicket} usdoc-s-builui job download_auth0_metadata for ${connectToEnv}/${process.env.BUILD_SITE}`;
192
+ log('About to commit changes to git');
193
+ await $`cd ${cloneTo} && git commit -m ${message}`;
194
+ await $`cd ${cloneTo} && git push -u origin master`;
195
+ } else {
196
+ log('No changes have been made. The site likely already has the correct configuration.');
197
+ }
198
+ }
199
+