@docupace/pipeline 1.0.61-alpha.1 → 1.0.61

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/eslint.config.js CHANGED
@@ -10,7 +10,7 @@ export default [
10
10
  globals: {
11
11
  ...globals.browser,
12
12
  ...globals.node, // Add Node.js globals
13
- },
13
+ },g
14
14
  },
15
15
  },
16
16
  pluginJs.configs.recommended,
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.61-alpha.1",
3
+ "version": "1.0.61",
4
+ "description": "",
4
5
  "main": "index.js",
5
6
  "type": "module",
6
7
  "bin": {
7
8
  "dp-changeset-cli": "src/changeset/cli.js",
8
9
  "dp-next-cli": "src/next/cli.js",
9
- "dp-auth0-cli": "src/auth0/cli.js",
10
- "dp-merge-cli": "src/merge/cli.js"
10
+ "dp-auth0-cli": "src/auth0/cli.js"
11
11
  },
12
12
  "keywords": [
13
13
  "bash"
@@ -10,10 +10,6 @@ import {
10
10
  versionCommand,
11
11
  } from './version.js';
12
12
  import { createChangeset } from './create.js';
13
- import {
14
- updateWikiWithVersion,
15
- upsertReleaseNotesFromFile,
16
- } from './changelog-wiki.js';
17
13
 
18
14
  dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
19
15
 
@@ -97,11 +93,6 @@ async function commitTag() {
97
93
  await $`node -p "require('./package.json').version"`
98
94
  ).stdout.trim();
99
95
 
100
- if (process.env.IS_DEV) {
101
- console.log(`Simulate commit of version ${newVersion}`);
102
- return;
103
- }
104
-
105
96
  const defaultBranch = process.env.BITBUCKET_BRANCH;
106
97
 
107
98
  await $`git commit -m "Version bump to ${newVersion} and changelog"`;
@@ -145,7 +136,6 @@ program
145
136
  console.log('šŸ“¦ Running all steps...');
146
137
  const releases = await versionCommand();
147
138
  await updateJiraWithVersion(releases);
148
- await updateWikiWithVersion(releases);
149
139
  await commitTagCommand(releases);
150
140
  });
151
141
 
@@ -197,41 +187,5 @@ program
197
187
  await createChangeset();
198
188
  });
199
189
 
200
- program
201
- .command('upload-wiki')
202
- .description('Upload release notes from markdown file to Confluence')
203
- .requiredOption(
204
- '-v, --version <version>',
205
- 'Version title (e.g., "Version 1.0")',
206
- )
207
- .requiredOption(
208
- '-c, --component <component>',
209
- 'Component title (e.g., "Component A")',
210
- )
211
- .requiredOption('-f, --file <file>', 'Path to markdown file')
212
- .requiredOption('-g, --group <group>', 'Group of release notes')
213
-
214
- .action(async (options) => {
215
- try {
216
- console.log('šŸ“¤ Uploading release notes to Confluence...');
217
- const { versionPage, componentPage } = await upsertReleaseNotesFromFile({
218
- version: options.version,
219
- component: options.component,
220
- markdownFile: options.file,
221
- group: options.group,
222
- });
223
-
224
- console.log('āœ… Successfully uploaded to Confluence');
225
- console.log('Version page:', versionPage._links?.webui || versionPage.id);
226
- console.log(
227
- 'Component page:',
228
- componentPage._links?.webui || componentPage.id,
229
- );
230
- } catch (error) {
231
- console.error('āŒ Error uploading to Confluence:', error.message);
232
- process.exit(1);
233
- }
234
- });
235
-
236
190
  // Parse arguments
237
191
  program.parse(args);
