@docupace/pipeline 1.0.4-6.0.1 → 1.0.4

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.
@@ -1,47 +1,44 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
-
4
- export async function validateChangesets(directoryPath) {
5
- try {
6
- // Step 1: Read the directory for md files excluding README.md
7
- const allFiles = fs.readdirSync(directoryPath);
8
- const mdFiles = allFiles.filter(
9
- (file) => file.endsWith('.md') && file !== 'README.md',
10
- );
11
-
12
- // Step 2: Check for pre.json and parse it
13
- const preJsonPath = path.join(directoryPath, 'pre.json');
14
- let preJson;
15
-
16
- if (!fs.existsSync(preJsonPath) && mdFiles.length === 0) {
17
- throw new Error('Error: No pre.json and no md files found.');
18
- }
19
-
20
- if (fs.existsSync(preJsonPath)) {
21
- preJson = JSON.parse(fs.readFileSync(preJsonPath, 'utf-8'));
22
-
23
- if (preJson.mode == 'pre') {
24
- // Step 4a: Get list of changesets from pre.json
25
- const changesets = preJson.changesets || [];
26
- const changesetNames = changesets.map((change) => change);
27
-
28
- // Step 4b: Match files with the list of changesets
29
- const mdFileNamesWithoutExt = mdFiles.map((file) =>
30
- path.basename(file, '.md'),
31
- );
32
- const unmatchedFiles = mdFileNamesWithoutExt.filter(
33
- (fileName) => !changesetNames.includes(fileName),
34
- );
35
-
36
- if (unmatchedFiles.length == 0) {
37
- throw new Error('Error: No new MD files found:');
38
- }
39
- }
40
- }
41
-
42
- console.log('Validation successful.');
43
- } catch (error) {
44
- console.log(error.message);
45
- throw error;
46
- }
47
- }
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ export async function validateChangesets(directoryPath) {
5
+ try {
6
+ // Step 1: Read the directory for md files excluding README.md
7
+ const allFiles = fs.readdirSync(directoryPath);
8
+ const mdFiles = allFiles.filter(file => file.endsWith('.md') && file !== 'README.md');
9
+
10
+ // Step 2: Check for pre.json and parse it
11
+ const preJsonPath = path.join(directoryPath, 'pre.json');
12
+ let preJson;
13
+
14
+ if (!fs.existsSync(preJsonPath) && mdFiles.length === 0) {
15
+ throw new Error("Error: No pre.json and no md files found.")
16
+ }
17
+
18
+ if (fs.existsSync(preJsonPath)) {
19
+ preJson = JSON.parse(fs.readFileSync(preJsonPath, 'utf-8'));
20
+
21
+ if(preJson.mode == 'pre') {
22
+ // Step 4a: Get list of changesets from pre.json
23
+ const changesets = preJson.changesets || [];
24
+ const changesetNames = changesets.map(change => change);
25
+
26
+ // Step 4b: Match files with the list of changesets
27
+ const mdFileNamesWithoutExt = mdFiles.map(file => path.basename(file, '.md'));
28
+ const unmatchedFiles = mdFileNamesWithoutExt.filter(fileName => !changesetNames.includes(fileName));
29
+
30
+ if (unmatchedFiles.length == 0) {
31
+ throw new Error("Error: No new MD files found:");
32
+ }
33
+ }
34
+ }
35
+
36
+ console.log("Validation successful.");
37
+ } catch (error) {
38
+ console.log(error.message);
39
+ throw(error);
40
+ }
41
+ }
42
+
43
+
44
+
package/src/next/cli.js CHANGED
@@ -4,207 +4,56 @@ import { Command } from 'commander';
4
4
  import { pull } from './pull.js';
5
5
  import { sonar } from './sonar.js';
6
6
  import { publish } from './publish.js';
7
- import {
8
- deployAppWithTag,
9
- deployFromSite,
10
- getDefaultDeploySite,
11
- getDeployTag,
12
- } from './deploy.js';
7
+ import { deploy } from './deploy.js';
13
8
  import { deployTemplate } from './deploy.js';
14
9
  import { copy } from './copy.js';
15
- import { vaultAddSiteData } from './vault.js';
16
- import { addApacheSite } from './apache.js';
17
- import { haproxySync } from './haproxy.js';
18
- import { connectClone } from './connect.js';
19
- import dotenv from 'dotenv';
20
-
21
- dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
22
10
 
