@docupace/pipeline 1.0.26-alpha-4 โ†’ 1.0.27

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.
@@ -4,10 +4,9 @@ import yaml from 'js-yaml';
4
4
  import { $ } from 'zx';
5
5
  import lodash from 'lodash';
6
6
  import { appInfo, environmentConfig, getRepUrl } from './config.js';
7
- import { copy } from './copy.js';
7
+ import { copy2 } from './copy.js';
8
8
  import axios from 'axios';
9
- import { runPipeline } from './pipline.js';
10
- import { deployCore } from './jenkins.js';
9
+ import { deployCore, deployConnect } from './jenkins.js';
11
10
 
12
11
  /**
13
12
  * Clone the repository, read the YAML file, and return the parsed data and file paths.
@@ -22,6 +21,81 @@ function getRepoLocalPath(env) {
22
21
  return { repoPath, repoName };
23
22
  }
24
23
 
24
+ async function updateAndCommitConnectVersion(
25
+ toEnv,
26
+ toSite,
27
+ getComparedVersion,
28
+ connectDeployPath,
29
+ ) {
30
+ const connectToEnv = toEnv == 'qa' ? 'preprod' : toEnv;
31
+ const filePath = path.join(
32
+ connectDeployPath,
33
+ 'envs',
34
+ connectToEnv,
35
+ toSite,
36
+ 'dock.sh',
37
+ );
38
+
39
+ try {
40
+ let content = fs.readFileSync(filePath, 'utf8');
41
+ content = content.replace(
42
+ /IMAGE_VERSION=.*/,
43
+ `IMAGE_VERSION=git-commit-${getComparedVersion}`,
44
+ );
45
+ fs.writeFileSync(filePath, content, 'utf8');
46
+
47
+ // Git commands to stage, commit and push changes
48
+ await $`cd ${connectDeployPath} && git config user.email "gitops@docupace.com"`;
49
+ await $`cd ${connectDeployPath} && git add .`;
50
+ await $`cd ${connectDeployPath} && git commit -m "Update Connect version for ${toSite} in ${toEnv} to ${getComparedVersion}"`;
51
+ await $`cd ${connectDeployPath} && git push`;
52
+
53
+ console.log('๐Ÿงน Cleaning up...');
54
+ await $`rm -rf ${connectDeployPath}`;
55
+ console.log('โœ… Cleanup complete.');
56
+ } catch (error) {
57
+ console.error('Error updating Connect version:', error);
58
+ throw error;
59
+ }
60
+ }
61
+
62
+ async function fetchLoginFooter(env, site, isNewUrl) {
63
+ const url = isNewUrl
64
+ ? environmentConfig[env].newUrl(site)
65
+ : environmentConfig[env].oldUrl(site);
66
+ const endpoint = isNewUrl ? '/connect/loginFooter' : '_ui/loginFooter';
67
+ return await axios.get(`${url}${endpoint}`);
68
+ }
69
+
70
+ async function compareGetConnectSiteVersions(fromEnv, fromSite, toEnv, toSite) {
71
+ try {
72
+ let fromResponse, toResponse;
73
+ try {
74
+ fromResponse = await fetchLoginFooter(fromEnv, fromSite, true);
75
+ } catch {
76
+ fromResponse = await fetchLoginFooter(fromEnv, fromSite, false);
77
+ }
78
+
79
+ try {
80
+ toResponse = await fetchLoginFooter(toEnv, toSite, true);
81
+ } catch {
82
+ toResponse = await fetchLoginFooter(toEnv, toSite, false);
83
+ }
84
+
85
+ const fromMatch = fromResponse.data.match(/UI Build: ([a-f0-9]*)/);
86
+ const toMatch = toResponse.data.match(/UI Build: ([a-f0-9]*)/);
87
+
88
+ if (fromMatch && fromMatch[1] && toMatch && toMatch[1]) {
89
+ if (fromMatch[1] !== toMatch[1]) {
90
+ return fromMatch[1];
91
+ }
92
+ }
93
+ return false;
94
+ } catch (error) {
95
+ console.error('Error fetching Connect versions:', error);
96
+ throw error;
97
+ }
98
+ }
25
99
  function getRepoLocalPathByRepoSlug(repoSlug) {
26
100
  const repoName = `${repoSlug}`;
27
101
  const repoPath = path.join(process.cwd(), repoName);
@@ -34,7 +108,7 @@ function cleanUpRepoPath(repoPath) {
34
108
  console.log(`${repoPath} directory exists. Removing it...`);
35
109
  fs.rmSync(repoPath, {
36
110
  recursive: true,
37
- force: true
111
+ force: true,
38
112
  });
39
113
  }
40
114
  }
