@docupace/pipeline 1.0.7-7.micro-cli6 → 1.0.7-7.micro-cli8
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 +2 -2
- package/src/micro/ms-deploy.js +31 -11
package/package.json
CHANGED
package/src/micro/cli.js
CHANGED
|
@@ -20,8 +20,8 @@ program
|
|
|
20
20
|
.command('publish-microservice <serviceName>')
|
|
21
21
|
.description('Publish a microservice Docker image with version tags')
|
|
22
22
|
.option('-t, --tag <tag>', 'Version tag (defaults to BITBUCKET_TAG)')
|
|
23
|
-
.action(async (
|
|
24
|
-
await microserviceBuildPushImage(
|
|
23
|
+
.action(async (repoName, options) => {
|
|
24
|
+
await microserviceBuildPushImage(repoName, options);
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
program
|
package/src/micro/ms-deploy.js
CHANGED
|
@@ -264,17 +264,20 @@ export async function microserviceCopyImageToEnv(
|
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
|
|
267
|
-
export async function microserviceBuildPushImage(
|
|
267
|
+
export async function microserviceBuildPushImage(repoName, options = {}) {
|
|
268
268
|
// Use environment variables as defaults, but allow overrides
|
|
269
269
|
|
|
270
|
-
const
|
|
271
|
-
|
|
270
|
+
const serviceName = String(repoName || '')
|
|
271
|
+
.split('-')
|
|
272
|
+
.pop()
|
|
273
|
+
.trim();
|
|
274
|
+
config.repoName = repoName;
|
|
272
275
|
const config = {
|
|
273
276
|
imageName: serviceName,
|
|
274
277
|
registryUrl: options.registryUrl || process.env.JF_REGISTRY_URL,
|
|
275
|
-
repoName:
|
|
276
|
-
username: options.username || process.env.
|
|
277
|
-
password: options.password || process.env.
|
|
278
|
+
repoName: repoName,
|
|
279
|
+
username: options.username || process.env.JF_REGISTRY_DEV_USERNAME,
|
|
280
|
+
password: options.password || process.env.JF_REGISTRY_DEV_PASSWORD,
|
|
278
281
|
buildNumber: options.buildNumber || process.env.BITBUCKET_BUILD_NUMBER,
|
|
279
282
|
tag: options.tag || process.env.VERSION_TAG,
|
|
280
283
|
};
|
|
@@ -285,16 +288,18 @@ export async function microserviceBuildPushImage(serviceName, options = {}) {
|
|
|
285
288
|
'Image name is required. Set IMAGE_NAME or APP_NAME environment variable.',
|
|
286
289
|
);
|
|
287
290
|
}
|
|
288
|
-
|
|
291
|
+
const gitSha = (
|
|
292
|
+
await $`git log ${options.tag} --pretty=format:'%h' -n 1 `
|
|
293
|
+
).stdout.trim();
|
|
289
294
|
console.log('=== Docker Image Publishing Configuration ===');
|
|
290
295
|
console.log(`Image Name: ${config.imageName}`);
|
|
291
296
|
console.log(`Git SHA: ${gitSha}`);
|
|
292
297
|
console.log(`Build Number: ${config.buildNumber}`);
|
|
293
298
|
console.log(`Version Tag: ${config.tag || 'none'}`);
|
|
294
|
-
console.log(`Registry: ${config.registryUrl}/${
|
|
299
|
+
console.log(`Registry: ${config.registryUrl}/${repoName}`);
|
|
295
300
|
console.log('==========================================');
|
|
296
301
|
|
|
297
|
-
const registryPath = `${config.registryUrl}/${
|
|
302
|
+
const registryPath = `${config.registryUrl}/${repoName}`;
|
|
298
303
|
const SHA_IMAGE_NAME = `${config.imageName}:sha-${gitSha}`;
|
|
299
304
|
|
|
300
305
|
// Docker login
|
|
@@ -304,8 +309,23 @@ export async function microserviceBuildPushImage(serviceName, options = {}) {
|
|
|
304
309
|
// Build the image if it doesn't exist locally
|
|
305
310
|
const imageExists = await checkLocalImage(SHA_IMAGE_NAME);
|
|
306
311
|
if (!imageExists) {
|
|
312
|
+
const repoUrl = `https://${process.env.BITBUCKET_USERNAME}:${process.env.BITBUCKET_APP_PASSWORD}@bitbucket.org/dp-cloud/${repoName}.git`;
|
|
313
|
+
await $`git clone --depth 1 ${repoUrl} ${repoName}`;
|
|
314
|
+
|
|
315
|
+
console.log('Checking if directory exists...');
|
|
316
|
+
await $`ls -la ${repoName}`;
|
|
317
|
+
|
|
318
|
+
console.log(`Changing to directory: ${repoName}`);
|
|
319
|
+
process.chdir(repoName);
|
|
320
|
+
|
|
321
|
+
await $`cd ${repoName} && git config user.email "pipeline@bitbucket.org"`;
|
|
322
|
+
await $`cd ${repoName} && git config user.name "Bitbucket Pipeline"`;
|
|
323
|
+
|
|
324
|
+
console.log(`Attempting to checkout branch: ${options.tag}`);
|
|
325
|
+
await $`cd ${repoName} && git checkout ${options.tag}`;
|
|
326
|
+
|
|
307
327
|
console.log(`Building Docker image ${SHA_IMAGE_NAME}...`);
|
|
308
|
-
await $`docker build -t ${SHA_IMAGE_NAME} .`;
|
|
328
|
+
await $`cd ${repoName} && docker build -t ${SHA_IMAGE_NAME} .`;
|
|
309
329
|
}
|
|
310
330
|
|
|
311
331
|
// Array to track all tags we're pushing
|
|
@@ -320,7 +340,7 @@ export async function microserviceBuildPushImage(serviceName, options = {}) {
|
|
|
320
340
|
|
|
321
341
|
// 2. Push build number tag
|
|
322
342
|
if (config.buildNumber) {
|
|
323
|
-
const BUILD_IMAGE_NAME = `${config.imageName}
|
|
343
|
+
const BUILD_IMAGE_NAME = `${config.imageName}:${config.buildNumber}`;
|
|
324
344
|
const buildTag = `${registryPath}/${BUILD_IMAGE_NAME}`;
|
|
325
345
|
console.log(`Tagging and pushing build: ${buildTag}`);
|
|
326
346
|
await $`docker tag ${SHA_IMAGE_NAME} ${buildTag}`;
|