23
11
  const program = new Command();
24
12
 
13
+ // GIT SHA computation
25
14
  import { $ } from 'zx';
26
- import { deployConnect, deployCore } from './jenkins.js';
27
- import { runPipeline } from './pipline.js';
28
-
29
15
  const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
30
16
 
31
17
  program
32
- .command('pull <imageName>')
33
- .description('Pull a Docker image from the registry')
34
- .action(async (imageName) => {
35
- await pull(imageName);
36
- });
37
-
38
- program
39
- .command('sonar')
40
- .description('Run Sonar analysis')
41
- .action(async () => {
42
- await sonar(GIT_SHA);
43
- });
44
-
45
- program
46
- .command('addApacheSite')
47
- .description('Add site to apache')
48
- .action(async () => {
49
- await addApacheSite();
50
- });
51
-
52
- program
53
- .command('connectClone')
54
- .description('Clone connect site')
55
- .action(async () => {
56
- await connectClone();
57
- });
58
-
59
- program
60
- .command('haproxySync')
61
- .description('Sync haproxy config')
62
- .action(async () => {
63
- await haproxySync();
64
- });
65
-
66
- program
67
- .command('vaultAddSiteData')
68
- .description('Add m2m auth0 data to vault')
69
- .requiredOption('-s, --site-name <siteName>', 'Site name')
70
- .requiredOption(
71
- '-p, --site-config-remote-path <siteConfigRemotePath>',
72
- 'Site Config Remote Path',
73
- )
74
- .action(async (options) => {
75
- const { siteName, siteConfigRemotePath } = options;
76
- await vaultAddSiteData(siteName, siteConfigRemotePath);
77
- });
78
-
79
- program
80
- .command('publish')
81
- .description('Publish a Docker image')
82
- .action(async () => {
83
- await publish(GIT_SHA);
84
- });
85
-
86
- program
87
- .command('deploy-from-site')
88
- .description('Deploy an application for a specific site')
89
- .requiredOption('-f, --from-env <fromEnv>', 'Source environment')
90
- .requiredOption('-t, --to-env <toEnv>', 'Target environment')
91
- .requiredOption('-F, --from-site <fromSite>', 'Source site')
92
- .requiredOption('-T, --to-site <toSite>', 'Target site')
93
- .option('-c, --deploy-core <deployCore>', 'Deploy Core', 'false')
94
- .option('-C, --deploy-connect <deployConnect>', 'Deploy Connect', 'false')
95
- .action(async (options) => {
96
- const { fromEnv, fromSite, toEnv, toSite, deployCore, deployConnect } =
97
- options;
98
- await deployFromSite(
99
- fromEnv,
100
- fromSite,
101
- toEnv,
102
- toSite,
103
- deployCore,
104
- deployConnect,
105
- );
106
- });
107
-
108
- program
109
- .command('deploy-template')
110
- .description('Deploy an application for a specific site')
111
- .action(async () => {
112
- const deployTag = await getDeployTag();
113
- const { env, site } = await getDefaultDeploySite(deployTag);
114
- await deployTemplate(env, site, deployTag);
115
- });
116
-
117
- program
118
- .command('deployTemplate')
119
- .description('Deploy an application for a specific site')
120
- .action(async () => {
121
- const deployTag = await getDeployTag();
122
- const { env, site } = await getDefaultDeploySite(deployTag);
123
- await deployTemplate(env, site, deployTag);
124
- });
125
-
126
- program
127
- .command('deploy-app <application>')
128
- .description('Deploy an application for a specific site')
129
- .action(async (application) => {
130
- const deployTag = await getDeployTag();
131
- const { env, site } = await getDefaultDeploySite(deployTag);
132
- await deployAppWithTag(application, env, site, deployTag);
133
- });
18
+ .command('pull <imageName>')
19
+ .description('Pull a Docker image from the registry')
20
+ .action(async (imageName) => {
21
+ await pull(imageName);
22
+ });
134
23
 
135
24
  program
136
- .command('deploy-core <env> <site>')
137
- .description('Deploy Core')
138
- .option('-l, --liquibase <liquibase>', 'Application name', 'true')
139
- .option('-b, --branch <branch>', 'Branch', 'master')
140
- .action(async (env, site, options) => {
141
- await deployCore(env, site, options.liquibase, options.branch);
142
- });
25
+ .command('sonar')
26
+ .description('Run Sonar analysis')
27
+ .action(async () => {
28
+ await sonar(GIT_SHA);
29
+ });
143
30
 
