@docupace/pipeline 1.0.4-4.6 → 1.0.4-4.8

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.
@@ -1,224 +1,224 @@
1
- import 'zx/globals'; // npm i zx
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
- import { $ } from 'zx';
5
-
6
- import { getVaultSecrets } from '../auth0/vault.js';
7
-
8
- process.env.COMMON_VAULT_PATH =
9
- process.env.COMMON_VAULT_PATH || 'secret/data/common/config';
10
- process.env.VAULT_SKIP_VERIFY = process.env.VAULT_SKIP_VERIFY || 'true';
11
- process.env.CONNECT_DIR = process.env.CONNECT_DIR || 'connect';
12
- const vaultToken = process.env.VAULT_TOKEN;
13
- const vaultAddr = process.env.VAULT_ADDR;
14
-
15
- const connectUIEnvMap = {
16
- dev: 'dev',
17
- qa: 'preprod',
18
- stage: 'stg',
19
- uat: 'uat',
20
- prod: 'prod-www3',
21
- };
22
-
23
-
24
- const siteSettingsEnvMap = {
25
- dev: 'dev',
26
- preprod: 'preprod',
27
- qa: 'preprod',
28
- stage: 'staging',
29
- stg: 'staging',
30
- uat: 'uat',
31
- prd: 'prod',
32
- prod: 'prod',
33
- 'prod-www3': 'prod',
34
- 'prod-las': 'prod',
35
- 'prod-lax': 'prod',
36
- 'prod-athene': 'prod',
37
- 'prod-staging': 'prod',
38
- };
39
-
40
- const idpEnvMap = {
41
- dev: 'dev',
42
- preprod: 'qa',
43
- qa: 'qa',
44
- stage: 'stage',
45
- stg: 'stage',
46
- uat: 'uat',
47
- prd: 'prod',
48
- prod: 'prod',
49
- 'prod-www3': 'prod',
50
- 'prod-las': 'prod',
51
- 'prod-lax': 'prod',
52
- 'prod-athene': 'prod',
53
- 'prod-staging': 'prod',
54
- };
55
-
56
- function log(msg) {
57
- console.log(`[*] ${msg}`);
58
- }
59
-
60
- /* --------------------------------
61
- * 1. GIT CHECKOUT
62
- * -------------------------------- */
63
- async function gitCheckout(repository, destDir, branch = 'master') {
64
- if (!(await fs.pathExists(destDir))) {
65
- log(`Directory ${destDir} does not exist. Cloning repository...`);
66
- } else {
67
- log(`Directory ${destDir} exists. Removing it...`);
68
- await fs.remove(destDir);
69
- log(`Cloning ${destDir} repository...`);
70
- }
71
-
72
- const username = process.env.BITBUCKET_USERNAME;
73
- const password = process.env.BITBUCKET_APP_PASSWORD;
74
-
75
- // Construct clone command
76
- const cloneUrl = `https://${username}:${password}@bitbucket.org/dp-cloud/${repository}.git`;
77
-
78
- log(`Perform cloning`);
79
- await $`git clone --branch=${branch} --depth 1 ${cloneUrl} ${destDir}`;
80
- }
81
-
82
- export async function connectClone() {
83
- // const connectFromEnv = connectUIEnvMap[process.env.FROM_BUILD_ENVIRONMENT];
84
- const connectFromEnv = process.env.FROM_BUILD_ENVIRONMENT;
85
- const connectToEnv = process.env.BUILD_ENVIRONMENT;
86
-
87
- if (!vaultToken || !vaultAddr) {
88
- console.error('Error: VAULT_TOKEN and VAULT_ADDR must be set.');
89
- throw new Error('VAULT_TOKEN and VAULT_ADDR must be set.');
90
- }
91
-
92
- const site = process.env.BUILD_SITE;
93
- if (!site) {
94
- log('Error: BUILD_SITE is not set');
95
- process.exit(1);
96
- }
97
- const siteCommonVaultPath = `secret/data/${site}/common/config`;
98
-
99
- // 2) getVaultSecrets
100
- const secretsJson = await getVaultSecrets(siteCommonVaultPath);
101
- if (!secretsJson.AUTH0_CLIENT_ID) {
102
- log('Failed to retrieve secret data.');
103
- process.exit(1);
104
- }
105
- const siteCommonSecrets = secretsJson;
106
-
107
- // 3) Export secrets as environment variables
108
- process.env.AUTH0_CLIENT_ID = siteCommonSecrets.AUTH0_CLIENT_ID;
109
- process.env.AUTH0_CLIENT_SECRET = siteCommonSecrets.AUTH0_CLIENT_SECRET;
110
-
111
- process.env.AUTH0_REGION_DOMAIN = 'us.auth0.com';
112
-
113
- log(`BUILD_ENVIRONMENT: ${connectToEnv}`);
114
- log(`BUILD_SITE: ${process.env.BUILD_SITE}`);
115
- log(`AUTH0_SUBDOMAIN: ${process.env.AUTH0_SUBDOMAIN}`);
116
- log(`AUTH0_REGION_DOMAIN: ${process.env.AUTH0_REGION_DOMAIN}`);
117
- log(`AUTH0_CLIENT_ID: ${process.env.AUTH0_CLIENT_ID}`);
118
-
119
- process.env.AUTH0_DOMAIN = `docupace-${idpEnvMap[process.env.BUILD_ENVIRONMENT]}-${process.env.BUILD_SITE}.${process.env.AUTH0_REGION_DOMAIN}`;
120
-
121
- const projectRoot = process.cwd();
122
- // 4) Clone 'connect-deploy' into CONNECT_DIR
123
-
124
- await gitCheckout('connect-deploy', process.env.CONNECT_DIR);
125
-
126
- await gitCheckout(
127
- `${siteSettingsEnvMap[connectToEnv]}-site-settings`,
128
- `${process.env.CONNECT_DIR}/${siteSettingsEnvMap[connectToEnv]}-site-settings`,
129
- );
130
-
131
- // 5) Create site clone (emulating the dock.sh call)
132
- const cloneFrom = path.join(
133
- projectRoot,
134
- process.env.CONNECT_DIR,
135
- `envs`,
136
- `${connectFromEnv}/${process.env.FROM_BUILD_SITE}`,
137
- );
138
- const cloneTo = path.join(
139
- projectRoot,
140
- process.env.CONNECT_DIR,
141
- `envs`,
142
- `${connectToEnv}/${process.env.BUILD_SITE}`,
143
- );
144
-
145
- if (!(await fs.pathExists(cloneFrom))) {
146
- log('Clone template directory not found:');
147
- process.exit(1);
148
- }
149
-
150
- if (!(await fs.pathExists(cloneTo))) {
151
- log('New site does not exist. Performing cloning...');
152
-
153
- process.env.IMAGE_VERSION =
154
- await $`cd ${cloneFrom} && grep -E '^IMAGE_VERSION=' dock.sh | cut -f2 -d=`;
155
- log(`Image version: ${process.env.IMAGE_VERSION}`);
156
- //await $`cd ${cloneFrom} && bash dock.sh clone ${process.env.BUILD_ENVIRONMENT} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
157
- await (async () => {
158
- try {
159
- // Execute the shell command
160
- const result =
161
- await $`cd ${cloneFrom} && bash dock.sh clone ${connectToEnv} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
162
- await $`cd ${cloneTo} && git checkout master && git pull --ff-only`;
163
- await $`cd ${cloneTo} && git remote -v`;
164
- await $`cd ${cloneTo} && git branch`;
165
- await $`cd ${cloneTo} && git status`;
166
- await $`cd ${cloneTo} && git add . ../sites.sh`;
167
-
168
- console.log('Command succeeded:');
169
- console.log('stdout:', result.stdout); // Standard output
170
- console.log('stderr:', result.stderr); // Standard error
171
- } catch (error) {
172
- console.error('Command failed:');
173
- console.error('Exit Code:', error._code); // Exit code of the command
174
- console.error('Signal:', error._signal); // Signal that caused termination (if any)
175
- console.error('stdout:', error._stdout); // Standard output
176
- console.error('stderr:', error._stderr); // Standard error
177
- }
178
- })();
179
- } else {
180
- log('Site already exists. Continuing Auth0 setup...');
181
- }
182
-
183
- await (async () => {
184
- try {
185
- // Execute the shell command
186
- const result = await $`cd ${cloneTo} && bash dock.sh getAuth0Metadata`;
187
- console.log('Command succeeded:');
188
- console.log('stdout:', result.stdout); // Standard output
189
- console.log('stderr:', result.stderr); // Standard error
190
- } catch (error) {
191
- console.error('Command failed:');
192
- console.error('Exit Code:', error._code); // Exit code of the command
193
- console.error('Signal:', error._signal); // Signal that caused termination (if any)
194
- console.error('stdout:', error._stdout); // Standard output
195
- console.error('stderr:', error._stderr); // Standard error
196
- }
197
- })();
198
-
199
- // 7) Check conf files, print logs
200
- await $`grep "auth0" ${path.join(cloneTo, 'conf/application.conf')}`;
201
- await $`ls -all ${path.join(cloneTo, 'conf')}`;
202
- await $`ls -all ${path.join(cloneTo, 'conf/saml')}`;
203
- await $`cat ${path.join(cloneTo, 'conf/saml/auth0.xml')}`;
204
-
205
- // 8) Git add, commit, push
206
- await $`cd ${cloneTo} && git add ./conf/application.conf ./conf/saml/auth0.xml`;
207
- await $`cd ${cloneTo} && git status`;
208
-
209
- const numChanges = (await $`cd ${cloneTo} && git diff-index HEAD`).stdout
210
- .split('\n')
211
- .filter(Boolean).length;
212
-
213
- if (numChanges > 0) {
214
- const jiraTicket = process.env.JIRA_TICKET || 'NO_JIRA';
215
- const message = `${jiraTicket} usdoc-s-builui job download_auth0_metadata for ${connectToEnv}/${process.env.BUILD_SITE}`;
216
- log('About to commit changes to git');
217
- await $`cd ${cloneTo} && git commit -m ${message}`;
218
- await $`cd ${cloneTo} && git push -u origin master`;
219
- } else {
220
- log(
221
- 'No changes have been made. The site likely already has the correct configuration.',
222
- );
223
- }
224
- }
1
+ import 'zx/globals'; // npm i zx
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import { $ } from 'zx';
5
+
6
+ import { getVaultSecrets } from '../auth0/vault.js';
7
+
8
+ process.env.COMMON_VAULT_PATH =
9
+ process.env.COMMON_VAULT_PATH || 'secret/data/common/config';
10
+ process.env.VAULT_SKIP_VERIFY = process.env.VAULT_SKIP_VERIFY || 'true';
11
+ process.env.CONNECT_DIR = process.env.CONNECT_DIR || 'connect';
12
+ const vaultToken = process.env.VAULT_TOKEN;
13
+ const vaultAddr = process.env.VAULT_ADDR;
14
+
15
+ const connectUIEnvMap = {
16
+ dev: 'dev',
17
+ qa: 'preprod',
18
+ stage: 'stg',
19
+ uat: 'uat',
20
+ prod: 'prod-www3',
21
+ };
22
+
23
+
24
+ const siteSettingsEnvMap = {
25
+ dev: 'dev',
26
+ preprod: 'preprod',
27
+ qa: 'preprod',
28
+ stage: 'staging',
29
+ stg: 'staging',
30
+ uat: 'uat',
31
+ prd: 'prod',
32
+ prod: 'prod',
33
+ 'prod-www3': 'prod',
34
+ 'prod-las': 'prod',
35
+ 'prod-lax': 'prod',
36
+ 'prod-athene': 'prod',
37
+ 'prod-staging': 'prod',
38
+ };
39
+
40
+ const idpEnvMap = {
41
+ dev: 'dev',
42
+ preprod: 'qa',
43
+ qa: 'qa',
44
+ stage: 'stage',
45
+ stg: 'stage',
46
+ uat: 'uat',
47
+ prd: 'prod',
48
+ prod: 'prod',
49
+ 'prod-www3': 'prod',
50
+ 'prod-las': 'prod',
51
+ 'prod-lax': 'prod',
52
+ 'prod-athene': 'prod',
53
+ 'prod-staging': 'prod',
54
+ };
55
+
56
+ function log(msg) {
57
+ console.log(`[*] ${msg}`);
58
+ }
59
+
60
+ /* --------------------------------
61
+ * 1. GIT CHECKOUT
62
+ * -------------------------------- */
63
+ async function gitCheckout(repository, destDir, branch = 'master') {
64
+ if (!(await fs.pathExists(destDir))) {
65
+ log(`Directory ${destDir} does not exist. Cloning repository...`);
66
+ } else {
67
+ log(`Directory ${destDir} exists. Removing it...`);
68
+ await fs.remove(destDir);
69
+ log(`Cloning ${destDir} repository...`);
70
+ }
71
+
72
+ const username = process.env.BITBUCKET_USERNAME;
73
+ const password = process.env.BITBUCKET_APP_PASSWORD;
74
+
75
+ // Construct clone command
76
+ const cloneUrl = `https://${username}:${password}@bitbucket.org/dp-cloud/${repository}.git`;
77
+
78
+ log(`Perform cloning`);
79
+ await $`git clone --branch=${branch} --depth 1 ${cloneUrl} ${destDir}`;
80
+ }
81
+
82
+ export async function connectClone() {
83
+ // const connectFromEnv = connectUIEnvMap[process.env.FROM_BUILD_ENVIRONMENT];
84
+ const connectFromEnv = process.env.FROM_BUILD_ENVIRONMENT;
85
+ const connectToEnv = process.env.BUILD_ENVIRONMENT;
86
+
87
+ if (!vaultToken || !vaultAddr) {
88
+ console.error('Error: VAULT_TOKEN and VAULT_ADDR must be set.');
89
+ throw new Error('VAULT_TOKEN and VAULT_ADDR must be set.');
90
+ }
91
+
92
+ const site = process.env.BUILD_SITE;
93
+ if (!site) {
94
+ log('Error: BUILD_SITE is not set');
95
+ process.exit(1);
96
+ }
97
+ const siteCommonVaultPath = `secret/data/${site}/common/config`;
98
+
99
+ // 2) getVaultSecrets
100
+ const secretsJson = await getVaultSecrets(siteCommonVaultPath);
101
+ if (!secretsJson.AUTH0_CLIENT_ID) {
102
+ log('Failed to retrieve secret data.');
103
+ process.exit(1);
104
+ }
105
+ const siteCommonSecrets = secretsJson;
106
+
107
+ // 3) Export secrets as environment variables
108
+ process.env.AUTH0_CLIENT_ID = siteCommonSecrets.AUTH0_CLIENT_ID;
109
+ process.env.AUTH0_CLIENT_SECRET = siteCommonSecrets.AUTH0_CLIENT_SECRET;
110
+
111
+ process.env.AUTH0_REGION_DOMAIN = 'us.auth0.com';
112
+
113
+ log(`BUILD_ENVIRONMENT: ${connectToEnv}`);
114
+ log(`BUILD_SITE: ${process.env.BUILD_SITE}`);
115
+ log(`AUTH0_SUBDOMAIN: ${process.env.AUTH0_SUBDOMAIN}`);
116
+ log(`AUTH0_REGION_DOMAIN: ${process.env.AUTH0_REGION_DOMAIN}`);
117
+ log(`AUTH0_CLIENT_ID: ${process.env.AUTH0_CLIENT_ID}`);
118
+
119
+ process.env.AUTH0_DOMAIN = `docupace-${idpEnvMap[process.env.BUILD_ENVIRONMENT]}-${process.env.BUILD_SITE}.${process.env.AUTH0_REGION_DOMAIN}`;
120
+
121
+ const projectRoot = process.cwd();
122
+ // 4) Clone 'connect-deploy' into CONNECT_DIR
123
+
124
+ await gitCheckout('connect-deploy', process.env.CONNECT_DIR);
125
+
126
+ await gitCheckout(
127
+ `${siteSettingsEnvMap[connectToEnv]}-site-settings`,
128
+ `${process.env.CONNECT_DIR}/${siteSettingsEnvMap[connectToEnv]}-site-settings`,
129
+ );
130
+
131
+ // 5) Create site clone (emulating the dock.sh call)
132
+ const cloneFrom = path.join(
133
+ projectRoot,
134
+ process.env.CONNECT_DIR,
135
+ `envs`,
136
+ `${connectFromEnv}/${process.env.FROM_BUILD_SITE}`,
137
+ );
138
+ const cloneTo = path.join(
139
+ projectRoot,
140
+ process.env.CONNECT_DIR,
141
+ `envs`,
142
+ `${connectToEnv}/${process.env.BUILD_SITE}`,
143
+ );
144
+
145
+ if (!(await fs.pathExists(cloneFrom))) {
146
+ log('Clone template directory not found:');
147
+ process.exit(1);
148
+ }
149
+
150
+ if (!(await fs.pathExists(cloneTo))) {
151
+ log('New site does not exist. Performing cloning...');
152
+
153
+ process.env.IMAGE_VERSION =
154
+ await $`cd ${cloneFrom} && grep -E '^IMAGE_VERSION=' dock.sh | cut -f2 -d=`;
155
+ log(`Image version: ${process.env.IMAGE_VERSION}`);
156
+ //await $`cd ${cloneFrom} && bash dock.sh clone ${process.env.BUILD_ENVIRONMENT} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
157
+ await (async () => {
158
+ try {
159
+ // Execute the shell command
160
+ const result =
161
+ await $`cd ${cloneFrom} && bash dock.sh clone ${connectToEnv} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
162
+ await $`cd ${cloneTo} && git checkout master && git pull --ff-only`;
163
+ await $`cd ${cloneTo} && git remote -v`;
164
+ await $`cd ${cloneTo} && git branch`;
165
+ await $`cd ${cloneTo} && git status`;
166
+ await $`cd ${cloneTo} && git add . ../sites.sh`;
167
+
168
+ console.log('Command succeeded:');
169
+ console.log('stdout:', result.stdout); // Standard output
170
+ console.log('stderr:', result.stderr); // Standard error
171
+ } catch (error) {
172
+ console.error('Command failed:');
173
+ console.error('Exit Code:', error._code); // Exit code of the command
174
+ console.error('Signal:', error._signal); // Signal that caused termination (if any)
175
+ console.error('stdout:', error._stdout); // Standard output
176
+ console.error('stderr:', error._stderr); // Standard error
177
+ }
178
+ })();
179
+ } else {
180
+ log('Site already exists. Continuing Auth0 setup...');
181
+ }
182
+
183
+ await (async () => {
184
+ try {
185
+ // Execute the shell command
186
+ const result = await $`cd ${cloneTo} && bash dock.sh getAuth0Metadata`;
187
+ console.log('Command succeeded:');
188
+ console.log('stdout:', result.stdout); // Standard output
189
+ console.log('stderr:', result.stderr); // Standard error
190
+ } catch (error) {
191
+ console.error('Command failed:');
192
+ console.error('Exit Code:', error._code); // Exit code of the command
193
+ console.error('Signal:', error._signal); // Signal that caused termination (if any)
194
+ console.error('stdout:', error._stdout); // Standard output
195
+ console.error('stderr:', error._stderr); // Standard error
196
+ }
197
+ })();
198
+
199
+ // 7) Check conf files, print logs
200
+ await $`grep "auth0" ${path.join(cloneTo, 'conf/application.conf')}`;
201
+ await $`ls -all ${path.join(cloneTo, 'conf')}`;
202
+ await $`ls -all ${path.join(cloneTo, 'conf/saml')}`;
203
+ await $`cat ${path.join(cloneTo, 'conf/saml/auth0.xml')}`;
204
+
205
+ // 8) Git add, commit, push
206
+ await $`cd ${cloneTo} && git add ./conf/application.conf ./conf/saml/auth0.xml`;
207
+ await $`cd ${cloneTo} && git status`;
208
+
209
+ const numChanges = (await $`cd ${cloneTo} && git diff-index HEAD`).stdout
210
+ .split('\n')
211
+ .filter(Boolean).length;
212
+
213
+ if (numChanges > 0) {
214
+ const jiraTicket = process.env.JIRA_TICKET || 'NO_JIRA';
215
+ const message = `${jiraTicket} usdoc-s-builui job download_auth0_metadata for ${connectToEnv}/${process.env.BUILD_SITE}`;
216
+ log('About to commit changes to git');
217
+ await $`cd ${cloneTo} && git commit -m ${message}`;
218
+ await $`cd ${cloneTo} && git push -u origin master`;
219
+ } else {
220
+ log(
221
+ 'No changes have been made. The site likely already has the correct configuration.',
222
+ );
223
+ }
224
+ }
@@ -1,71 +1,71 @@
1
- import { $ } from 'zx';
2
- import fs from 'fs-extra';
3
- import path from 'path';
4
-
5
- export async function haproxySync() {
6
- const cluster = process.env.HAPROXY_CLUSTER;
7
- if (cluster !== 'preprod' && cluster !== 'stage' && cluster !== 'prod-www3') {
8
- console.log('Error: Cluster must be preprod or stage');
9
- process.exit(1);
10
- }
11
-
12
- const repoPath = '/root/repo/docupace-ansible';
13
- const inventory = path.join(repoPath, `inventories/${cluster}/inventory`);
14
-
15
- // Create haproxy.sh
16
- const cluserHostMap = {
17
- preprod: {
18
- host: '10.10.28.198',
19
- branch: 'master',
20
- },
21
- stage: {
22
- host: '10.12.28.10',
23
- branch: 'INFP-6565-haproxy-prod-implementation',
24
- },
25
- 'prod-www3': {
26
- host: '10.13.28.45',
27
- branch: 'INFP-6565-haproxy-prod-implementation',
28
- },
29
- };
30
-
31
- const scriptContent = `
32
- #!/bin/bash
33
-
34
- [[ ! -f ${inventory} ]] && ( echo "Alert: no inventory file: ${inventory}" ; exit 1 )
35
- cd ${repoPath}
36
- pwd
37
- git stash
38
- git fetch --all
39
- git pull origin master
40
- git checkout ${cluserHostMap[cluster].branch}
41
- git submodule update --remote
42
- git submodule foreach --recursive git checkout master
43
- git submodule foreach --recursive git pull origin master
44
-
45
- ansible-playbook -i inventories/${cluster}/inventory haproxy.yml -e "cluster=${cluster} -e build=true"
46
-
47
- echo "proceeding"
48
- echo "committing changes"
49
- git add ${cluster}-haproxy.cfg
50
- git commit -m "Sync haproxy"
51
- git push origin master
52
- `;
53
-
54
- await fs.writeFile('haproxy.sh', scriptContent);
55
-
56
- // Private key
57
- const haproxyPrivateKey = process.env.HAPROXY_PRIVATE_KEY;
58
- if (!haproxyPrivateKey) {
59
- console.log('Error: HAPROXY_PRIVATE_KEY not set.');
60
- process.exit(1);
61
- }
62
-
63
- await fs.writeFile('private.key', Buffer.from(haproxyPrivateKey, 'base64'));
64
- await fs.chmod('private.key', 0o600);
65
-
66
- // Copy script to remote
67
- await $`scp -i private.key -o StrictHostKeyChecking=no haproxy.sh root@${cluserHostMap[cluster].host}:/tmp/haproxy.sh`;
68
-
69
- // Execute script on remote
70
- await $`ssh -i private.key -o StrictHostKeyChecking=no root@${cluserHostMap[cluster].host} "bash /tmp/haproxy.sh"`;
71
- }
1
+ import { $ } from 'zx';
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+
5
+ export async function haproxySync() {
6
+ const cluster = process.env.HAPROXY_CLUSTER;
7
+ if (cluster !== 'preprod' && cluster !== 'stage' && cluster !== 'prod-www3') {
8
+ console.log('Error: Cluster must be preprod or stage');
9
+ process.exit(1);
10
+ }
11
+
12
+ const repoPath = '/root/repo/docupace-ansible';
13
+ const inventory = path.join(repoPath, `inventories/${cluster}/inventory`);
14
+
15
+ // Create haproxy.sh
16
+ const cluserHostMap = {
17
+ preprod: {
18
+ host: '10.10.28.198',
19
+ branch: 'master',
20
+ },
21
+ stage: {
22
+ host: '10.12.28.10',
23
+ branch: 'INFP-6565-haproxy-prod-implementation',
24
+ },
25
+ 'prod-www3': {
26
+ host: '10.13.28.45',
27
+ branch: 'INFP-6565-haproxy-prod-implementation',
28
+ },
29
+ };
30
+
31
+ const scriptContent = `
32
+ #!/bin/bash
33
+
34
+ [[ ! -f ${inventory} ]] && ( echo "Alert: no inventory file: ${inventory}" ; exit 1 )
35
+ cd ${repoPath}
36
+ pwd
37
+ git stash
38
+ git fetch --all
39
+ git pull origin master
40
+ git checkout ${cluserHostMap[cluster].branch}
41
+ git submodule update --remote
42
+ git submodule foreach --recursive git checkout master
43
+ git submodule foreach --recursive git pull origin master
44
+
45
+ ansible-playbook -i inventories/${cluster}/inventory haproxy.yml -e "cluster=${cluster} -e build=true"
46
+
47
+ echo "proceeding"
48
+ echo "committing changes"
49
+ git add ${cluster}-haproxy.cfg
50
+ git commit -m "Sync haproxy"
51
+ git push origin master
52
+ `;
53
+
54
+ await fs.writeFile('haproxy.sh', scriptContent);
55
+
56
+ // Private key
57
+ const haproxyPrivateKey = process.env.HAPROXY_PRIVATE_KEY;
58
+ if (!haproxyPrivateKey) {
59
+ console.log('Error: HAPROXY_PRIVATE_KEY not set.');
60
+ process.exit(1);
61
+ }
62
+
63
+ await fs.writeFile('private.key', Buffer.from(haproxyPrivateKey, 'base64'));
64
+ await fs.chmod('private.key', 0o600);
65
+
66
+ // Copy script to remote
67
+ await $`scp -i private.key -o StrictHostKeyChecking=no haproxy.sh root@${cluserHostMap[cluster].host}:/tmp/haproxy.sh`;
68
+
69
+ // Execute script on remote
70
+ await $`ssh -i private.key -o StrictHostKeyChecking=no root@${cluserHostMap[cluster].host} "bash /tmp/haproxy.sh"`;
71
+ }