@docupace/pipeline 1.0.26-alpha-4 → 1.0.26

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/src/next/cli.js CHANGED
@@ -1,173 +1,185 @@
1
- #!/usr/bin/env node
2
-
3
- import { Command } from 'commander';
4
- import { pull } from './pull.js';
5
- import { sonar } from './sonar.js';
6
- import { publish } from './publish.js';
7
- import { deployFromSite } from './deploy.js';
8
- import { deployTemplate } from './deploy.js';
9
- import { copy } from './copy.js';
10
- import { vaultAddSiteData } from './vault.js';
11
- import { addApacheSite } from './apache.js';
12
- import { haproxySync } from './haproxy.js';
13
- import { connectClone } from './connect.js';
14
- import dotenv from 'dotenv';
15
-
16
- dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
17
-
18
- const program = new Command();
19
-
20
- import { $ } from 'zx';
21
- import {deployConnect, deployCore} from './jenkins.js';
22
- import { runPipeline } from './pipline.js';
23
-
24
- const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
25
-
26
- program
27
- .command('pull <imageName>')
28
- .description('Pull a Docker image from the registry')
29
- .action(async (imageName) => {
30
- await pull(imageName);
31
- });
32
-
33
- program
34
- .command('sonar')
35
- .description('Run Sonar analysis')
36
- .action(async () => {
37
- await sonar(GIT_SHA);
38
- });
39
-
40
- program
41
- .command('addApacheSite')
42
- .description('Add site to apache')
43
- .action(async () => {
44
- await addApacheSite();
45
- });
46
-
47
- program
48
- .command('connectClone')
49
- .description('Clone connect site')
50
- .action(async () => {
51
- await connectClone();
52
- });
53
-
54
- program
55
- .command('haproxySync')
56
- .description('Sync haproxy config')
57
- .action(async () => {
58
- await haproxySync();
59
- });
60
-
61
- program
62
- .command('vaultAddSiteData')
63
- .description('Add m2m auth0 data to vault')
64
- .requiredOption('-s, --site-name <siteName>', 'Site name')
65
- .requiredOption('-p, --site-config-remote-path <siteConfigRemotePath>', 'Site Config Remote Path')
66
- .action(async (options) => {
67
- const { siteName, siteConfigRemotePath } = options;
68
- await vaultAddSiteData(siteName, siteConfigRemotePath);
69
- });
70
-
71
- program
72
- .command('publish')
73
- .description('Publish a Docker image')
74
- .action(async () => {
75
- await publish(GIT_SHA);
76
- });
77
-
78
- program
79
- .command('deploy-from-site')
80
- .description('Deploy an application for a specific site')
81
- .requiredOption('-f, --from-env <fromEnv>', 'Source environment')
82
- .requiredOption('-t, --to-env <toEnv>', 'Target environment')
83
- .requiredOption('-F, --from-site <fromSite>', 'Source site')
84
- .requiredOption('-T, --to-site <toSite>', 'Target site')
85
- .option('-c, --deploy-core <deployCore>', 'Deploy Core', 'false')
86
- .action(async (options) => {
87
- const { fromEnv, fromSite, toEnv, toSite, deployCore } = options;
88
- await deployFromSite(fromEnv, fromSite, toEnv, toSite, deployCore);
89
- });
90
-
91
- program
92
- .command('deployTemplate <site>')
93
- .description('Deploy an application for a specific site')
94
- .action(async (site) => {
95
- await deployTemplate(site);
96
- });
97
-
98
- program
99
- .command('deploy-core <env> <site>')
100
- .description('Deploy Core')
101
- .option('-l, --liquibase <liquibase>', 'Application name', 'true')
102
- .option('-b, --branch <branch>', 'Branch', 'master')
103
- .action(async (env, site, options) => {
104
- await deployCore(env, site, options.liquibase, options.branch);
105
- });
106
-
107
- program
108
- .command('deploy-connect <env> <site>')
109
- .description('Deploy Core')
110
- .option('-l, --liquibase <liquibase>', 'Application name', 'true')
111
- .option('-b, --branch <branch>', 'Branch', 'master')
112
- .action(async (env, site, options) => {
113
- await deployConnect(env, site, options.liquibase, options.branch);
114
- });
115
-
116
- program
117
- .command('deploy-core-pipeline <env> <site>')
118
- .description('Deploy Core')
119
- .option('-l, --liquibase <liquibase>', 'Application name', 'true')
120
- .option('-b, --branch <branch>', 'Branch', 'master')
121
- .action(async (env, site, options) => {
122
- await runPipeline('site-deploy', 'deploy-core', 'main', {
123
- ENV: env,
124
- SITE: site,
125
- LIQUIBASE: options.liquibase,
126
- BRANCH: options.branch,
127
- });
128
- });
129
-
130
- program
131
- .command('copy')
132
- .description('Copy a Docker image between registries')
133
- .requiredOption('-a, --application <application>', 'Application name')
134
- .requiredOption('-f, --from-env <fromEnv>', 'Source environment')
135
- .requiredOption('-t, --to-env <toEnv>', 'Target environment')
136
- .requiredOption('-g, --tag <tag>', 'Image tag')
137
- .action(async (options) => {
138
- const { application, fromEnv, toEnv, tag } = options;
139
- await copy(application, fromEnv, toEnv, tag);
140
- });
141
-
142
- program
143
- .command('run-pipeline')
144
- .description('Trigger a pipeline by name')
145
- .requiredOption('-r, --repository <repository>', 'Repository name')
146
- .requiredOption('-p, --pipeline-name <pipelineName>', 'Pipeline name')
147
- .requiredOption('-b, --branch <branch>', 'Branch name')
148
- .option(
149
- '-v, --variables <key=value>',
150
- 'Pipeline variable as key=value pair',
151
- (value, previous) => {
152
- const [key, val] = value.split('=');
153
- if (!key || val === undefined) {
154
- throw new Error(`Invalid variable format: ${value}. Use key=value.`);
155
- }
156
- return { ...previous, [key]: val };
157
- },
158
- {},
159
- )
160
- .option('-w, --wait', 'Wait for the pipeline to complete', false) // Defaults to false
161
- .action(async (cmdObj) => {
162
- try {
163
- const { repository, pipelineName, branch, variables, wait } = cmdObj;
164
-
165
- // Call the triggerPipelineByName function
166
- await runPipeline(repository, pipelineName, branch, variables, wait);
167
- } catch (error) {
168
- console.error('Error triggering pipeline:', error.message);
169
- process.exit(1);
170
- }
171
- });
172
-
173
- program.parse(process.argv);
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from 'commander';
4
+ import { pull } from './pull.js';
5
+ import { sonar } from './sonar.js';
6
+ import { publish } from './publish.js';
7
+ import { deployFromSite } from './deploy.js';
8
+ import { deployTemplate } from './deploy.js';
9
+ import { copy } from './copy.js';
10
+ import { vaultAddSiteData } from './vault.js';
11
+ import { addApacheSite } from './apache.js';
12
+ import { haproxySync } from './haproxy.js';
13
+ import { connectClone } from './connect.js';
14
+ import dotenv from 'dotenv';
15
+
16
+ dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
17
+
18
+ const program = new Command();
19
+
20
+ import { $ } from 'zx';
21
+ import { deployConnect, deployCore } from './jenkins.js';
22
+ import { runPipeline } from './pipline.js';
23
+
24
+ const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
25
+
26
+ program
27
+ .command('pull <imageName>')
28
+ .description('Pull a Docker image from the registry')
29
+ .action(async (imageName) => {
30
+ await pull(imageName);
31
+ });
32
+
33
+ program
34
+ .command('sonar')
35
+ .description('Run Sonar analysis')
36
+ .action(async () => {
37
+ await sonar(GIT_SHA);
38
+ });
39
+
40
+ program
41
+ .command('addApacheSite')
42
+ .description('Add site to apache')
43
+ .action(async () => {
44
+ await addApacheSite();
45
+ });
46
+
47
+ program
48
+ .command('connectClone')
49
+ .description('Clone connect site')
50
+ .action(async () => {
51
+ await connectClone();
52
+ });
53
+
54
+ program
55
+ .command('haproxySync')
56
+ .description('Sync haproxy config')
57
+ .action(async () => {
58
+ await haproxySync();
59
+ });
60
+
61
+ program
62
+ .command('vaultAddSiteData')
63
+ .description('Add m2m auth0 data to vault')
64
+ .requiredOption('-s, --site-name <siteName>', 'Site name')
65
+ .requiredOption(
66
+ '-p, --site-config-remote-path <siteConfigRemotePath>',
67
+ 'Site Config Remote Path',
68
+ )
69
+ .action(async (options) => {
70
+ const { siteName, siteConfigRemotePath } = options;
71
+ await vaultAddSiteData(siteName, siteConfigRemotePath);
72
+ });
73
+
74
+ program
75
+ .command('publish')
76
+ .description('Publish a Docker image')
77
+ .action(async () => {
78
+ await publish(GIT_SHA);
79
+ });
80
+
81
+ program
82
+ .command('deploy-from-site')
83
+ .description('Deploy an application for a specific site')
84
+ .requiredOption('-f, --from-env <fromEnv>', 'Source environment')
85
+ .requiredOption('-t, --to-env <toEnv>', 'Target environment')
86
+ .requiredOption('-F, --from-site <fromSite>', 'Source site')
87
+ .requiredOption('-T, --to-site <toSite>', 'Target site')
88
+ .option('-c, --deploy-core <deployCore>', 'Deploy Core', 'false')
89
+ .option('-C, --deploy-connect <deployConnect>', 'Deploy Connect', 'false')
90
+ .action(async (options) => {
91
+ const { fromEnv, fromSite, toEnv, toSite, deployCore, deployConnect } =
92
+ options;
93
+ await deployFromSite(
94
+ fromEnv,
95
+ fromSite,
96
+ toEnv,
97
+ toSite,
98
+ deployCore,
99
+ deployConnect,
100
+ );
101
+ });
102
+
103
+ program
104
+ .command('deployTemplate <site>')
105
+ .description('Deploy an application for a specific site')
106
+ .action(async (site) => {
107
+ await deployTemplate(site);
108
+ });
109
+
110
+ program
111
+ .command('deploy-core <env> <site>')
112
+ .description('Deploy Core')
113
+ .option('-l, --liquibase <liquibase>', 'Application name', 'true')
114
+ .option('-b, --branch <branch>', 'Branch', 'master')
115
+ .action(async (env, site, options) => {
116
+ await deployCore(env, site, options.liquibase, options.branch);
117
+ });
118
+
119
+ program
120
+ .command('deploy-connect <env> <site>')
121
+ .description('Deploy Core')
122
+ .option('-l, --liquibase <liquibase>', 'Application name', 'true')
123
+ .option('-b, --branch <branch>', 'Branch', 'master')
124
+ .action(async (env, site, options) => {
125
+ await deployConnect(env, site, options.liquibase, options.branch);
126
+ });
127
+
128
+ program
129
+ .command('deploy-core-pipeline <env> <site>')
130
+ .description('Deploy Core')
131
+ .option('-l, --liquibase <liquibase>', 'Application name', 'true')
132
+ .option('-b, --branch <branch>', 'Branch', 'master')
133
+ .action(async (env, site, options) => {
134
+ await runPipeline('site-deploy', 'deploy-core', 'main', {
135
+ ENV: env,
136
+ SITE: site,
137
+ LIQUIBASE: options.liquibase,
138
+ BRANCH: options.branch,
139
+ });
140
+ });
141
+
142
+ program
143
+ .command('copy')
144
+ .description('Copy a Docker image between registries')
145
+ .requiredOption('-a, --application <application>', 'Application name')
146
+ .requiredOption('-f, --from-env <fromEnv>', 'Source environment')
147
+ .requiredOption('-t, --to-env <toEnv>', 'Target environment')
148
+ .requiredOption('-g, --tag <tag>', 'Image tag')
149
+ .action(async (options) => {
150
+ const { application, fromEnv, toEnv, tag } = options;
151
+ await copy(application, fromEnv, toEnv, tag);
152
+ });
153
+
154
+ program
155
+ .command('run-pipeline')
156
+ .description('Trigger a pipeline by name')
157
+ .requiredOption('-r, --repository <repository>', 'Repository name')
158
+ .requiredOption('-p, --pipeline-name <pipelineName>', 'Pipeline name')
159
+ .requiredOption('-b, --branch <branch>', 'Branch name')
160
+ .option(
161
+ '-v, --variables <key=value>',
162
+ 'Pipeline variable as key=value pair',
163
+ (value, previous) => {
164
+ const [key, val] = value.split('=');
165
+ if (!key || val === undefined) {
166
+ throw new Error(`Invalid variable format: ${value}. Use key=value.`);
167
+ }
168
+ return { ...previous, [key]: val };
169
+ },
170
+ {},
171
+ )
172
+ .option('-w, --wait', 'Wait for the pipeline to complete', false) // Defaults to false
173
+ .action(async (cmdObj) => {
174
+ try {
175
+ const { repository, pipelineName, branch, variables, wait } = cmdObj;
176
+
177
+ // Call the triggerPipelineByName function
178
+ await runPipeline(repository, pipelineName, branch, variables, wait);
179
+ } catch (error) {
180
+ console.error('Error triggering pipeline:', error.message);
181
+ process.exit(1);
182
+ }
183
+ });
184
+
185
+ program.parse(process.argv);