@docupace/pipeline 1.0.6 → 1.0.7-7.micro-cli

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.
Files changed (68) hide show
  1. package/.prettierrc.cjs +12 -12
  2. package/README.md +136 -0
  3. package/bin/azuread_update_callbacks_for_app.sh +58 -0
  4. package/bin/next-changeset-validate.sh +8 -8
  5. package/bitbucket-pipelines.yml +60 -0
  6. package/eslint.config.js +49 -26
  7. package/jest.config.js +15 -0
  8. package/next/changeset.sh +75 -75
  9. package/next/copy.sh +34 -34
  10. package/next/deploy.sh +40 -40
  11. package/next/execute.sh +123 -117
  12. package/next/sonar.sh +23 -23
  13. package/package.json +22 -7
  14. package/src/auth0/alias.js +79 -0
  15. package/src/auth0/alias.test.js +172 -0
  16. package/src/auth0/cli.js +82 -0
  17. package/src/auth0/configure.js +902 -0
  18. package/src/auth0/configure.test.js +167 -0
  19. package/src/auth0/export.js +48 -0
  20. package/src/auth0/export.test.js +103 -0
  21. package/src/auth0/metadata.js +141 -0
  22. package/src/auth0/metadata.test.js +186 -0
  23. package/src/auth0/vault.js +60 -0
  24. package/src/auth0/vault.test.js +134 -0
  25. package/src/changeset/changelog-wiki.js +328 -0
  26. package/src/changeset/changeset-config.js +34 -0
  27. package/src/changeset/cli.js +237 -281
  28. package/src/changeset/create.js +215 -0
  29. package/src/changeset/package-util.js +87 -0
  30. package/src/changeset/util.js +43 -0
  31. package/src/changeset/validate.js +91 -47
  32. package/src/changeset/version.js +102 -0
  33. package/src/jenkins/setParams.groovy +58 -59
  34. package/src/lib/merge-driver.js +204 -0
  35. package/src/merge/cli-merge-all.js +507 -0
  36. package/src/merge/cli-merge.js +492 -0
  37. package/src/merge/cli-resolve.js +399 -0
  38. package/src/merge/cli.js +38 -0
  39. package/src/merge/merge-changelog.js +87 -0
  40. package/src/merge/merge-package.js +106 -0
  41. package/src/merge/merge-types.js +82 -0
  42. package/src/merge/pr.js +231 -0
  43. package/src/micro/cli.js +71 -0
  44. package/src/micro/ms-deploy.js +273 -0
  45. package/src/micro/ms-publish.js +186 -0
  46. package/src/next/alias.js +53 -0
  47. package/src/next/apache.js +81 -0
  48. package/src/next/cli.js +111 -15
  49. package/src/next/config.js +137 -72
  50. package/src/next/connect.js +226 -0
  51. package/src/next/copy.js +61 -30
  52. package/src/next/deploy.js +633 -312
  53. package/src/next/git-to-semver.js +79 -0
  54. package/src/next/haproxy.js +76 -0
  55. package/src/next/jenkins.js +123 -88
  56. package/src/next/jira.js +84 -0
  57. package/src/next/logger.js +17 -0
  58. package/src/next/pipline.js +114 -115
  59. package/src/next/publish.js +71 -48
  60. package/src/next/pull.js +7 -7
  61. package/src/next/sonar.js +23 -23
  62. package/src/next/test.js +5 -0
  63. package/src/next/util.js +93 -0
  64. package/src/next/vault.js +45 -0
  65. package/terraform/apply.sh +37 -0
  66. package/terraform/init.sh +72 -0
  67. package/terraform/plan.sh +76 -0
  68. package/terraform/validate.sh +17 -0