144
31
  program
145
- .command('deploy-connect <env> <site>')
146
- .description('Deploy Core')
147
- .option('-l, --liquibase <liquibase>', 'Application name', 'true')
148
- .option('-b, --branch <branch>', 'Branch', 'master')
149
- .action(async (env, site, options) => {
150
- await deployConnect(env, site, options.liquibase, options.branch);
151
- });
32
+ .command('publish')
33
+ .description('Publish a Docker image')
34
+ .action(async () => {
35
+ await publish(GIT_SHA);
36
+ });
152
37
 
153
38
  program
154
- .command('deploy-core-pipeline <env> <site>')
155
- .description('Deploy Core')
156
- .option('-l, --liquibase <liquibase>', 'Application name', 'true')
157
- .option('-b, --branch <branch>', 'Branch', 'master')
158
- .action(async (env, site, options) => {
159
- await runPipeline('site-deploy', 'deploy-core', 'main', {
160
- ENV: env,
161
- SITE: site,
162
- LIQUIBASE: options.liquibase,
163
- BRANCH: options.branch,
39
+ .command('deploy <application> <site>')
40
+ .description('Deploy an application for a specific site')
41
+ .action(async (application, site) => {
42
+ await deploy(application, site);
164
43
  });
165
- });
166
44
 
167
45
  program
168
- .command('copy')
169
- .description('Copy a Docker image between registries')
170
- .requiredOption('-a, --application <application>', 'Application name')
171
- .requiredOption('-f, --from-env <fromEnv>', 'Source environment')
172
- .requiredOption('-t, --to-env <toEnv>', 'Target environment')
173
- .requiredOption('-g, --tag <tag>', 'Image tag')
174
- .action(async (options) => {
175
- const { application, fromEnv, toEnv, tag } = options;
176
- await copy(application, fromEnv, toEnv, tag);
177
- });
46
+ .command('deployTemplate <site>')
47
+ .description('Deploy an application for a specific site')
48
+ .action(async (site) => {
49
+ await deployTemplate(site);
50
+ });
178
51
 
179
52
  program
180
- .command('run-pipeline')
181
- .description('Trigger a pipeline by name')
182
- .requiredOption('-r, --repository <repository>', 'Repository name')
183
- .requiredOption('-p, --pipeline-name <pipelineName>', 'Pipeline name')
184
- .requiredOption('-b, --branch <branch>', 'Branch name')
185
- .option(
186
- '-v, --variables <key=value>',
187
- 'Pipeline variable as key=value pair',
188
- (value, previous) => {
189
- const [key, val] = value.split('=');
190
- if (!key || val === undefined) {
191
- throw new Error(`Invalid variable format: ${value}. Use key=value.`);
192
- }
193
- return { ...previous, [key]: val };
194
- },
195
- {},
196
- )
197
- .option('-w, --wait', 'Wait for the pipeline to complete', false) // Defaults to false
198
- .action(async (cmdObj) => {
199
- try {
200
- const { repository, pipelineName, branch, variables, wait } = cmdObj;
201
-
202
- // Call the triggerPipelineByName function
203
- await runPipeline(repository, pipelineName, branch, variables, wait);
204
- } catch (error) {
205
- console.error('Error triggering pipeline:', error.message);
206
- process.exit(1);
207
- }
208
- });
53
+ .command('copy')
54
+ .description('Copy a Docker image between registries')
55
+ .action(async () => {
56
+ await copy();
57
+ });
209
58
 
210
59
  program.parse(process.argv);
package/src/next/copy.js CHANGED
@@ -1,55 +1,27 @@
1
- import { $ } from 'zx';
2
- import { appInfo, getEnvInfo, jfRegistryUrl } from './config.js';
3
-
4
- /*
5
- TARGET_ENV
6
- PUBLISH_TAG
7
- REPOSITORY_NAME
8
- */
9
- export async function copy(application, fromEnv, toEnv, tag) {
10
- const envInfo = getEnvInfo();
11
- const repositoryName = appInfo[application].repositoryName;
12
- const fromRegistry = `${jfRegistryUrl}/${repositoryName}-${fromEnv}-docker-local`;
13
- const toRegistry = `${jfRegistryUrl}/${repositoryName}-${toEnv}-docker-local`;
14
- const imageName = `${repositoryName}:${tag}`;
15
- const fromFullImageName = `${fromRegistry}/${imageName}`;
16
- const toFullImageName = `${toRegistry}/${imageName}`;
17
-
18
- console.log(
19
- `Copying Docker image: ${fromFullImageName} -> ${toFullImageName}`,
20
- );
21
-
22
- // Login to source registry
23
- await $`echo ${envInfo[fromEnv].jfrog.password} | docker login --username ${envInfo[fromEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
24
- await $`docker pull ${fromFullImageName}`;
25
- await $`docker tag ${fromFullImageName} ${toFullImageName}`;
26
-
27
- // Login to target registry
28
- await $`echo ${envInfo[toEnv].jfrog.password} | docker login --username ${envInfo[toEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
29
- await $`docker push ${toFullImageName}`;
30
- }
31
-
32
- export async function copy2(repositoryName, fromEnv, toEnv, tag) {
33
- console.log(
34
- `Copying repository ${repositoryName} from ${fromEnv} to ${toEnv} for tag ${tag}`,
35
- );
36
- const envInfo = getEnvInfo();
37
- const fromRegistry = `${jfRegistryUrl}/${repositoryName}-${fromEnv}-docker-local`;
38
- const toRegistry = `${jfRegistryUrl}/${repositoryName}-${toEnv}-docker-local`;
39
- const imageName = `${repositoryName}:${tag}`;
40
- const fromFullImageName = `${fromRegistry}/${imageName}`;
41
- const toFullImageName = `${toRegistry}/${imageName}`;
42
-
43
- console.log(
44
- `Copying Docker image: ${fromFullImageName} -> ${toFullImageName}`,
45
- );
46
-
47
- // Login to source registry
48
- await $`echo ${envInfo[fromEnv].jfrog.password} | docker login --username ${envInfo[fromEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
49
- await $`docker pull ${fromFullImageName}`;
50
- await $`docker tag ${fromFullImageName} ${toFullImageName}`;
51
-
52
- // Login to target registry
53
- await $`echo ${envInfo[toEnv].jfrog.password} | docker login --username ${envInfo[toEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
54
- await $`docker push ${toFullImageName}`;
55
- }
1
+ import { $ } from 'zx';
2
+
3
+
4
+ /*
5
+ TARGET_ENV
6
+ PUBLISH_TAG
7
+ REPOSITORY_NAME
8
+ */
9
+ export async function copy() {
10
+ const JF_REGISTRY_URL = 'registry.paperout.com';
11
+ const SOURCE_REGISTRY = `${JF_REGISTRY_URL}/${process.env.REPOSITORY_NAME}-dev-docker-local`;
12
+ const TARGET_REGISTRY = `${JF_REGISTRY_URL}/${process.env.REPOSITORY_NAME}-${process.env.TARGET_ENV}-docker-local`;
13
+ const IMAGE_NAME = `${process.env.REPOSITORY_NAME}:${process.env.PUBLISH_TAG}`;
14
+ const SOURCE_FULL_IMAGE_NAME = `${SOURCE_REGISTRY}/${IMAGE_NAME}`;
15
+ const TARGET_FULL_IMAGE_NAME = `${TARGET_REGISTRY}/${IMAGE_NAME}`;
16
+
17
+ console.log(`Copying Docker image: ${SOURCE_FULL_IMAGE_NAME} -> ${TARGET_FULL_IMAGE_NAME}`);
18
+
19
+ // Login to source registry
20
+ await $`echo ${process.env.JF_REGISTRY_PASSWORD_DEV} | docker login --username ${process.env.JF_REGISTRY_USER_DEV} --password-stdin ${JF_REGISTRY_URL}`;
21
+ await $`docker pull ${SOURCE_FULL_IMAGE_NAME}`;
22
+ await $`docker tag ${SOURCE_FULL_IMAGE_NAME} ${TARGET_FULL_IMAGE_NAME}`;
23
+
24
+ // Login to target registry
25
+ await $`echo ${process.env.JF_REGISTRY_PASSWORD_QA} | docker login --username ${process.env.JF_REGISTRY_USER_QA} --password-stdin ${JF_REGISTRY_URL}`;
26
+ await $`docker push ${TARGET_FULL_IMAGE_NAME}`;
27
+ }