@@ -110,17 +110,8 @@ async function generateReleaseNotes(jiraTicketData) {
110
110
  /**
111
111
  * Writes the changeset file
112
112
  */
113
- async function writeJiraChangesetFile(
114
- packages,
115
- jiraTicketId,
116
- changeType,
117
- summary,
118
- ) {
119
- const text = `${summary} [${jiraTicketId}]`;
120
- await writeChangesetFile(packages, jiraTicketId, changeType, text);
121
- }
122
-
123
- export async function writeChangesetFile(packages, filename, changeType, text) {
113
+ async function writeChangesetFile(packages, jiraTicketId, changeType, summary) {
114
+ // Generate the YAML frontmatter for multiple packages
124
115
  const packageEntries = packages
125
116
  .map((pkg) => `'${pkg.name}': ${changeType}`)
126
117
  .join('\n');
@@ -129,10 +120,9 @@ export async function writeChangesetFile(packages, filename, changeType, text) {
129
120
  ${packageEntries}
130
121
  ---
131
122
 
132
- ${text}
123
+ ${summary} [${jiraTicketId}]
133
124
  `;
134
-
135
- const changesetFile = `./.changeset/${filename}.md`;
125
+ const changesetFile = `./.changeset/${jiraTicketId}.md`;
136
126
 
137
127
  await createChangesetDirectory();
138
128
  await fs.promises.writeFile(changesetFile, changesetContent);
@@ -205,7 +195,7 @@ export async function createChangesetForPackage(packages) {
205
195
  console.log(`Release note: ${summary}`);
206
196
 
207
197
  // Step 5: Create a changeset .md file for all packages
208
- await writeJiraChangesetFile(packages, jiraTicketId, change_type, summary);
198
+ await writeChangesetFile(packages, jiraTicketId, change_type, summary);
209
199
 
210
200
  console.log('Changeset created successfully!');
211
201
  } catch (err) {
@@ -37,7 +37,7 @@ export function getPackageNames(rootPath = '.') {
37
37
  fs.readFileSync(rootPackageJson, 'utf8'),
38
38
  );
39
39
  return packageJson.name
40
- ? [{ name: packageJson.name, path: rootPath, content: packageJson }]
40
+ ? [{ name: packageJson.name, path: rootPath }]
41
41
  : [];
42
42
  } catch (error) {
43
43
  console.error('Error reading root package.json:', error);
@@ -71,7 +71,6 @@ function getPackagesFromDirectory(dirPath) {
71
71
  packages.push({
72
72
  name: packageJson.name,
73
73
  path: itemPath,
74
- content: packageJson,
75
74
  });
76
75
  }
77
76
  } catch (error) {
@@ -0,0 +1,116 @@
1
+ import { $ } from '@docupace/pipeline/src/next/logger.js';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+
5
+ export async function deployMicroservice(appName, helmPath, environment = 'dev', tag = null) {
6
+ if (!appName || !helmPath) {
7
+ throw new Error('Missing required parameters. Usage: deployMicroservice(appName, helmPath, [environment], [tag])');
8
+ }
9
+
10
+ let deployTag = tag;
11
+ if (!deployTag) {
12
+ deployTag = process.env.VERSION_TAG ||
13
+ process.env.BITBUCKET_TAG ||
14
+ (process.env.BITBUCKET_BUILD_NUMBER ? `build-${process.env.BITBUCKET_BUILD_NUMBER}` : null);
15
+ }
16
+
17
+ if (!deployTag) {
18
+ throw new Error('No tag specified and no default tag available from environment variables');
19
+ }
20
+
21
+ const repoName = `gitops-${environment}`;
22
+ const filePath = `dp/${helmPath}/${appName}.values.yaml`;
23
+
24
+ const gitopsBranch = (environment === 'dev' || environment === 'uat')
25
+ ? (process.env.GITOPS_BRANCH || 'master')
26
+ : (process.env.GITOPS_BRANCH || 'main');
27
+
28
+ let repoUrl;
29
+ if (environment === 'dev' && process.env.GITOPS_REP_TOKEN) {
30
+ repoUrl = `https://x-token-auth:${process.env.GITOPS_REP_TOKEN}@bitbucket.org/dp-cloud/${repoName}.git`;
31
+ } else if (process.env.BITBUCKET_USERNAME && process.env.BITBUCKET_APP_PASSWORD) {
32
+ repoUrl = `https://${process.env.BITBUCKET_USERNAME}:${process.env.BITBUCKET_APP_PASSWORD}@bitbucket.org/dp-cloud/${repoName}.git`;
33
+ } else {
34
+ throw new Error('No authentication credentials found for GitOps repository');
35
+ }
36
+
37
+ console.log('=========================================');
38
+ console.log('Microservice Deployment Configuration');
39
+ console.log('=========================================');
40
+ console.log(`Application: ${appName}`);
41
+ console.log(`Environment: ${environment}`);
42
+ console.log(`Tag: ${deployTag}`);
43
+ console.log(`GitOps Repo: ${repoName}`);
44
+ console.log(`Values File: ${filePath}`);
45
+ console.log(`Branch: ${gitopsBranch}`);
46
+ console.log('=========================================');
47
+
48
+ try {
49
+ console.log('Cloning GitOps repository...');
50
+ await $`git clone --depth 1 ${repoUrl} ${repoName}`;
51
+
52
+ console.log('Checking if directory exists...');
53
+ await $`ls -la ${repoName}`;
54
+
55
+ console.log(`Changing to directory: ${repoName}`);
56
+ const originalDir = process.cwd();
57
+ process.chdir(repoName);
58
+
59
+ console.log('Verifying directory change...');
60
+ const newDir = process.cwd();
61
+ console.log(`Original: ${originalDir}`);
62
+ console.log(`New: ${newDir}`);
63
+
64
+ await $`cd ${repoName} && git config user.email "pipeline@bitbucket.org"`;
65
+ await $`cd ${repoName} && git config user.name "Bitbucket Pipeline"`;
66
+
67
+ console.log(`Attempting to checkout branch: ${gitopsBranch}`);
68
+ await $`cd ${repoName} && git checkout ${gitopsBranch}`;
69
+
70
+ const fullFilePath = path.resolve(filePath);
71
+ console.log(`Looking for file at: ${fullFilePath}`);
72
+ if (!fs.existsSync(fullFilePath)) {
73
+ throw new Error(`Values file ${filePath} does not exist in ${repoName} on branch ${gitopsBranch}`);
74
+ }
75
+
76
+ console.log(`Updating image tag to ${deployTag}...`);
77
+
78
+ let fileContent = fs.readFileSync(fullFilePath, 'utf8');
79
+
80
+ const tagRegex = /^ tag: .*/gm;
81
+ const newContent = fileContent.replace(tagRegex, ` tag: ${deployTag}`);
82
+
83
+ if (fileContent === newContent) {
84
+ console.log(`No changes detected - tag is already ${deployTag}`);
85
+ return;
86
+ }
87
+
88
+ fs.writeFileSync(fullFilePath, newContent, 'utf8');
89
+
90
+ console.log('Changes to be committed:');
91
+ await $`cd ${repoName} && git diff ${filePath}`;
92
+
93
+ await $`cd ${repoName} && git add ${filePath}`;
94
+ await $`cd ${repoName} && git commit -m "Update ${appName} image tag to ${deployTag} in ${environment} environment"`;
95
+
96
+ console.log('Pushing changes to GitOps repository...');
97
+ await $`cd ${repoName} && git push origin ${gitopsBranch}`;
98
+
99
+ console.log('=========================================');
100
+ console.log(`āœ… Successfully deployed ${appName}:${deployTag} to ${environment}`);
101
+ console.log('=========================================');
102
+
103
+ } catch (error) {
104
+ console.error('Error during microservice deployment:', error.message);
105
+ throw error;
106
+ } finally {
107
+ try {
108
+ process.chdir('..');
109
+ await $`rm -rf ${repoName}`;
110
+ } catch (cleanupError) {
111
+ console.warn('Warning: Failed to clean up temporary directory:', cleanupError.message);
112
+ }
113
+ }
114
+ }
115
+
116
+ export default deployMicroservice;
@@ -0,0 +1,180 @@
1
+ import { $ } from '@docupace/pipeline/src/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(gitSha, options = {}) {
15
+ // Use environment variables as defaults, but allow overrides
16
+ const config = {
17
+ imageName: options.imageName || process.env.IMAGE_NAME || process.env.APP_NAME,
18
+ registryUrl: options.registryUrl || process.env.JF_REGISTRY_URL,
19
+ repoName: options.repoName || process.env.JF_REGISTRY_REPO_NAME,
20
+ username: options.username || process.env.JF_REGISTRY_USER_DEV,
21
+ password: options.password || process.env.JF_REGISTRY_PASSWORD_DEV,
22
+ buildNumber: options.buildNumber || process.env.BITBUCKET_BUILD_NUMBER,
23
+ tag: options.tag || process.env.TAG || process.env.BITBUCKET_TAG || process.env.VERSION_TAG
24
+ };
25
+
26
+ // Validate required fields
27
+ if (!config.imageName) {
28
+ throw new Error('Image name is required. Set IMAGE_NAME or APP_NAME environment variable.');
29
+ }
30
+
31
+ console.log('=== Docker Image Publishing Configuration ===');
32
+ console.log(`Image Name: ${config.imageName}`);
33
+ console.log(`Git SHA: ${gitSha}`);
34
+ console.log(`Build Number: ${config.buildNumber}`);
35
+ console.log(`Version Tag: ${config.tag || 'none'}`);
36
+ console.log(`Registry: ${config.registryUrl}/${config.repoName}`);
37
+ console.log('==========================================');
38
+
39
+ const registryPath = `${config.registryUrl}/${config.repoName}`;
40
+ const SHA_IMAGE_NAME = `${config.imageName}:sha-${gitSha}`;
41
+
42
+ // Docker login
43
+ await $`echo ${config.password} | docker login --username ${config.username} --password-stdin ${config.registryUrl}`;
44
+
45
+ try {
46
+ // Build the image if it doesn't exist locally
47
+ const imageExists = await checkLocalImage(SHA_IMAGE_NAME);
48
+ if (!imageExists) {
49
+ console.log(`Building Docker image ${SHA_IMAGE_NAME}...`);
50
+ await $`docker build -t ${SHA_IMAGE_NAME} .`;
51
+ }
52
+
53
+ // Array to track all tags we're pushing
54
+ const tagsToPush = [];
55
+
56
+ // 1. Push SHA tag
57
+ const shaTag = `${registryPath}/${SHA_IMAGE_NAME}`;
58
+ console.log(`Tagging and pushing SHA: ${shaTag}`);
59
+ await $`docker tag ${SHA_IMAGE_NAME} ${shaTag}`;
60
+ await $`docker push ${shaTag}`;
61
+ tagsToPush.push(SHA_IMAGE_NAME);
62
+
63
+ // 2. Push build number tag
64
+ if (config.buildNumber) {
65
+ const BUILD_IMAGE_NAME = `${config.imageName}:build-${config.buildNumber}`;
66
+ const buildTag = `${registryPath}/${BUILD_IMAGE_NAME}`;
67
+ console.log(`Tagging and pushing build: ${buildTag}`);
68
+ await $`docker tag ${SHA_IMAGE_NAME} ${buildTag}`;
69
+ await $`docker push ${buildTag}`;
70
+ tagsToPush.push(BUILD_IMAGE_NAME);
71
+ }
72
+
73
+ // 3. Push version tag (this is what ArgoCD needs!)
74
+ if (config.tag) {
75
+ // Handle various tag formats
76
+ let version = config.tag;
77
+
78
+ // If tag contains @, extract version after it
79
+ if (version.includes('@')) {
80
+ version = 'v' + version.split('@')[1];
81
+ }
82
+
83
+ // Ensure version starts with 'v' if it's a semver without it
84
+ if (/^\d+\.\d+\.\d+/.test(version) && !version.startsWith('v')) {
85
+ version = 'v' + version;
86
+ }
87
+
88
+ const VERSION_IMAGE_NAME = `${config.imageName}:${version}`;
89
+ const versionTag = `${registryPath}/${VERSION_IMAGE_NAME}`;
90
+
91
+ console.log(`Tagging and pushing version: ${versionTag}`);
92
+ await $`docker tag ${SHA_IMAGE_NAME} ${versionTag}`;
93
+ await $`docker push ${versionTag}`;
94
+ tagsToPush.push(VERSION_IMAGE_NAME);
95
+
96
+ // Also push 'latest' tag when we have a version
97
+ const LATEST_IMAGE_NAME = `${config.imageName}:latest`;
98
+ const latestTag = `${registryPath}/${LATEST_IMAGE_NAME}`;
99
+ console.log(`Tagging and pushing latest: ${latestTag}`);
100
+ await $`docker tag ${SHA_IMAGE_NAME} ${latestTag}`;
101
+ await $`docker push ${latestTag}`;
102
+ tagsToPush.push(LATEST_IMAGE_NAME);
103
+ }
104
+
105
+ // 4. Check for git tags at current commit
106
+ try {
107
+ const gitTags = (await $`git tag --points-at HEAD`).stdout
108
+ .trim()
109
+ .split('\n')
110
+ .filter(Boolean);
111
+
112
+ if (gitTags.length > 0) {
113
+ console.log(`Found git tags at HEAD: ${gitTags.join(', ')}`);
114
+
115
+ for (const gitTag of gitTags) {
116
+ // Skip if we already handled this tag above
117
+ if (gitTag === config.tag) continue;
118
+
119
+ let version = gitTag;
120
+ if (version.includes('@')) {
121
+ version = 'v' + version.split('@')[1];
122
+ }
123
+
124
+ const TAG_IMAGE_NAME = `${config.imageName}:${version}`;
125
+ const gitTagPath = `${registryPath}/${TAG_IMAGE_NAME}`;
126
+
127
+ console.log(`Tagging and pushing git tag: ${gitTagPath}`);
128
+ await $`docker tag ${SHA_IMAGE_NAME} ${gitTagPath}`;
129
+ await $`docker push ${gitTagPath}`;
130
+ tagsToPush.push(TAG_IMAGE_NAME);
131
+ }
132
+ }
133
+ } catch (e) {
134
+ console.log('No git tags found at HEAD or error checking tags');
135
+ }
136
+
137
+ console.log('\nāœ… Docker image published successfully!');
138
+ console.log('=== Summary of pushed tags ===');
139
+ tagsToPush.forEach(tag => console.log(` āœ“ ${tag}`));
140
+ console.log('==============================\n');
141
+
142
+ // Verify the version tag if we expect one
143
+ if (config.tag) {
144
+ const version = config.tag.includes('@') ? 'v' + config.tag.split('@')[1] : config.tag;
145
+ const expectedTag = `${registryPath}/${config.imageName}:${version}`;
146
+ console.log(`Verifying version tag exists: ${expectedTag}`);
147
+ try {
148
+ await $`docker manifest inspect ${expectedTag}`;
149
+ console.log('āœ… Version tag verified in registry!');
150
+ } catch (e) {
151
+ console.error('āŒ WARNING: Could not verify version tag in registry!');
152
+ console.error('ArgoCD may fail to pull this image.');
153
+ }
154
+ }
155
+
156
+ } catch (error) {
157
+ console.error('Error during image publishing:', error);
158
+ throw error;
159
+ } finally {
160
+ // Always logout
161
+ await $`docker logout ${config.registryUrl}`;
162
+ }
163
+ }
164
+
165
+ async function checkLocalImage(imageName) {
166
+ try {
167
+ $.verbose = false;
168
+ await $`docker image inspect ${imageName}`;
169
+ return true;
170
+ } catch {
171
+ return false;
172
+ } finally {
173
+ $.verbose = true;
174
+ }
175
+ }
176
+
177
+ // Backward compatibility wrapper
178
+ export async function publishWithDefaults(gitSha) {
179
+ return publishMicroservice(gitSha);
180
+ }
package/src/next/cli.js CHANGED
@@ -4,6 +4,7 @@ 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 { publishMicroservice } from './micro/publish-ms.js'; // Add this import
7
8
  import {
8
9
  deployAppWithTag,
9
10
  deployFromSite,
@@ -82,6 +83,14 @@ program
82
83
  await publish(GIT_SHA);
83
84
  });
84
85
 
86
+ // Add the new publish-microservice command
87
+ program
88
+ .command('publish-microservice')
89
+ .description('Publish a microservice Docker image with version tags')
90
+ .action(async () => {
91
+ await publishMicroservice(GIT_SHA);
92
+ });
93
+
85
94
  program
86
95
  .command('deploy-from-site')
87
96
  .description('Deploy an application for a specific site')
@@ -223,4 +232,4 @@ program
223
232
  }
224
233
  });
225
234
 
226
- program.parse(process.argv);
235
+ program.parse(process.argv);