@@ -0,0 +1,186 @@
1
+ import { $ } from '../next/logger.js';
2
+
3
+ /**
4
+ * Publish Docker images for microservices with flexible naming
5
+ * @param {string} gitSha - Git commit SHA
6
+ * @param {Object} options - Configuration options
7
+ * @param {string} options.imageName - Docker image name (e.g., 'swp')
8
+ * @param {string} options.registryUrl - JFrog registry URL
9
+ * @param {string} options.repoName - Repository name in JFrog
10
+ * @param {string} options.username - JFrog username
11
+ * @param {string} options.password - JFrog password
12
+ * @param {string} options.buildNumber - Build number
13
+ */
14
+ export async function publishMicroservice(serviceName, options = {}) {
15
+ // Use environment variables as defaults, but allow overrides
16
+
17
+ const gitSha = (await $`git log --pretty=format:'%h' -n 1 `).stdout.trim();
18
+
19
+ const config = {
20
+ imageName: serviceName,
21
+ registryUrl: options.registryUrl || process.env.JF_REGISTRY_URL,
22
+ repoName: options.repoName || process.env.JF_REGISTRY_REPO_NAME,
23
+ username: options.username || process.env.JF_REGISTRY_USER_DEV,
24
+ password: options.password || process.env.JF_REGISTRY_PASSWORD_DEV,
25
+ buildNumber: options.buildNumber || process.env.BITBUCKET_BUILD_NUMBER,
26
+ tag: options.tag || process.env.VERSION_TAG,
27
+ };
28
+
29
+ // Validate required fields
30
+ if (!config.imageName) {
31
+ throw new Error(
32
+ 'Image name is required. Set IMAGE_NAME or APP_NAME environment variable.',
33
+ );
34
+ }
35
+
36
+ console.log('=== Docker Image Publishing Configuration ===');
37
+ console.log(`Image Name: ${config.imageName}`);
38
+ console.log(`Git SHA: ${gitSha}`);
39
+ console.log(`Build Number: ${config.buildNumber}`);
40
+ console.log(`Version Tag: ${config.tag || 'none'}`);
41
+ console.log(`Registry: ${config.registryUrl}/${config.repoName}`);
42
+ console.log('==========================================');
43
+
44
+ const registryPath = `${config.registryUrl}/${config.repoName}`;
45
+ const SHA_IMAGE_NAME = `${config.imageName}:sha-${gitSha}`;
46
+
47
+ // Docker login
48
+ await $`echo ${config.password} | docker login --username ${config.username} --password-stdin ${config.registryUrl}`;
49
+
50
+ try {
51
+ // Build the image if it doesn't exist locally
52
+ const imageExists = await checkLocalImage(SHA_IMAGE_NAME);
53
+ if (!imageExists) {
54
+ console.log(`Building Docker image ${SHA_IMAGE_NAME}...`);
55
+ await $`docker build -t ${SHA_IMAGE_NAME} .`;
56
+ }
57
+
58
+ // Array to track all tags we're pushing
59
+ const tagsToPush = [];
60
+
61
+ // 1. Push SHA tag
62
+ const shaTag = `${registryPath}/${SHA_IMAGE_NAME}`;
63
+ console.log(`Tagging and pushing SHA: ${shaTag}`);
64
+ await $`docker tag ${SHA_IMAGE_NAME} ${shaTag}`;
65
+ await $`docker push ${shaTag}`;
66
+ tagsToPush.push(SHA_IMAGE_NAME);
67
+
68
+ // 2. Push build number tag
69
+ if (config.buildNumber) {
70
+ const BUILD_IMAGE_NAME = `${config.imageName}:build-${config.buildNumber}`;
71
+ const buildTag = `${registryPath}/${BUILD_IMAGE_NAME}`;
72
+ console.log(`Tagging and pushing build: ${buildTag}`);
73
+ await $`docker tag ${SHA_IMAGE_NAME} ${buildTag}`;
74
+ await $`docker push ${buildTag}`;
75
+ tagsToPush.push(BUILD_IMAGE_NAME);
76
+ }
77
+
78
+ // 3. Push version tag (this is what ArgoCD needs!)
79
+ if (config.tag) {
80
+ // Handle various tag formats
81
+ let version = config.tag;
82
+
83
+ // If tag contains @, extract version after it
84
+ if (version.includes('@')) {
85
+ version = 'v' + version.split('@')[1];
86
+ }
87
+
88
+ // Ensure version starts with 'v' if it's a semver without it
89
+ if (/^\d+\.\d+\.\d+/.test(version) && !version.startsWith('v')) {
90
+ version = 'v' + version;
91
+ }
92
+
93
+ const VERSION_IMAGE_NAME = `${config.imageName}:${version}`;
94
+ const versionTag = `${registryPath}/${VERSION_IMAGE_NAME}`;
95
+
96
+ console.log(`Tagging and pushing version: ${versionTag}`);
97
+ await $`docker tag ${SHA_IMAGE_NAME} ${versionTag}`;
98
+ await $`docker push ${versionTag}`;
99
+ tagsToPush.push(VERSION_IMAGE_NAME);
100
+
101
+ // Also push 'latest' tag when we have a version
102
+ const LATEST_IMAGE_NAME = `${config.imageName}:latest`;
103
+ const latestTag = `${registryPath}/${LATEST_IMAGE_NAME}`;
104
+ console.log(`Tagging and pushing latest: ${latestTag}`);
105
+ await $`docker tag ${SHA_IMAGE_NAME} ${latestTag}`;
106
+ await $`docker push ${latestTag}`;
107
+ tagsToPush.push(LATEST_IMAGE_NAME);
108
+ }
109
+
110
+ // 4. Check for git tags at current commit
111
+ try {
112
+ const gitTags = (await $`git tag --points-at HEAD`).stdout
113
+ .trim()
114
+ .split('\n')
115
+ .filter(Boolean);
116
+
117
+ if (gitTags.length > 0) {
118
+ console.log(`Found git tags at HEAD: ${gitTags.join(', ')}`);
119
+
120
+ for (const gitTag of gitTags) {
121
+ // Skip if we already handled this tag above
122
+ if (gitTag === config.tag) continue;
123
+
124
+ let version = gitTag;
125
+ if (version.includes('@')) {
126
+ version = 'v' + version.split('@')[1];
127
+ }
128
+
129
+ const TAG_IMAGE_NAME = `${config.imageName}:${version}`;
130
+ const gitTagPath = `${registryPath}/${TAG_IMAGE_NAME}`;
131
+
132
+ console.log(`Tagging and pushing git tag: ${gitTagPath}`);
133
+ await $`docker tag ${SHA_IMAGE_NAME} ${gitTagPath}`;
134
+ await $`docker push ${gitTagPath}`;
135
+ tagsToPush.push(TAG_IMAGE_NAME);
136
+ }
137
+ }
138
+ } catch (e) {
139
+ console.log('No git tags found at HEAD or error checking tags', e);
140
+ }
141
+
142
+ console.log('\n✅ Docker image published successfully!');
143
+ console.log('=== Summary of pushed tags ===');
144
+ tagsToPush.forEach((tag) => console.log(` ✓ ${tag}`));
145
+ console.log('==============================\n');
146
+
147
+ // Verify the version tag if we expect one
148
+ if (config.tag) {
149
+ const version = config.tag.includes('@')
150
+ ? 'v' + config.tag.split('@')[1]
151
+ : config.tag;
152
+ const expectedTag = `${registryPath}/${config.imageName}:${version}`;
153
+ console.log(`Verifying version tag exists: ${expectedTag}`);
154
+ try {
155
+ await $`docker manifest inspect ${expectedTag}`;
156
+ console.log('✅ Version tag verified in registry!');
157
+ } catch (e) {
158
+ console.error('❌ WARNING: Could not verify version tag in registry!');
159
+ console.error('ArgoCD may fail to pull this image.', e);
160
+ }
161
+ }
162
+ } catch (error) {
163
+ console.error('Error during image publishing:', error);
164
+ throw error;
165
+ } finally {
166
+ // Always logout
167
+ await $`docker logout ${config.registryUrl}`;
168
+ }
169
+ }
170
+
171
+ async function checkLocalImage(imageName) {
172
+ try {
173
+ $.verbose = false;
174
+ await $`docker image inspect ${imageName}`;
175
+ return true;
176
+ } catch {
177
+ return false;
178
+ } finally {
179
+ $.verbose = true;
180
+ }
181
+ }
182
+
183
+ // Backward compatibility wrapper
184
+ export async function publishWithDefaults(gitSha) {
185
+ return publishMicroservice(gitSha);
186
+ }
@@ -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,81 @@
1
+ import fs from 'fs-extra';
2
+ import { $ } from 'zx';
3
+
4
+ function log(msg) {
5
+ console.log(`[*] ${msg}`);
6
+ }
7
+
8
+ export async function addApacheSite() {
9
+ if (
10
+ !process.env.ENVIRONMENT ||
11
+ !['dev', 'qa', 'uat', 'stage', 'www3'].includes(process.env.ENVIRONMENT)
12
+ ) {
13
+ log('Error: wront ENVIRONMENT');
14
+ process.exit(1);
15
+ }
16
+ if (!process.env.SITE) {
17
+ log('Error: SITE cannot be empty.');
18
+ process.exit(1);
19
+ }
20
+
21
+ const apacheEnvHostMap = {
22
+ dev: {
23
+ host1: 'dev-apalb01a.corp.docupace.com',
24
+ host2: 'dev-apalb01b.corp.docupace.com',
25
+ repo: 'iis-preprod',
26
+ },
27
+ qa: {
28
+ host1: 'qa-apalb01a.corp.docupace.com',
29
+ host2: 'qa-apalb01b.corp.docupace.com',
30
+ repo: 'iis-preprod',
31
+ },
32
+ uat: {
33
+ host1: 'uat-apalb01a.edc.docupace.internal',
34
+ host2: 'uat-apalb01b.edc.docupace.internal',
35
+ repo: 'iis-www2',
36
+ },
37
+ stage: {
38
+ host1: 'stg-apalb01a.edc.docupace.internal',
39
+ host2: 'stg-apalb01b.edc.docupace.internal',
40
+ repo: 'iis-www2',
41
+ },
42
+ www3: {
43
+ host1: 'prd-apalb05a.edc.docupace.internal',
44
+ host2: 'prd-apalb05b.edc.docupace.internal',
45
+ repo: 'iis-www2',
46
+ },
47
+ };
48
+
49
+ // Save private key from base64
50
+ const haproxyPrivateKey = process.env.HAPROXY_PRIVATE_KEY;
51
+ if (!haproxyPrivateKey) {
52
+ log('Error: HAPROXY_PRIVATE_KEY not set.');
53
+ process.exit(1);
54
+ }
55
+
56
+ await fs.writeFile('private.key', Buffer.from(haproxyPrivateKey, 'base64'));
57
+ await fs.chmod('private.key', 0o600);
58
+
59
+ console.log('Running command');
60
+ const sshCmd = (server, script) =>
61
+ $`ssh -i private.key -o StrictHostKeyChecking=no root@${server} ${script}`;
62
+
63
+ // The script is run twice in the Bash version
64
+ await sshCmd(
65
+ apacheEnvHostMap[process.env.ENVIRONMENT].host1,
66
+ `/root/tomcat_repo_sync.sh`,
67
+ );
68
+ await sshCmd(
69
+ apacheEnvHostMap[process.env.ENVIRONMENT].host1,
70
+ `/root/repo/${apacheEnvHostMap[process.env.ENVIRONMENT].repo}/scripts/addsite/add_core_site.sh ${process.env.ENVIRONMENT} ${process.env.SITE}`,
71
+ );
72
+
73
+ await sshCmd(
74
+ apacheEnvHostMap[process.env.ENVIRONMENT].host2,
75
+ `/root/tomcat_repo_sync.sh`,
76
+ );
77
+ await sshCmd(
78
+ apacheEnvHostMap[process.env.ENVIRONMENT].host2,
79
+ `/root/repo/${apacheEnvHostMap[process.env.ENVIRONMENT].repo}/scripts/addsite/add_core_site.sh ${process.env.ENVIRONMENT} ${process.env.SITE}`,
80
+ );
81
+ }
package/src/next/cli.js CHANGED
@@ -4,19 +4,27 @@ 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 { deployFromSite } from './deploy.js';
8
- import { deployTemplate } from './deploy.js';
9
- import { copy } from './copy.js';
7
+ import {
8
+ deployAppWithTag,
9
+ deployFromSite,
10
+ deployTemplate,
11
+ getDefaultDeploySite,
12
+ getDeployTag,
13
+ } from './deploy.js';
14
+ import { copy2 } from './copy.js';
15
+ import { vaultAddSiteData } from './vault.js';
16
+ import { addApacheSite } from './apache.js';
17
+ import { haproxySync } from './haproxy.js';
18
+ import { connectClone } from './connect.js';
10
19
  import dotenv from 'dotenv';
