@docupace/pipeline 1.0.2-5.1 → 1.0.2

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,185 +1,59 @@
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);
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 { deploy } from './deploy.js';
8
+ import { deployTemplate } from './deploy.js';
9
+ import { copy } from './copy.js';
10
+
11
+ const program = new Command();
12
+
13
+ // GIT SHA computation
14
+ import { $ } from 'zx';
15
+ const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
16
+
17
+ program
18
+ .command('pull <imageName>')
19
+ .description('Pull a Docker image from the registry')
20
+ .action(async (imageName) => {
21
+ await pull(imageName);
22
+ });
23
+
24
+ program
25
+ .command('sonar')
26
+ .description('Run Sonar analysis')
27
+ .action(async () => {
28
+ await sonar(GIT_SHA);
29
+ });
30
+
31
+ program
32
+ .command('publish')
33
+ .description('Publish a Docker image')
34
+ .action(async () => {
35
+ await publish(GIT_SHA);
36
+ });
37
+
38
+ program
39
+ .command('deploy <application> <site>')
40
+ .description('Deploy an application for a specific site')
41
+ .action(async (application, site) => {
42
+ await deploy(application, site);
43
+ });
44
+
45
+ program
46
+ .command('deployTemplate <site>')
47
+ .description('Deploy an application for a specific site')
48
+ .action(async (site) => {
49
+ await deployTemplate(site);
50
+ });
51
+
52
+ program
53
+ .command('copy')
54
+ .description('Copy a Docker image between registries')
55
+ .action(async () => {
56
+ await copy();
57
+ });
58
+
59
+ program.parse(process.argv);
package/src/next/copy.js CHANGED
@@ -1,52 +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
- const envInfo = getEnvInfo();
34
- const fromRegistry = `${jfRegistryUrl}/${repositoryName}-${fromEnv}-docker-local`;
35
- const toRegistry = `${jfRegistryUrl}/${repositoryName}-${toEnv}-docker-local`;
36
- const imageName = `${repositoryName}:${tag}`;
37
- const fromFullImageName = `${fromRegistry}/${imageName}`;
38
- const toFullImageName = `${toRegistry}/${imageName}`;
39
-
40
- console.log(
41
- `Copying Docker image: ${fromFullImageName} -> ${toFullImageName}`,
42
- );
43
-
44
- // Login to source registry
45
- await $`echo ${envInfo[fromEnv].jfrog.password} | docker login --username ${envInfo[fromEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
46
- await $`docker pull ${fromFullImageName}`;
47
- await $`docker tag ${fromFullImageName} ${toFullImageName}`;
48
-
49
- // Login to target registry
50
- await $`echo ${envInfo[toEnv].jfrog.password} | docker login --username ${envInfo[toEnv].jfrog.username} --password-stdin ${jfRegistryUrl}`;
51
- await $`docker push ${toFullImageName}`;
52
- }
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
+ }