@docupace/pipeline 1.0.7-7.micro-cli6 → 1.0.7-7.micro-cli7
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 +28 -9
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,19 @@ 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();
|
|
272
274
|
const config = {
|
|
273
275
|
imageName: serviceName,
|
|
274
276
|
registryUrl: options.registryUrl || process.env.JF_REGISTRY_URL,
|
|
275
|
-
repoName:
|
|
276
|
-
username: options.username || process.env.
|
|
277
|
-
password: options.password || process.env.
|
|
277
|
+
repoName: repoName,
|
|
278
|
+
username: options.username || process.env.JF_REGISTRY_DEV_USERNAME,
|
|
279
|
+
password: options.password || process.env.JF_REGISTRY_DEV_PASSWORD,
|
|
278
280
|
buildNumber: options.buildNumber || process.env.BITBUCKET_BUILD_NUMBER,
|
|
279
281
|
tag: options.tag || process.env.VERSION_TAG,
|
|
280
282
|
};
|
|
@@ -285,7 +287,9 @@ export async function microserviceBuildPushImage(serviceName, options = {}) {
|
|
|
285
287
|
'Image name is required. Set IMAGE_NAME or APP_NAME environment variable.',
|
|
286
288
|
);
|
|
287
289
|
}
|
|
288
|
-
|
|
290
|
+
const gitSha = (
|
|
291
|
+
await $`git log ${options.tag} --pretty=format:'%h' -n 1 `
|
|
292
|
+
).stdout.trim();
|
|
289
293
|
console.log('=== Docker Image Publishing Configuration ===');
|
|
290
294
|
console.log(`Image Name: ${config.imageName}`);
|
|
291
295
|
console.log(`Git SHA: ${gitSha}`);
|
|
@@ -304,8 +308,23 @@ export async function microserviceBuildPushImage(serviceName, options = {}) {
|
|
|
304
308
|
// Build the image if it doesn't exist locally
|
|
305
309
|
const imageExists = await checkLocalImage(SHA_IMAGE_NAME);
|
|
306
310
|
if (!imageExists) {
|
|
311
|
+
const repoUrl = `https://${process.env.BITBUCKET_USERNAME}:${process.env.BITBUCKET_APP_PASSWORD}@bitbucket.org/dp-cloud/${repoName}.git`;
|
|
312
|
+
await $`git clone --depth 1 ${repoUrl} ${repoName}`;
|
|
313
|
+
|
|
314
|
+
console.log('Checking if directory exists...');
|
|
315
|
+
await $`ls -la ${repoName}`;
|
|
316
|
+
|
|
317
|
+
console.log(`Changing to directory: ${repoName}`);
|
|
318
|
+
process.chdir(repoName);
|
|
319
|
+
|
|
320
|
+
await $`cd ${repoName} && git config user.email "pipeline@bitbucket.org"`;
|
|
321
|
+
await $`cd ${repoName} && git config user.name "Bitbucket Pipeline"`;
|
|
322
|
+
|
|
323
|
+
console.log(`Attempting to checkout branch: ${options.tag}`);
|
|
324
|
+
await $`cd ${repoName} && git checkout ${options.tag}`;
|
|
325
|
+
|
|
307
326
|
console.log(`Building Docker image ${SHA_IMAGE_NAME}...`);
|
|
308
|
-
await $`docker build -t ${SHA_IMAGE_NAME} .`;
|
|
327
|
+
await $`cd ${repoName} && docker build -t ${SHA_IMAGE_NAME} .`;
|
|
309
328
|
}
|
|
310
329
|
|
|
311
330
|
// Array to track all tags we're pushing
|
|
@@ -320,7 +339,7 @@ export async function microserviceBuildPushImage(serviceName, options = {}) {
|
|
|
320
339
|
|
|
321
340
|
// 2. Push build number tag
|
|
322
341
|
if (config.buildNumber) {
|
|
323
|
-
const BUILD_IMAGE_NAME = `${config.imageName}
|
|
342
|
+
const BUILD_IMAGE_NAME = `${config.imageName}:${config.buildNumber}`;
|
|
324
343
|
const buildTag = `${registryPath}/${BUILD_IMAGE_NAME}`;
|
|
325
344
|
console.log(`Tagging and pushing build: ${buildTag}`);
|
|
326
345
|
await $`docker tag ${SHA_IMAGE_NAME} ${buildTag}`;
|