20
+ import { $ } from 'zx';
21
+ import { deployConnect, deployCore } from './jenkins.js';
22
+ import { runPipeline } from './pipline.js';
11
23
 
12
24
  dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
13
25
 
14
26
  const program = new Command();
15
27
 
16
- // GIT SHA computation
17
- import { $ } from 'zx';
18
- import { deployCore } from './jenkins.js';
19
- import { runPipeline } from './pipline.js';
20
28
  const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
21
29
 
22
30
  program
@@ -33,6 +41,40 @@ program
33
41
  await sonar(GIT_SHA);
34
42
  });
35
43
 
44
+ program
45
+ .command('addApacheSite')
46
+ .description('Add site to apache')
47
+ .action(async () => {
48
+ await addApacheSite();
49
+ });
50
+
51
+ program
52
+ .command('connectClone')
53
+ .description('Clone connect site')
54
+ .action(async () => {
55
+ await connectClone();
56
+ });
57
+
58
+ program
59
+ .command('haproxySync')
60
+ .description('Sync haproxy config')
61
+ .action(async () => {
62
+ await haproxySync();
63
+ });
64
+
65
+ program
66
+ .command('vaultAddSiteData')
67
+ .description('Add m2m auth0 data to vault')
68
+ .requiredOption('-s, --site-name <siteName>', 'Site name')
69
+ .requiredOption(
70
+ '-p, --site-config-remote-path <siteConfigRemotePath>',
71
+ 'Site Config Remote Path',
72
+ )
73
+ .action(async (options) => {
74
+ const { siteName, siteConfigRemotePath } = options;
75
+ await vaultAddSiteData(siteName, siteConfigRemotePath);
76
+ });
77
+
36
78
  program
