@docupace/pipeline 1.0.7-7.micro-cli5 → 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 +33 -10
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
|
@@ -216,10 +216,14 @@ export async function deployMicroservice(
|
|
|
216
216
|
export default deployMicroservice;
|
|
217
217
|
|
|
218
218
|
export async function microserviceDeployTagVersion(
|
|
219
|
-
|
|
219
|
+
repoName,
|
|
220
220
|
environment = '',
|
|
221
221
|
tag = null,
|
|
222
222
|
) {
|
|
223
|
+
const serviceName = String(repoName || '')
|
|
224
|
+
.split('-')
|
|
225
|
+
.pop()
|
|
226
|
+
.trim();
|
|
223
227
|
console.log(`Starting ${serviceName} test deployment...`);
|
|
224
228
|
console.log(`Environment: ${environment}`);
|
|
225
229
|
console.log(`Tag: ${tag}`);
|
|
@@ -260,17 +264,19 @@ export async function microserviceCopyImageToEnv(
|
|
|
260
264
|
}
|
|
261
265
|
}
|
|
262
266
|
|
|
263
|
-
export async function microserviceBuildPushImage(
|
|
267
|
+
export async function microserviceBuildPushImage(repoName, options = {}) {
|
|
264
268
|
// Use environment variables as defaults, but allow overrides
|
|
265
269
|
|
|
266
|
-
const
|
|
267
|
-
|
|
270
|
+
const serviceName = String(repoName || '')
|
|
271
|
+
.split('-')
|
|
272
|
+
.pop()
|
|
273
|
+
.trim();
|
|
268
274
|
const config = {
|
|
269
275
|
imageName: serviceName,
|
|
270
276
|
registryUrl: options.registryUrl || process.env.JF_REGISTRY_URL,
|
|
271
|
-
repoName:
|
|
272
|
-
username: options.username || process.env.
|
|
273
|
-
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,
|
|
274
280
|
buildNumber: options.buildNumber || process.env.BITBUCKET_BUILD_NUMBER,
|
|
275
281
|
tag: options.tag || process.env.VERSION_TAG,
|
|
276
282
|
};
|
|
@@ -281,7 +287,9 @@ export async function microserviceBuildPushImage(serviceName, options = {}) {
|
|
|
281
287
|
'Image name is required. Set IMAGE_NAME or APP_NAME environment variable.',
|
|
282
288
|
);
|
|
283
289
|
}
|
|
284
|
-
|
|
290
|
+
const gitSha = (
|
|
291
|
+
await $`git log ${options.tag} --pretty=format:'%h' -n 1 `
|
|
292
|
+
).stdout.trim();
|
|
285
293
|
console.log('=== Docker Image Publishing Configuration ===');
|
|
286
294
|
console.log(`Image Name: ${config.imageName}`);
|
|
287
295
|
console.log(`Git SHA: ${gitSha}`);
|
|
@@ -300,8 +308,23 @@ export async function microserviceBuildPushImage(serviceName, options = {}) {
|
|
|
300
308
|
// Build the image if it doesn't exist locally
|
|
301
309
|
const imageExists = await checkLocalImage(SHA_IMAGE_NAME);
|
|
302
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
|
+
|
|
303
326
|
console.log(`Building Docker image ${SHA_IMAGE_NAME}...`);
|
|
304
|
-
await $`docker build -t ${SHA_IMAGE_NAME} .`;
|
|
327
|
+
await $`cd ${repoName} && docker build -t ${SHA_IMAGE_NAME} .`;
|
|
305
328
|
}
|
|
306
329
|
|
|
307
330
|
// Array to track all tags we're pushing
|
|
@@ -316,7 +339,7 @@ export async function microserviceBuildPushImage(serviceName, options = {}) {
|
|
|
316
339
|
|
|
317
340
|
// 2. Push build number tag
|
|
318
341
|
if (config.buildNumber) {
|
|
319
|
-
const BUILD_IMAGE_NAME = `${config.imageName}
|
|
342
|
+
const BUILD_IMAGE_NAME = `${config.imageName}:${config.buildNumber}`;
|
|
320
343
|
const buildTag = `${registryPath}/${BUILD_IMAGE_NAME}`;
|
|
321
344
|
console.log(`Tagging and pushing build: ${buildTag}`);
|
|
322
345
|
await $`docker tag ${SHA_IMAGE_NAME} ${buildTag}`;
|