@docupace/pipeline 1.0.5-alpha.10 → 1.0.5-alpha.12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.5-alpha.10",
3
+ "version": "1.0.5-alpha.12",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -34,6 +34,7 @@
34
34
  "prettier": "^3.4.2"
35
35
  },
36
36
  "scripts": {
37
+ "test-deploy-core": "dp-next-cli deploy-core dev template",
37
38
  "test-deploy-from-site": "dp-next-cli deploy-from-site --from-env dev --to-env dev --from-site financialdev --to-site template"
38
39
  }
39
40
  }
package/src/next/cli.js CHANGED
@@ -16,6 +16,7 @@ const program = new Command();
16
16
  // GIT SHA computation
17
17
  import { $ } from 'zx';
18
18
  import { deployCore } from './jenkins.js';
19
+ import { runPipeline } from './pipline.js';
19
20
  const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
20
21
 
21
22
  program
@@ -61,8 +62,21 @@ program
61
62
  program
62
63
  .command('deploy-core <env> <site>')
63
64
  .description('Deploy Core')
64
- .action(async (env, site) => {
65
- await deployCore(env, site);
65
+ .option('-l, --liquibase <liquibase>', 'Application name', 'true')
66
+ .action(async (env, site, liquibase) => {
67
+ await deployCore(env, site, liquibase);
68
+ });
69
+
70
+ program
71
+ .command('deploy-core-pipeline <env> <site>')
72
+ .description('Deploy Core')
73
+ .option('-l, --liquibase <liquibase>', 'Application name', 'true')
74
+ .action(async (env, site, liquibase) => {
75
+ await runPipeline('site-deploy', 'deploy-core', {
76
+ ENV: env,
77
+ SITE: site,
78
+ LIQUIBASE: liquibase,
79
+ });
66
80
  });
67
81
 
68
82
  program
@@ -35,7 +35,14 @@ export const getBitbucketInfo = () => {
35
35
  return {
36
36
  username: process.env.BITBUCKET_USERNAME,
37
37
  password: process.env.BITBUCKET_APP_PASSWORD,
38
+ workspace: 'dp-cloud',
38
39
  };
39
40
  };
40
41
 
42
+ export const getRepUrl = (repoName) => {
43
+ const { username, password, workspace } = getBitbucketInfo();
44
+ const repoUrl = `https://${username}:${password}@bitbucket.org/${workspace}/${repoName}.git`;
45
+ return repoUrl;
46
+ }
47
+
41
48
  export const jfRegistryUrl = 'registry.paperout.com';
@@ -3,7 +3,7 @@ import path from 'path';
3
3
  import yaml from 'js-yaml';
4
4
  import { $ } from 'zx';
5
5
  import lodash from 'lodash';
6
- import { appInfo, getBitbucketInfo } from './config.js';
6
+ import {appInfo, getBitbucketInfo, getRepUrl} from './config.js';
7
7
  import { copy } from './copy.js';
8
8
 
9
9
  /**
@@ -21,8 +21,7 @@ function getRepoLocalPath(env) {
21
21
 
22
22
  async function cloneEnvRepository(env) {
23
23
  const { repoPath, repoName } = getRepoLocalPath(env);
24
- const { username, password } = getBitbucketInfo();
25
- const repoUrl = `https://${username}:${password}@bitbucket.org/dp-cloud/${repoName}.git`;
24
+ const repoUrl = getRepUrl(repoName);
26
25
  console.log(`Cloning repository: ${repoName}`);
27
26
  await $`git clone ${repoUrl}`;
28
27
  console.log(`Repository cloned to: ${repoPath}`);
@@ -5,11 +5,11 @@ const JOB_NAME = 'auto-deploy-site';
5
5
  const USERNAME = process.env.CORE_JENKINS_USERNAME;
6
6
  const API_TOKEN = process.env.CORE_JENKINS_API_TOKEN;
7
7
 
8
- export async function deployCore(env, site) {
8
+ export async function deployCore(env, site, liquibase) {
9
9
  const parameters = {
10
10
  environment: env,
11
11
  site: site,
12
- runLiquibase: 'true',
12
+ runLiquibase: liquibase,
13
13
  };
14
14
 
15
15
  try {
@@ -0,0 +1,101 @@
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
+ async function triggerPipelineByName(
7
+ repository,
8
+ pipelineName,
9
+ branch,
10
+ variables,
11
+ ) {
12
+ const { username, password, workspace } = getBitbucketInfo();
13
+ const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/`;
14
+ const auth = {
15
+ username: username,
16
+ password: password,
17
+ };
18
+
19
+ const payload = {
20
+ target: {
21
+ ref_type: 'branch',
22
+ ref_name: branch,
23
+ selector: {
24
+ type: 'custom',
25
+ pattern: pipelineName,
26
+ },
27
+ },
28
+ variables: Object.entries(variables).map(([key, value]) => ({
29
+ key,
30
+ value,
31
+ secured: false, // Set to true if the variable should be secure
32
+ })),
33
+ };
34
+
35
+ try {
36
+ const response = await axios.post(url, payload, { auth });
37
+ return response.data;
38
+ } catch (error) {
39
+ console.error(
40
+ 'Error triggering custom pipeline:',
41
+ error.response?.data || error.message,
42
+ );
43
+ throw error;
44
+ }
45
+ }
46
+
47
+ async function getPipelineStatus(repository, pipelineUUID) {
48
+ const { username, password, workspace } = getBitbucketInfo();
49
+ const url = `${BITBUCKET_BASE_URL}/repositories/${workspace}/${repository}/pipelines/${pipelineUUID}`;
50
+ const auth = {
51
+ username: username,
52
+ password: password,
53
+ };
54
+
55
+ try {
56
+ const response = await axios.get(url, { auth });
57
+ return response.data.state.name;
58
+ } catch (error) {
59
+ console.error(
60
+ 'Error fetching pipeline status:',
61
+ error.response?.data || error.message,
62
+ );
63
+ throw error;
64
+ }
65
+ }
66
+
67
+ export async function runPipeline(repository, pipelineName, branch, variables) {
68
+ try {
69
+ console.log(
70
+ `Triggering custom pipeline: ${pipelineName} for branch: ${branch}...`,
71
+ );
72
+ const pipeline = await triggerPipelineByName(
73
+ repository,
74
+ pipelineName,
75
+ branch,
76
+ variables,
77
+ );
78
+ const pipelineUUID = pipeline.uuid;
79
+
80
+ console.log(`Pipeline triggered with UUID: ${pipelineUUID}`);
81
+ let status = '';
82
+ do {
83
+ console.log('Checking pipeline status...');
84
+ await new Promise((resolve) => setTimeout(resolve, 10000)); // Wait 10 seconds
85
+ status = await getPipelineStatus(repository, pipelineUUID);
86
+ console.log(`Pipeline status: ${status}`);
87
+ } while (['IN_PROGRESS', 'PENDING', 'RUNNING'].includes(status));
88
+
89
+ console.log(`Pipeline completed with status: ${status}`);
90
+ } catch (error) {
91
+ console.error('Error monitoring pipeline:', error.message);
92
+ }
93
+ }
94
+
95
+ // Example: Trigger and monitor a custom pipeline
96
+ const variables = {
97
+ ENV: 'production',
98
+ DEPLOY_VERSION: 'v1.2.3',
99
+ };
100
+
101
+ runPipeline('site-deploy', 'deploy-to-production', 'main', variables);