37
79
  .command('publish')
38
80
  .description('Publish a Docker image')
@@ -48,16 +90,60 @@ program
48
90
  .requiredOption('-F, --from-site <fromSite>', 'Source site')
49
91
  .requiredOption('-T, --to-site <toSite>', 'Target site')
50
92
  .option('-c, --deploy-core <deployCore>', 'Deploy Core', 'false')
93
+ .option('-C, --deploy-connect <deployConnect>', 'Deploy Connect', 'false')
51
94
  .action(async (options) => {
52
- const { fromEnv, fromSite, toEnv, toSite, deployCore } = options;
53
- await deployFromSite(fromEnv, fromSite, toEnv, toSite, deployCore);
95
+ const { fromEnv, fromSite, toEnv, toSite, deployCore, deployConnect } =
96
+ options;
97
+ await deployFromSite(
98
+ fromEnv,
99
+ fromSite,
100
+ toEnv,
101
+ toSite,
102
+ deployCore,
103
+ deployConnect,
104
+ );
54
105
  });
55
106
 
56
107
  program
57
- .command('deployTemplate <site>')
108
+ .command('deploy-template [tagPrefix]')
109
+ .description('Deploy an standard configuration for configured sites')
110
+ .action(async (tagPrefix) => {
111
+ const deployTag = await getDeployTag(tagPrefix);
112
+ const sites = await getDefaultDeploySite(deployTag);
113
+ for (const { env, site } of sites) {
114
+ await deployTemplate(env, site, deployTag);
115
+ }
116
+ });
117
+
118
+ program
119
+ .command('deploy-site-config <env> <site> [tagPrefix]')
120
+ .description('Deploy site configuration for a specific site')
121
+ .action(async (env, site, tagPrefix) => {
122
+ const deployTag = await getDeployTag(tagPrefix);
123
+ await deployTemplate(env, site, deployTag, 'siteConfigRemoteBranch');
124
+ });
125
+
126
+ program
127
+ .command('deploy-app <application>')
58
128
  .description('Deploy an application for a specific site')