@@ -53,7 +127,7 @@ export async function cloneRepository(repoSlug) {
53
127
  const { repoPath, repoName } = getRepoLocalPathByRepoSlug(repoSlug);
54
128
  const repoUrl = getRepUrl(repoName);
55
129
 
56
- await cleanUpRepoPath(repoPath)
130
+ await cleanUpRepoPath(repoPath);
57
131
 
58
132
  console.log(`Cloning repository: ${repoName}`);
59
133
  await $`git clone --depth 1 ${repoUrl}`;
@@ -71,6 +145,23 @@ function getConfigPath(application, env, site, name) {
71
145
  return { repoPath, deployConfigFilePath };
72
146
  }
73
147
 
148
+ function getAppTypesFromRepo(env, site) {
149
+ const { repoPath } = getRepoLocalPath(env);
150
+ const deployConfigFilePath = path.join(repoPath, `dp/${site}`);
151
+ const applications = [];
152
+ if (fs.existsSync(deployConfigFilePath)) {
153
+ const files = fs.readdirSync(deployConfigFilePath);
154
+ files.forEach((file) => {
155
+ if (file.includes('.values.yaml')) {
156
+ const appName = file.split('.')[0];
157
+ applications.push(appName);
158
+ }
159
+ });
160
+ }
161
+
162
+ return { applications };
163
+ }
164
+
74
165
  export async function readDeployConfig(application, env, site, name) {
75
166
  const { deployConfigFilePath } = getConfigPath(application, env, site, name);
76
167
 
@@ -266,12 +357,72 @@ async function getCoreBranchName(fromEnv, fromSite) {
266
357
  return branchName;
267
358
  }
268
359
 
360
+ export async function deployApp(
361
+ application,
362
+ appDetails,
363
+ fromEnv,
364
+ fromSite,
365
+ toEnv,
366
+ toSite,
367
+ ) {
368
+ let changesMade = false;
369
+ console.log(`Processing application: ${application}`);
370
+
371
+ // Read the deployment configuration for the source environment and site
372
+ const { deployConfig: fromDeployConfig } = await readDeployConfig(
373
+ application,
374
+ fromEnv,
375
+ fromSite,
376
+ 'values',
377
+ );
378
+
379
+ if (fromEnv !== toEnv) {
380
+ await copy2(
381
+ appDetails.repositoryName,
382
+ fromEnv,
383
+ toEnv,
384
+ fromDeployConfig.image.tag,
385
+ );
386
+ }
387
+
388
+ // Read the deployment configuration for the target environment and site
389
+ const {
390
+ deployConfig: toDeployConfig,
391
+ deployConfigFilePath: toDeployConfigFilePath,
392
+ } = await readDeployConfig(application, toEnv, toSite, 'values');
393
+
394
+ // Update target configuration using attributes specified in appInfo
395
+ for (const attribute of appDetails.deployAttributes) {
396
+ const sourceValue = lodash.get(fromDeployConfig, attribute);
397
+
398
+ if (sourceValue !== undefined) {
399
+ // Update the target configuration with the source value
400
+ lodash.set(toDeployConfig, attribute, sourceValue);
401
+ changesMade = true;
402
+ }
403
+ }
404
+
405
+ const {
406
+ deployConfig: toDeployAppConfig,
407
+ deployConfigFilePath: toDeployAppConfigFilePath,
408
+ } = await readDeployConfig(application, toEnv, toSite, 'app');
409
+
410
+ toDeployAppConfig.revision = fromDeployConfig.image.tag;
411
+
412
+ // Write updated configuration to the target YAML file
413
+ writeDeployConfig(toDeployConfigFilePath, toDeployConfig);
414
+
415
+ writeDeployConfig(toDeployAppConfigFilePath, toDeployAppConfig);
416
+ return changesMade;
417
+ }
418
+
269
419
  export async function deployFromSite(
270
420
  fromEnv,
271
421
  fromSite,
272
422
  toEnv,
273
423
  toSite,
274
424
  isDeployCore,
425
+ isDeployConnect,
275
426
  ) {
276
427
  if (isDeployCore === 'true') {
277
428
  const branchName = await getCoreBranchName(fromEnv, fromSite);
@@ -288,6 +439,30 @@ export async function deployFromSite(
288
439
  });*/
289
440
  }
290
441
 
442
+ if (isDeployConnect === 'true') {
443
+ const branch = '';
444
+ const getComparedVersion = await compareGetConnectSiteVersions(
445
+ fromEnv,
446
+ fromSite,
447
+ toEnv,
448
+ toSite,
449
+ );
450
+ if (getComparedVersion) {
451
+ console.log('Version to deploy is: ', getComparedVersion);
452
+ const connectDeployPath = await cloneRepository('connect-deploy');
453
+ // update target version set to git-commit-${getCommparedVersion}}
454
+ await updateAndCommitConnectVersion(
455
+ toEnv,
456
+ toSite,
457
+ getComparedVersion,
458
+ connectDeployPath,
459
+ );
460
+ // save and deploy
461
+ const runLiquibase = true;
462
+ await deployConnect(toEnv, toSite, runLiquibase, branch);
463
+ }
464
+ }
465
+
291
466
  // Clone repositories for source and target environments
292
467
  const fromRepoPath = await cloneEnvRepository(fromEnv);
293
468
  const toRepoPath =
@@ -295,52 +470,53 @@ export async function deployFromSite(
295
470
 
296
471
  // Initialize a flag to track changes
297
472
  let changesMade = false;
298
-
473
+ const applications = await getAppTypesFromRepo(toEnv, toSite);
474
+ console.log(applications);
299
475
  // Iterate over applications in appInfo
300
- for (const [application, appDetails] of Object.entries(appInfo)) {
301
- console.log(`Processing application: ${application}`);
302
476
 
303
- // Read the deployment configuration for the source environment and site
304
- const { deployConfig: fromDeployConfig } = await readDeployConfig(
305
- application,
306
- fromEnv,
477
+ let appInfoLocal = Object.fromEntries(
478
+ applications.applications
479
+ .filter((application) =>
480
+ Object.prototype.hasOwnProperty.call(appInfo, application),
481
+ )
482
+ .map((application) => [application, appInfo[application]]),
483
+ );
484
+
485
+ // let appInfoLocal = {};
486
+ // for (const application of applications.applications) {
487
+ // if (Object.prototype.hasOwnProperty.call(appInfo, application)) {
488
+ // appInfoLocal[application] = appInfo[application];
489
+ // }
490
+ // }
491
+
492
+ if (Object.keys(appInfoLocal).length === 0) {
493
+ const { deployConfig: toDeployAppConfig } = await readDeployConfig(
307
494
  fromSite,
308
- 'values',
495
+ toEnv,
496
+ toSite,
497
+ 'app',
309
498
  );
310
499
 
311
- if (fromEnv !== toEnv) {
312
- await copy(application, fromEnv, toEnv, fromDeployConfig.image.tag);
313
- }
314
-
315
- // Read the deployment configuration for the target environment and site
316
- const {
317
- deployConfig: toDeployConfig,
318
- deployConfigFilePath: toDeployConfigFilePath,
319
- } = await readDeployConfig(application, toEnv, toSite, 'values');
500
+ appInfoLocal[fromSite] = {
501
+ repositoryName: toDeployAppConfig.repo,
502
+ deployAttributes: ['image.tag'],
503
+ };
504
+ }
320
505
 
321
- // Update target configuration using attributes specified in appInfo
322
- for (const attribute of appDetails.deployAttributes) {
323
- const sourceValue = lodash.get(fromDeployConfig, attribute);
506
+ console.log('appinfoLocal', appInfoLocal);
324
507
 
325
- if (sourceValue !== undefined) {
326
- // Update the target configuration with the source value
327
- lodash.set(toDeployConfig, attribute, sourceValue);
328
- changesMade = true;
329
- }
508
+ for (const [application, appDetails] of Object.entries(appInfoLocal)) {
509
+ let cm = await deployApp(
510
+ application,
511
+ appDetails,
512
+ fromEnv,
513
+ fromSite,
514
+ toEnv,
515
+ toSite,
516
+ );
517
+ if (cm) {
518
+ changesMade = true;
330
519
  }
331
-
332
- const {
333
- deployConfig: toDeployAppConfig,
334
- deployConfigFilePath: toDeployAppConfigFilePath,
335
- } = await readDeployConfig(application, toEnv, toSite, 'app');
336
-
337
- toDeployAppConfig.revision = fromDeployConfig.image.tag;
338
-
339
- // Write updated configuration to the target YAML file
340
- writeDeployConfig(toDeployConfigFilePath, toDeployConfig);
341
-
342
- writeDeployConfig(toDeployAppConfigFilePath, toDeployAppConfig);
343
-
344
520
  }
345
521
 
346
522
  // Push all changes if any updates were made
@@ -26,6 +26,7 @@ export async function deployCore(env, site, liquibase, gitBranch) {
26
26
  });
27
27
  }
28
28
 
29
+ // eslint-disable-next-line no-unused-vars
29
30
  export async function deployConnect(env, site, liquibase, branch) {
30
31
  const parameters = {
31
32
  BUILD_ENVIRONMENT: env,
@@ -1,115 +1,114 @@
1
- import axios from 'axios';
2
- import { getBitbucketInfo } from './config.js';
3
-
4
- const BITBUCKET_BASE_URL = 'https://api.bitbucket.org/2.0';
5
-
6
- const BITBUCKET_WS_URL = 'https://bitbucket.org/dp-cloud';
7
-
8
- async function triggerPipelineByName(
9
- repository,
10
- pipelineName,
11
- branch,
12
- variables,
13
- ) {
14
- const { username, password, workspace } = getBitbucketInfo();
15
- const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/`;
16
- const auth = {
17
- username: username,
18
- password: password,
19
- };
20
-
21
- const payload = {
22
- target: {
23
- type: 'pipeline_ref_target',
24
- ref_type: 'branch',
25
- ref_name: branch,
26
- selector: {
27
- type: 'custom',
28
- pattern: pipelineName,
29
- },
30
- },
31
- variables: variables
32
- ? Object.entries(variables).map(([key, value]) => ({
33
- key,
34
- value,
35
- secured: false, // Set to true if the variable should be secure
36
- }))
37
- : undefined,
38
- };
39
-
40
- try {
41
- const response = await axios.post(url, payload, { auth });
42
- return response.data;
43
- } catch (error) {
44
- console.error(
45
- 'Error triggering custom pipeline:',
46
- error.response?.data || error.message,
47
- );
48
- throw error;
49
- }
50
- }
51
-
52
- async function getPipelineStatus(repository, pipelineUUID) {
53
- const { username, password, workspace } = getBitbucketInfo();
54
- const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/${pipelineUUID}`;
55
- const auth = {
56
- username: username,
57
- password: password,
58
- };
59
-
60
- try {
61
- const response = await axios.get(url, { auth });
62
- return response.data.state.name;
63
- } catch (error) {
64
- console.error(
65
- 'Error fetching pipeline status:',
66
- error.response?.data || error.message,
67
- );
68
- throw error;
69
- }
70
- }
71
-
72
- export async function runPipeline(
73
- repository,
74
- pipelineName,
75
- branch,
76
- variables,
77
- wait = false,
78
- ) {
79
- try {
80
- console.log(
81
- `Triggering custom pipeline: ${pipelineName} for branch: ${branch}...`,
82
- );
83
- const pipeline = await triggerPipelineByName(
84
- repository,
85
- pipelineName,
86
- branch,
87
- variables,
88
- );
89
-
90
- const pipelineUUID = pipeline.uuid;
91
- const buildNumber = pipeline.build_number;
92
-
93
- console.log(`Pipeline triggered with UUID: ${pipelineUUID}`);
94
- console.log(
95
- `See results here: ${BITBUCKET_WS_URL}/${repository}/piplines/results/${buildNumber}`,
96
- );
97
-
98
- if (!wait) {
99
- return;
100
- }
101
-
102
-
103
- let status = '';
104
- do {
105
- console.log('Checking pipeline status...');
106
- await new Promise((resolve) => setTimeout(resolve, 10000)); // Wait 10 seconds
107
- status = await getPipelineStatus(repository, pipelineUUID);
108
- console.log(`Pipeline status: ${status}`);
109
- } while (['IN_PROGRESS', 'PENDING', 'RUNNING'].includes(status));
110
-
111
- console.log(`Pipeline completed with status: ${status}`);
112
- } catch (error) {
113
- console.error('Error monitoring pipeline:', error.message);
114
- }
115
- }
1
+ import axios from 'axios';
2
+ import { getBitbucketInfo } from './config.js';
3
+
4
+ const BITBUCKET_BASE_URL = 'https://api.bitbucket.org/2.0';
5
+
6
+ const BITBUCKET_WS_URL = 'https://bitbucket.org/dp-cloud';
7
+
8
+ async function triggerPipelineByName(
9
+ repository,
10
+ pipelineName,
11
+ branch,
12
+ variables,
13
+ ) {
14
+ const { username, password, workspace } = getBitbucketInfo();
15
+ const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/`;
16
+ const auth = {
17
+ username: username,
18
+ password: password,
19
+ };
20
+
21
+ const payload = {
22
+ target: {
23
+ type: 'pipeline_ref_target',
24
+ ref_type: 'branch',
25
+ ref_name: branch,
26
+ selector: {
27
+ type: 'custom',
28
+ pattern: pipelineName,
29
+ },
30
+ },
31
+ variables: variables
32
+ ? Object.entries(variables).map(([key, value]) => ({
33
+ key,
34
+ value,
35
+ secured: false, // Set to true if the variable should be secure
36
+ }))
37
+ : undefined,
38
+ };
39
+
40
+ try {
41
+ const response = await axios.post(url, payload, { auth });
42
+ return response.data;
43
+ } catch (error) {
44
+ console.error(
45
+ 'Error triggering custom pipeline:',
46
+ error.response?.data || error.message,
47
+ );
48
+ throw error;
49
+ }
50
+ }
51
+
52
+ async function getPipelineStatus(repository, pipelineUUID) {
53
+ const { username, password, workspace } = getBitbucketInfo();
54
+ const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/${pipelineUUID}`;
55
+ const auth = {
56
+ username: username,
57
+ password: password,
58
+ };
59
+
60
+ try {
61
+ const response = await axios.get(url, { auth });
62
+ return response.data.state.name;
63
+ } catch (error) {
64
+ console.error(
65
+ 'Error fetching pipeline status:',
66
+ error.response?.data || error.message,
67
+ );
68
+ throw error;
69
+ }
70
+ }
71
+
72
+ export async function runPipeline(
73
+ repository,
74
+ pipelineName,
75
+ branch,
76
+ variables,
77
+ wait = false,
78
+ ) {
79
+ try {
80
+ console.log(
81
+ `Triggering custom pipeline: ${pipelineName} for branch: ${branch}...`,
82
+ );
83
+ const pipeline = await triggerPipelineByName(
84
+ repository,
85
+ pipelineName,
86
+ branch,
87
+ variables,
88
+ );
89
+
90
+ const pipelineUUID = pipeline.uuid;
91
+ const buildNumber = pipeline.build_number;
92
+
93
+ console.log(`Pipeline triggered with UUID: ${pipelineUUID}`);
94
+ console.log(
95
+ `See results here: ${BITBUCKET_WS_URL}/${repository}/piplines/results/${buildNumber}`,
96
+ );
97
+
98
+ if (!wait) {
99
+ return;
100
+ }
101
+
102
+ let status = '';
103
+ do {
104
+ console.log('Checking pipeline status...');
105
+ await new Promise((resolve) => setTimeout(resolve, 10000)); // Wait 10 seconds
106
+ status = await getPipelineStatus(repository, pipelineUUID);
107
+ console.log(`Pipeline status: ${status}`);
108
+ } while (['IN_PROGRESS', 'PENDING', 'RUNNING'].includes(status));
109
+
110
+ console.log(`Pipeline completed with status: ${status}`);
111
+ } catch (error) {
112
+ console.error('Error monitoring pipeline:', error.message);
113
+ }
114
+ }
@@ -1,48 +1,48 @@
1
- import { $ } from 'zx';
2
-
3
- export async function publish(GIT_SHA) {
4
- const BITBUCKET_REPO_SLUG = process.env.BITBUCKET_REPO_SLUG;
5
- const BUILD_IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:build-${process.env.BITBUCKET_BUILD_NUMBER}`;
6
- const IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}`;
7
- const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
8
-
9
- console.log(`Publishing Docker image: ${IMAGE_NAME}`);
10
-
11
- // Docker login
12
- await $`echo ${process.env.JF_REGISTRY_PASSWORD_DEV} | docker login --username ${process.env.JF_REGISTRY_USER_DEV} --password-stdin ${process.env.JF_REGISTRY_URL}`;
13
-
14
- // Check if the image already exists
15
- try {
16
- await $`docker manifest inspect ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
17
- console.log(
18
- `Tag sha-${GIT_SHA} already exists in the remote repository. Skipping push.`,
19
- );
20
- } catch {
21
- await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
22
- await $`docker push ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
23
- }
24
-
25
- // Tag and push build image
26
- await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
27
- await $`docker push ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
28
-
29
- // Fetch Git tags pointing to the current HEAD
30
- const gitTagsOutput = (await $`git tag --points-at HEAD`).stdout.trim();
31
- const gitTags = gitTagsOutput.split('\n').filter((tag) => tag);
32
-
33
- // Tag and push each Git tag as a Docker tag
34
- if (gitTags.length > 0) {
35
- console.log(`Found Git tags pointing to HEAD: ${gitTags.join(', ')}`);
36
- for (const gitTag of gitTags) {
37
- const dockerTag = `${JF_REGISTRY_FULL_URL}/${BITBUCKET_REPO_SLUG}:${gitTag}`;
38
- console.log(`Tagging and pushing Docker image for Git tag: ${gitTag}`);
39
- await $`docker tag ${IMAGE_NAME} ${dockerTag}`;
40
- await $`docker push ${dockerTag}`;
41
- }
42
- } else {
43
- console.log('No Git tags found pointing to the current HEAD.');
44
- }
45
-
46
- // Docker logout
47
- await $`docker logout ${process.env.JF_REGISTRY_URL}`;
48
- }
1
+ import { $ } from 'zx';
2
+
3
+ export async function publish(GIT_SHA) {
4
+ const BITBUCKET_REPO_SLUG = process.env.BITBUCKET_REPO_SLUG;
5
+ const BUILD_IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:build-${process.env.BITBUCKET_BUILD_NUMBER}`;
6
+ const IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}`;
7
+ const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
8
+
9
+ console.log(`Publishing Docker image: ${IMAGE_NAME}`);
10
+
11
+ // Docker login
12
+ await $`echo ${process.env.JF_REGISTRY_PASSWORD_DEV} | docker login --username ${process.env.JF_REGISTRY_USER_DEV} --password-stdin ${process.env.JF_REGISTRY_URL}`;
13
+
14
+ // Check if the image already exists
15
+ try {
16
+ await $`docker manifest inspect ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
17
+ console.log(
18
+ `Tag sha-${GIT_SHA} already exists in the remote repository. Skipping push.`,
19
+ );
20
+ } catch {
21
+ await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
22
+ await $`docker push ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
23
+ }
24
+
25
+ // Tag and push build image
26
+ await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
27
+ await $`docker push ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
28
+
29
+ // Fetch Git tags pointing to the current HEAD
30
+ const gitTagsOutput = (await $`git tag --points-at HEAD`).stdout.trim();
31
+ const gitTags = gitTagsOutput.split('\n').filter((tag) => tag);
32
+
33
+ // Tag and push each Git tag as a Docker tag
34
+ if (gitTags.length > 0) {
35
+ console.log(`Found Git tags pointing to HEAD: ${gitTags.join(', ')}`);
36
+ for (const gitTag of gitTags) {
37
+ const dockerTag = `${JF_REGISTRY_FULL_URL}/${BITBUCKET_REPO_SLUG}:${gitTag}`;
38
+ console.log(`Tagging and pushing Docker image for Git tag: ${gitTag}`);
39
+ await $`docker tag ${IMAGE_NAME} ${dockerTag}`;
40
+ await $`docker push ${dockerTag}`;
41
+ }
42
+ } else {
43
+ console.log('No Git tags found pointing to the current HEAD.');
44
+ }
45
+
46
+ // Docker logout
47
+ await $`docker logout ${process.env.JF_REGISTRY_URL}`;
48
+ }
package/src/next/pull.js CHANGED
@@ -1,7 +1,7 @@
1
- import { $ } from 'zx';
2
-
3
- export async function pull(imageName) {
4
- const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
5
- console.log(`Pulling Docker image: ${JF_REGISTRY_FULL_URL}/${imageName}`);
6
- await $`docker pull ${JF_REGISTRY_FULL_URL}/${imageName}`;
7
- }
1
+ import { $ } from 'zx';
2
+
3
+ export async function pull(imageName) {
4
+ const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
5
+ console.log(`Pulling Docker image: ${JF_REGISTRY_FULL_URL}/${imageName}`);
6
+ await $`docker pull ${JF_REGISTRY_FULL_URL}/${imageName}`;
7
+ }