@docupace/pipeline 1.0.7-7.micro-cli4 → 1.0.7-7.micro-cli5
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/micro/cli.js +7 -27
- package/src/micro/ms-deploy.js +279 -117
- package/src/micro/ms-publish.js +174 -174
package/package.json
CHANGED
package/src/micro/cli.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { Command } from 'commander';
|
|
4
|
-
import { publishMicroservice } from './ms-publish.js';
|
|
4
|
+
//import { publishMicroservice } from './ms-publish.js';
|
|
5
5
|
|
|
6
6
|
import dotenv from 'dotenv';
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
testMicroservicePublish,
|
|
8
|
+
microserviceDeployTagVersion,
|
|
9
|
+
microserviceCopyImageToEnv,
|
|
10
|
+
microserviceBuildPushImage,
|
|
12
11
|
} from './ms-deploy.js';
|
|
13
12
|
|
|
14
13
|
dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
|
|
@@ -17,13 +16,12 @@ const program = new Command();
|
|
|
17
16
|
|
|
18
17
|
//const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
|
|
19
18
|
|
|
20
|
-
// Add the new publish-microservice command
|
|
21
19
|
program
|
|
22
20
|
.command('publish-microservice <serviceName>')
|
|
23
21
|
.description('Publish a microservice Docker image with version tags')
|
|
24
22
|
.option('-t, --tag <tag>', 'Version tag (defaults to BITBUCKET_TAG)')
|
|
25
23
|
.action(async (serviceName, options) => {
|
|
26
|
-
await
|
|
24
|
+
await microserviceBuildPushImage(serviceName, options);
|
|
27
25
|
});
|
|
28
26
|
|
|
29
27
|
program
|
|
@@ -32,7 +30,7 @@ program
|
|
|
32
30
|
.option('-e, --env <environment>', 'Target environment', 'dev')
|
|
33
31
|
.option('-t, --tag <tag>', 'Version tag (defaults to BITBUCKET_TAG)')
|
|
34
32
|
.action(async (repoName, options) => {
|
|
35
|
-
await
|
|
33
|
+
await microserviceDeployTagVersion(repoName, options.env, options.tag);
|
|
36
34
|
});
|
|
37
35
|
|
|
38
36
|
program
|
|
@@ -42,7 +40,7 @@ program
|
|
|
42
40
|
.requiredOption('-t, --to <toEnv>', 'Target environment')
|
|
43
41
|
.requiredOption('-g, --tag <tag>', 'Image tag to promote')
|
|
44
42
|
.action(async (repoName, options) => {
|
|
45
|
-
await
|
|
43
|
+
await microserviceCopyImageToEnv(
|
|
46
44
|
repoName,
|
|
47
45
|
options.from,
|
|
48
46
|
options.to,
|
|
@@ -50,22 +48,4 @@ program
|
|
|
50
48
|
);
|
|
51
49
|
});
|
|
52
50
|
|
|
53
|
-
program
|
|
54
|
-
.command('test-deploy-microservice <serviceName>')
|
|
55
|
-
.description('Test microservice deployment only (no image building)')
|
|
56
|
-
.option('-e, --env <environment>', 'Target environment', 'dev')
|
|
57
|
-
.option('-t, --tag <tag>', 'Version tag', 'v0.1.0')
|
|
58
|
-
.action(async (serviceName, options) => {
|
|
59
|
-
await testMicroserviceDeploy(serviceName, options.env, options.tag);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
program
|
|
63
|
-
.command('test-publish-microservice <serviceName>')
|
|
64
|
-
.description(
|
|
65
|
-
'Test microservice Docker build and publish only (no deployment)',
|
|
66
|
-
)
|
|
67
|
-
.action(async (serviceName) => {
|
|
68
|
-
await testMicroservicePublish(serviceName);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
51
|
program.parse(process.argv);
|
package/src/micro/ms-deploy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { $ } from '../next/logger.js';
|
|
2
|
-
|
|
2
|
+
//mport { publishMicroservice } from './ms-publish.js';
|
|
3
3
|
import { copy2 } from '../next/copy.js';
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
import path from 'path';
|
|
@@ -9,126 +9,74 @@ import path from 'path';
|
|
|
9
9
|
* @param {string} environment - Target environment (dev, qa, uat, stage, prod)
|
|
10
10
|
* @param {string} tag - Version tag (optional, defaults to BITBUCKET_TAG)
|
|
11
11
|
*/
|
|
12
|
-
export async function deployMicroserviceEndToEnd(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
* Promote microservice image between environments
|
|
61
|
-
* @param {string} repoName - Name of microservice
|
|
62
|
-
* @param {string} fromEnv - Source environment
|
|
63
|
-
* @param {string} toEnv - Target environment
|
|
64
|
-
* @param {string} tag - Image tag to promote
|
|
65
|
-
*/
|
|
66
|
-
export async function promoteMicroserviceImage(repoName, fromEnv, toEnv, tag) {
|
|
67
|
-
const serviceName = String(repoName || '')
|
|
68
|
-
.split('-')
|
|
69
|
-
.pop()
|
|
70
|
-
.trim();
|
|
71
|
-
console.log(`Starting ${serviceName} image promotion...`);
|
|
72
|
-
console.log(`From: ${fromEnv} → To: ${toEnv}`);
|
|
73
|
-
console.log(`Tag: ${tag}`);
|
|
74
|
-
console.log('==========================================');
|
|
75
|
-
try {
|
|
76
|
-
// Step 1: Copy Docker image between registries
|
|
77
|
-
console.log('\nCopying Docker image...');
|
|
78
|
-
const repositoryName = `${repoName}`;
|
|
79
|
-
await copy2(repositoryName, fromEnv, toEnv, tag, serviceName);
|
|
80
|
-
console.log('Docker image copied successfully!');
|
|
81
|
-
} catch (error) {
|
|
82
|
-
console.error('\nImage promotion failed:', error.message);
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Test deployment only (no image building)
|
|
88
|
-
* @param {string} serviceName - Name of microservice
|
|
89
|
-
* @param {string} environment - Target environment
|
|
90
|
-
* @param {string} tag - Version tag
|
|
91
|
-
*/
|
|
92
|
-
export async function testMicroserviceDeploy(
|
|
93
|
-
serviceName,
|
|
94
|
-
environment = 'dev',
|
|
95
|
-
tag = 'v0.1.0',
|
|
96
|
-
) {
|
|
97
|
-
console.log(`Starting ${serviceName} test deployment...`);
|
|
98
|
-
console.log(`Environment: ${environment}`);
|
|
99
|
-
console.log(`Tag: ${tag}`);
|
|
100
|
-
console.log('==========================================');
|
|
101
|
-
try {
|
|
102
|
-
console.log(`\nTesting deployment to ${environment}...`);
|
|
103
|
-
await deployMicroservice(serviceName, serviceName, environment, tag);
|
|
104
|
-
console.log(`Test deployment to ${environment} completed successfully!`);
|
|
105
|
-
} catch (error) {
|
|
106
|
-
console.error('\nTest deployment failed:', error.message);
|
|
107
|
-
throw error;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
12
|
+
// export async function deployMicroserviceEndToEnd(
|
|
13
|
+
// repoName,
|
|
14
|
+
// environment = '',
|
|
15
|
+
// tag = null,
|
|
16
|
+
// ) {
|
|
17
|
+
// const serviceName = String(repoName || '')
|
|
18
|
+
// .split('-')
|
|
19
|
+
// .pop()
|
|
20
|
+
// .trim();
|
|
21
|
+
// const registryUrl = process.env.JF_REGISTRY_URL || '';
|
|
22
|
+
// const deployTag = tag || process.env.BITBUCKET_TAG || process.env.VERSION_TAG;
|
|
23
|
+
// if (!deployTag) {
|
|
24
|
+
// throw new Error(
|
|
25
|
+
// 'No tag provided. Set tag parameter or BITBUCKET_TAG/VERSION_TAG environment variable.',
|
|
26
|
+
// );
|
|
27
|
+
// }
|
|
28
|
+
// console.log(`Starting ${serviceName} microservice deployment...`);
|
|
29
|
+
// console.log(`Environment: ${environment}`);
|
|
30
|
+
// console.log(`Tag: ${deployTag}`);
|
|
31
|
+
// console.log('==========================================');
|
|
32
|
+
// try {
|
|
33
|
+
// // Step 1: Get Git SHA for image building
|
|
34
|
+
// const gitSha = (
|
|
35
|
+
// await $`git log ${deployTag} --pretty=format:'%h' -n 1`
|
|
36
|
+
// ).stdout.trim();
|
|
37
|
+
// console.log(`Git SHA: ${gitSha}`);
|
|
38
|
+
// // Step 2: Publish Docker image with version tags
|
|
39
|
+
// console.log('\nPublishing Docker image...');
|
|
40
|
+
// await publishMicroservice(serviceName, {
|
|
41
|
+
// tag: deployTag,
|
|
42
|
+
// });
|
|
43
|
+
// console.log('Docker image published successfully!');
|
|
44
|
+
// // Step 3: Deploy to GitOps repository
|
|
45
|
+
// console.log(`\nDeploying to ${environment} environment...`);
|
|
46
|
+
// await deployMicroservice(serviceName, serviceName, environment, deployTag);
|
|
47
|
+
// console.log(`Deployment to ${environment} completed successfully!`);
|
|
48
|
+
// console.log(
|
|
49
|
+
// `\n${serviceName} microservice deployment completed successfully!`,
|
|
50
|
+
// );
|
|
51
|
+
// console.log(
|
|
52
|
+
// `Image: ${registryUrl}/${repoName}-${environment}-docker-local/${serviceName}:${deployTag}`,
|
|
53
|
+
// );
|
|
54
|
+
// } catch (error) {
|
|
55
|
+
// console.error('\nDeployment failed:', error.message);
|
|
56
|
+
// throw error;
|
|
57
|
+
// }
|
|
58
|
+
// }
|
|
59
|
+
|
|
110
60
|
/**
|
|
111
61
|
* Test Docker build and publish only (no deployment)
|
|
112
62
|
* @param {string} serviceName - Name of microservice
|
|
113
63
|
*/
|
|
114
|
-
export async function testMicroservicePublish(serviceName) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/////
|
|
64
|
+
// export async function testMicroservicePublish(serviceName) {
|
|
65
|
+
// console.log(`Starting ${serviceName} test publish...`);
|
|
66
|
+
// console.log('==========================================');
|
|
67
|
+
// try {
|
|
68
|
+
// const gitSha = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
|
|
69
|
+
// console.log(`Git SHA: ${gitSha}`);
|
|
70
|
+
// console.log('\nTesting Docker build and publish...');
|
|
71
|
+
// await publishMicroservice(gitSha, {
|
|
72
|
+
// imageName: serviceName,
|
|
73
|
+
// });
|
|
74
|
+
// console.log('Test publish completed successfully!');
|
|
75
|
+
// } catch (error) {
|
|
76
|
+
// console.error('\nTest publish failed:', error.message);
|
|
77
|
+
// throw error;
|
|
78
|
+
// }
|
|
79
|
+
// }
|
|
132
80
|
|
|
133
81
|
export async function deployMicroservice(
|
|
134
82
|
appName,
|
|
@@ -266,3 +214,217 @@ export async function deployMicroservice(
|
|
|
266
214
|
}
|
|
267
215
|
|
|
268
216
|
export default deployMicroservice;
|
|
217
|
+
|
|
218
|
+
export async function microserviceDeployTagVersion(
|
|
219
|
+
serviceName,
|
|
220
|
+
environment = '',
|
|
221
|
+
tag = null,
|
|
222
|
+
) {
|
|
223
|
+
console.log(`Starting ${serviceName} test deployment...`);
|
|
224
|
+
console.log(`Environment: ${environment}`);
|
|
225
|
+
console.log(`Tag: ${tag}`);
|
|
226
|
+
console.log('==========================================');
|
|
227
|
+
try {
|
|
228
|
+
console.log(`\nTesting deployment to ${environment}...`);
|
|
229
|
+
await deployMicroservice(serviceName, serviceName, environment, tag);
|
|
230
|
+
console.log(`Test deployment to ${environment} completed successfully!`);
|
|
231
|
+
} catch (error) {
|
|
232
|
+
console.error('\nTest deployment failed:', error.message);
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export async function microserviceCopyImageToEnv(
|
|
238
|
+
repoName,
|
|
239
|
+
fromEnv,
|
|
240
|
+
toEnv,
|
|
241
|
+
tag,
|
|
242
|
+
) {
|
|
243
|
+
const serviceName = String(repoName || '')
|
|
244
|
+
.split('-')
|
|
245
|
+
.pop()
|
|
246
|
+
.trim();
|
|
247
|
+
console.log(`Starting ${serviceName} image promotion...`);
|
|
248
|
+
console.log(`From: ${fromEnv} → To: ${toEnv}`);
|
|
249
|
+
console.log(`Tag: ${tag}`);
|
|
250
|
+
console.log('==========================================');
|
|
251
|
+
try {
|
|
252
|
+
// Step 1: Copy Docker image between registries
|
|
253
|
+
console.log('\nCopying Docker image...');
|
|
254
|
+
const repositoryName = `${repoName}`;
|
|
255
|
+
await copy2(repositoryName, fromEnv, toEnv, tag, serviceName);
|
|
256
|
+
console.log('Docker image copied successfully!');
|
|
257
|
+
} catch (error) {
|
|
258
|
+
console.error('\nImage promotion failed:', error.message);
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export async function microserviceBuildPushImage(serviceName, options = {}) {
|
|
264
|
+
// Use environment variables as defaults, but allow overrides
|
|
265
|
+
|
|
266
|
+
const gitSha = (await $`git log --pretty=format:'%h' -n 1 `).stdout.trim();
|
|
267
|
+
|
|
268
|
+
const config = {
|
|
269
|
+
imageName: serviceName,
|
|
270
|
+
registryUrl: options.registryUrl || process.env.JF_REGISTRY_URL,
|
|
271
|
+
repoName: options.repoName || process.env.JF_REGISTRY_REPO_NAME,
|
|
272
|
+
username: options.username || process.env.JF_REGISTRY_USER_DEV,
|
|
273
|
+
password: options.password || process.env.JF_REGISTRY_PASSWORD_DEV,
|
|
274
|
+
buildNumber: options.buildNumber || process.env.BITBUCKET_BUILD_NUMBER,
|
|
275
|
+
tag: options.tag || process.env.VERSION_TAG,
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// Validate required fields
|
|
279
|
+
if (!config.imageName) {
|
|
280
|
+
throw new Error(
|
|
281
|
+
'Image name is required. Set IMAGE_NAME or APP_NAME environment variable.',
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
console.log('=== Docker Image Publishing Configuration ===');
|
|
286
|
+
console.log(`Image Name: ${config.imageName}`);
|
|
287
|
+
console.log(`Git SHA: ${gitSha}`);
|
|
288
|
+
console.log(`Build Number: ${config.buildNumber}`);
|
|
289
|
+
console.log(`Version Tag: ${config.tag || 'none'}`);
|
|
290
|
+
console.log(`Registry: ${config.registryUrl}/${config.repoName}`);
|
|
291
|
+
console.log('==========================================');
|
|
292
|
+
|
|
293
|
+
const registryPath = `${config.registryUrl}/${config.repoName}`;
|
|
294
|
+
const SHA_IMAGE_NAME = `${config.imageName}:sha-${gitSha}`;
|
|
295
|
+
|
|
296
|
+
// Docker login
|
|
297
|
+
await $`echo ${config.password} | docker login --username ${config.username} --password-stdin ${config.registryUrl}`;
|
|
298
|
+
|
|
299
|
+
try {
|
|
300
|
+
// Build the image if it doesn't exist locally
|
|
301
|
+
const imageExists = await checkLocalImage(SHA_IMAGE_NAME);
|
|
302
|
+
if (!imageExists) {
|
|
303
|
+
console.log(`Building Docker image ${SHA_IMAGE_NAME}...`);
|
|
304
|
+
await $`docker build -t ${SHA_IMAGE_NAME} .`;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// Array to track all tags we're pushing
|
|
308
|
+
const tagsToPush = [];
|
|
309
|
+
|
|
310
|
+
// 1. Push SHA tag
|
|
311
|
+
const shaTag = `${registryPath}/${SHA_IMAGE_NAME}`;
|
|
312
|
+
console.log(`Tagging and pushing SHA: ${shaTag}`);
|
|
313
|
+
await $`docker tag ${SHA_IMAGE_NAME} ${shaTag}`;
|
|
314
|
+
await $`docker push ${shaTag}`;
|
|
315
|
+
tagsToPush.push(SHA_IMAGE_NAME);
|
|
316
|
+
|
|
317
|
+
// 2. Push build number tag
|
|
318
|
+
if (config.buildNumber) {
|
|
319
|
+
const BUILD_IMAGE_NAME = `${config.imageName}:build-${config.buildNumber}`;
|
|
320
|
+
const buildTag = `${registryPath}/${BUILD_IMAGE_NAME}`;
|
|
321
|
+
console.log(`Tagging and pushing build: ${buildTag}`);
|
|
322
|
+
await $`docker tag ${SHA_IMAGE_NAME} ${buildTag}`;
|
|
323
|
+
await $`docker push ${buildTag}`;
|
|
324
|
+
tagsToPush.push(BUILD_IMAGE_NAME);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// 3. Push version tag (this is what ArgoCD needs!)
|
|
328
|
+
if (config.tag) {
|
|
329
|
+
// Handle various tag formats
|
|
330
|
+
let version = config.tag;
|
|
331
|
+
|
|
332
|
+
// If tag contains @, extract version after it
|
|
333
|
+
if (version.includes('@')) {
|
|
334
|
+
version = 'v' + version.split('@')[1];
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Ensure version starts with 'v' if it's a semver without it
|
|
338
|
+
if (/^\d+\.\d+\.\d+/.test(version) && !version.startsWith('v')) {
|
|
339
|
+
version = 'v' + version;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const VERSION_IMAGE_NAME = `${config.imageName}:${version}`;
|
|
343
|
+
const versionTag = `${registryPath}/${VERSION_IMAGE_NAME}`;
|
|
344
|
+
|
|
345
|
+
console.log(`Tagging and pushing version: ${versionTag}`);
|
|
346
|
+
await $`docker tag ${SHA_IMAGE_NAME} ${versionTag}`;
|
|
347
|
+
await $`docker push ${versionTag}`;
|
|
348
|
+
tagsToPush.push(VERSION_IMAGE_NAME);
|
|
349
|
+
|
|
350
|
+
// Also push 'latest' tag when we have a version
|
|
351
|
+
const LATEST_IMAGE_NAME = `${config.imageName}:latest`;
|
|
352
|
+
const latestTag = `${registryPath}/${LATEST_IMAGE_NAME}`;
|
|
353
|
+
console.log(`Tagging and pushing latest: ${latestTag}`);
|
|
354
|
+
await $`docker tag ${SHA_IMAGE_NAME} ${latestTag}`;
|
|
355
|
+
await $`docker push ${latestTag}`;
|
|
356
|
+
tagsToPush.push(LATEST_IMAGE_NAME);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// 4. Check for git tags at current commit
|
|
360
|
+
try {
|
|
361
|
+
const gitTags = (await $`git tag --points-at HEAD`).stdout
|
|
362
|
+
.trim()
|
|
363
|
+
.split('\n')
|
|
364
|
+
.filter(Boolean);
|
|
365
|
+
|
|
366
|
+
if (gitTags.length > 0) {
|
|
367
|
+
console.log(`Found git tags at HEAD: ${gitTags.join(', ')}`);
|
|
368
|
+
|
|
369
|
+
for (const gitTag of gitTags) {
|
|
370
|
+
// Skip if we already handled this tag above
|
|
371
|
+
if (gitTag === config.tag) continue;
|
|
372
|
+
|
|
373
|
+
let version = gitTag;
|
|
374
|
+
if (version.includes('@')) {
|
|
375
|
+
version = 'v' + version.split('@')[1];
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const TAG_IMAGE_NAME = `${config.imageName}:${version}`;
|
|
379
|
+
const gitTagPath = `${registryPath}/${TAG_IMAGE_NAME}`;
|
|
380
|
+
|
|
381
|
+
console.log(`Tagging and pushing git tag: ${gitTagPath}`);
|
|
382
|
+
await $`docker tag ${SHA_IMAGE_NAME} ${gitTagPath}`;
|
|
383
|
+
await $`docker push ${gitTagPath}`;
|
|
384
|
+
tagsToPush.push(TAG_IMAGE_NAME);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
} catch (e) {
|
|
388
|
+
console.log('No git tags found at HEAD or error checking tags', e);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
console.log('\n✅ Docker image published successfully!');
|
|
392
|
+
console.log('=== Summary of pushed tags ===');
|
|
393
|
+
tagsToPush.forEach((tag) => console.log(` ✓ ${tag}`));
|
|
394
|
+
console.log('==============================\n');
|
|
395
|
+
|
|
396
|
+
// Verify the version tag if we expect one
|
|
397
|
+
if (config.tag) {
|
|
398
|
+
const version = config.tag.includes('@')
|
|
399
|
+
? 'v' + config.tag.split('@')[1]
|
|
400
|
+
: config.tag;
|
|
401
|
+
const expectedTag = `${registryPath}/${config.imageName}:${version}`;
|
|
402
|
+
console.log(`Verifying version tag exists: ${expectedTag}`);
|
|
403
|
+
try {
|
|
404
|
+
await $`docker manifest inspect ${expectedTag}`;
|
|
405
|
+
console.log('✅ Version tag verified in registry!');
|
|
406
|
+
} catch (e) {
|
|
407
|
+
console.error('❌ WARNING: Could not verify version tag in registry!');
|
|
408
|
+
console.error('ArgoCD may fail to pull this image.', e);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
} catch (error) {
|
|
412
|
+
console.error('Error during image publishing:', error);
|
|
413
|
+
throw error;
|
|
414
|
+
} finally {
|
|
415
|
+
// Always logout
|
|
416
|
+
await $`docker logout ${config.registryUrl}`;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
async function checkLocalImage(imageName) {
|
|
421
|
+
try {
|
|
422
|
+
$.verbose = false;
|
|
423
|
+
await $`docker image inspect ${imageName}`;
|
|
424
|
+
return true;
|
|
425
|
+
} catch {
|
|
426
|
+
return false;
|
|
427
|
+
} finally {
|
|
428
|
+
$.verbose = true;
|
|
429
|
+
}
|
|
430
|
+
}
|
package/src/micro/ms-publish.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ } from '../next/logger.js';
|
|
1
|
+
//import { $ } from '../next/logger.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Publish Docker images for microservices with flexible naming
|
|
@@ -11,176 +11,176 @@ import { $ } from '../next/logger.js';
|
|
|
11
11
|
* @param {string} options.password - JFrog password
|
|
12
12
|
* @param {string} options.buildNumber - Build number
|
|
13
13
|
*/
|
|
14
|
-
export async function publishMicroservice(serviceName, options = {}) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async function checkLocalImage(imageName) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Backward compatibility wrapper
|
|
184
|
-
export async function publishWithDefaults(gitSha) {
|
|
185
|
-
|
|
186
|
-
}
|
|
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
|
+
// }
|