59
- .action(async (site) => {
60
- await deployTemplate(site);
129
+ .action(async (application) => {
130
+ const deployTag = await getDeployTag();
131
+ const sites = await getDefaultDeploySite(deployTag);
132
+ for (const { env, site } of sites) {
133
+ await deployAppWithTag(application, env, site, deployTag);
134
+ }
135
+ });
136
+
137
+ program
138
+ .command('deploy-mono-app <tag> <application>')
139
+ .description('Deploy an mono application for a specific site')
140
+ .action(async (tag, application) => {
141
+ const deployTag = await getDeployTag(tag);
142
+ const version = 'v' + deployTag.split('@')[1];
143
+ const sites = await getDefaultDeploySite(version);
144
+ for (const { env, site } of sites) {
145
+ await deployAppWithTag(application, env, site, version);
146
+ }
61
147
  });
62
148
 
63
149
  program
@@ -69,6 +155,15 @@ program
69
155
  await deployCore(env, site, options.liquibase, options.branch);
70
156
  });
71
157
 
158
+ program
159
+ .command('deploy-connect <env> <site>')
160
+ .description('Deploy Core')
161
+ .option('-l, --liquibase <liquibase>', 'Application name', 'true')
162
+ .option('-b, --branch <branch>', 'Branch', 'master')
163
+ .action(async (env, site, options) => {
164
+ await deployConnect(env, site, options.liquibase, options.branch);
165
+ });
166
+
72
167
  program
73
168
  .command('deploy-core-pipeline <env> <site>')
74
169
  .description('Deploy Core')
@@ -86,13 +181,14 @@ program
86
181
  program
87
182
  .command('copy')
88
183
  .description('Copy a Docker image between registries')
89
- .requiredOption('-a, --application <application>', 'Application name')
184
+ .requiredOption('-r, --repository <repository>', 'Repostory name')
90
185
  .requiredOption('-f, --from-env <fromEnv>', 'Source environment')
91
186
  .requiredOption('-t, --to-env <toEnv>', 'Target environment')
92
187
  .requiredOption('-g, --tag <tag>', 'Image tag')
188
+ .requiredOption('-a, --application <application>', 'Application name')
93
189
  .action(async (options) => {
94
- const { application, fromEnv, toEnv, tag } = options;
95
- await copy(application, fromEnv, toEnv, tag);
190
+ const { repository, fromEnv, toEnv, tag, application } = options;
191
+ await copy2(repository, fromEnv, toEnv, tag, application);
96
192
  });
97
193
 
98
194
  program