@docupace/pipeline 1.0.1-2.ervinsUpdate2.6 → 1.0.1

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
@@ -4,174 +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 { deployFromSite } from './deploy.js';
7
+ import { deploy } from './deploy.js';
8
8
  import { deployTemplate } from './deploy.js';
9
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
10
 
18
11
  const program = new Command();
19
12
 
20
13
  // GIT SHA computation
21
14
  import { $ } from 'zx';
22
- import {deployConnect, deployCore} from './jenkins.js';
23
- import { runPipeline } from './pipline.js';
24
-
25
15
  const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
26
16
 
27
17
  program
28
- .command('pull <imageName>')
29
- .description('Pull a Docker image from the registry')
30
- .action(async (imageName) => {
31
- await pull(imageName);
32
- });
33
-
34
- program
35
- .command('sonar')
36
- .description('Run Sonar analysis')
37
- .action(async () => {
38
- await sonar(GIT_SHA);
39
- });
40
-
41
- program
42
- .command('addApacheSite')
43
- .description('Add site to apache')
44
- .action(async () => {
45
- await addApacheSite();
46
- });
47
-
48
- program
49
- .command('connectClone')
50
- .description('Clone connect site')
51
- .action(async () => {
52
- await connectClone();
53
- });
54
-
55
-
56
- program
57
- .command('haproxySync')
58
- .description('Sync haproxy config')
59
- .action(async () => {
60
- await haproxySync();
61
- });
62
-
63
-
64
-
65
- program
66
- .command('vaultAddSiteData')
67
- .description('Add m2m auth0 data to vault')
68
- .requiredOption('-s, --site-name <siteName>', 'Site name')
69
- .action(async (options) => {
70
- const { siteName, } = options;
71
- await vaultAddSiteData(siteName);
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
- .action(async (options) => {
90
- const { fromEnv, fromSite, toEnv, toSite, deployCore } = options;
91
- await deployFromSite(fromEnv, fromSite, toEnv, toSite, deployCore);
92
- });
18
+ .command('pull <imageName>')
19
+ .description('Pull a Docker image from the registry')
20
+ .action(async (imageName) => {
21
+ await pull(imageName);
22
+ });
93
23
 
94
24
  program
95
- .command('deployTemplate <site>')
96
- .description('Deploy an application for a specific site')
97
- .action(async (site) => {
98
- await deployTemplate(site);
99
- });
25
+ .command('sonar')
26
+ .description('Run Sonar analysis')
27
+ .action(async () => {
28
+ await sonar(GIT_SHA);
29
+ });
100
30
 
101
31
  program
102
- .command('deploy-core <env> <site>')
103
- .description('Deploy Core')
104
- .option('-l, --liquibase <liquibase>', 'Application name', 'true')
105
- .option('-b, --branch <branch>', 'Branch', 'master')
106
- .action(async (env, site, options) => {
107
- await deployCore(env, site, options.liquibase, options.branch);
108
- });
32
+ .command('publish')
33
+ .description('Publish a Docker image')
34
+ .action(async () => {
35
+ await publish(GIT_SHA);
36
+ });
109
37
 
110
38
  program
111
- .command('deploy-connect <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 deployConnect(env, site, options.liquibase, options.branch);
117
- });
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
+ });
118
44
 
119
45
  program
120
- .command('deploy-core-pipeline <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 runPipeline('site-deploy', 'deploy-core', 'main', {
126
- ENV: env,
127
- SITE: site,
128
- LIQUIBASE: options.liquibase,
129
- BRANCH: options.branch,
46
+ .command('deployTemplate <site>')
47
+ .description('Deploy an application for a specific site')
48
+ .action(async (site) => {
49
+ await deployTemplate(site);
130
50
  });
131
- });
132
-
133
-
134
- program
135
- .command('copy')
136
- .description('Copy a Docker image between registries')
137
- .requiredOption('-a, --application <application>', 'Application name')
138
- .requiredOption('-f, --from-env <fromEnv>', 'Source environment')
139
- .requiredOption('-t, --to-env <toEnv>', 'Target environment')
140
- .requiredOption('-g, --tag <tag>', 'Image tag')
141
- .action(async (options) => {
142
- const { application, fromEnv, toEnv, tag } = options;
143
- await copy(application, fromEnv, toEnv, tag);
144
- });
145
51
 
146
52
  program
147
- .command('run-pipeline')
148
- .description('Trigger a pipeline by name')
149
- .requiredOption('-r, --repository <repository>', 'Repository name')
150
- .requiredOption('-p, --pipeline-name <pipelineName>', 'Pipeline name')
151
- .requiredOption('-b, --branch <branch>', 'Branch name')
152
- .option(
153
- '-v, --variables <key=value>',
154
- 'Pipeline variable as key=value pair',
155
- (value, previous) => {
156
- const [key, val] = value.split('=');
157
- if (!key || val === undefined) {
158
- throw new Error(`Invalid variable format: ${value}. Use key=value.`);
159
- }
160
- return { ...previous, [key]: val };
161
- },
162
- {},
163
- )
164
- .option('-w, --wait', 'Wait for the pipeline to complete', false) // Defaults to false
165
- .action(async (cmdObj) => {
166
- try {
167
- const { repository, pipelineName, branch, variables, wait } = cmdObj;
168
-
169
- // Call the triggerPipelineByName function
170
- await runPipeline(repository, pipelineName, branch, variables, wait);
171
- } catch (error) {
172
- console.error('Error triggering pipeline:', error.message);
173
- process.exit(1);
174
- }
175
- });
53
+ .command('copy')
54
+ .description('Copy a Docker image between registries')
55
+ .action(async () => {
56
+ await copy();
57
+ });
176
58
 
177
59
  program.parse(process.argv);
package/src/next/copy.js CHANGED
@@ -1,30 +1,27 @@
1
1
  import { $ } from 'zx';
2
- import { appInfo, getEnvInfo, jfRegistryUrl } from './config.js';
2
+
3
3
 
4
4
  /*
5
5
  TARGET_ENV
6
6
  PUBLISH_TAG
7
7
  REPOSITORY_NAME
8
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}`;
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}`;
17
16
 
18
- console.log(
19
- `Copying Docker image: ${fromFullImageName} -> ${toFullImageName}`,
20
- );
17
+ console.log(`Copying Docker image: ${SOURCE_FULL_IMAGE_NAME} -> ${TARGET_FULL_IMAGE_NAME}`);
21
18
 
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}`;
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}`;
26
23
 
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}`;
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}`;
30
27
  }
@@ -2,12 +2,10 @@ import fs from 'fs';
2
2
  import path from 'path';
3
3
  import yaml from 'js-yaml';
4
4
  import { $ } from 'zx';
5
- import lodash from 'lodash';
6
- import { appInfo, environmentConfig, getRepUrl } from './config.js';
7
- import { copy } from './copy.js';
8
- import axios from 'axios';
9
- import { runPipeline } from './pipline.js';
10
- import { deployCore } from './jenkins.js';
5
+
6
+ const REPO_NAME = 'gitops-dev';
7
+ const REPO_URL = `https://x-token-auth:${process.env.GITOPS_DEV_REP_TOKEN}@bitbucket.org/dp-cloud/${REPO_NAME}.git`;
8
+ const GITOPS_BRANCH = 'master';
11
9
 
12
10
  /**
13
11
  * Clone the repository, read the YAML file, and return the parsed data and file paths.
@@ -15,87 +13,24 @@ import { deployCore } from './jenkins.js';
15
13
  * @param {string} site - The site name.
16
14
  * @returns {object} - The repository path, file path, and YAML data.
17
15
  */
16
+ export async function readDeployConfig(application, site) {
17
+ const repoPath = path.join(process.cwd(), REPO_NAME);
18
+ const deployConfigFilePath = path.join(repoPath, `dp/${site}/${application}.values.yaml`);
18
19
 
19
- function getRepoLocalPath(env) {
20
- const repoName = `gitops-${env}`;
21
- const repoPath = path.join(process.cwd(), repoName);
22
- return { repoPath, repoName };
23
- }
24
-
25
- function getRepoLocalPathByRepoSlug(repoSlug) {
26
- const repoName = `${repoSlug}`;
27
- const repoPath = path.join(process.cwd(), repoName);
28
- return { repoPath, repoName };
29
- }
30
-
31
- function cleanUpRepoPath(repoPath) {
32
- // Check and handle repo directory
33
- if (fs.existsSync(repoPath)) {
34
- console.log(`${repoPath} directory exists. Removing it...`);
35
- fs.rmSync(repoPath, {
36
- recursive: true,
37
- force: true
38
- });
39
- }
40
- }
41
-
42
- export async function cloneEnvRepository(env) {
43
- const { repoPath, repoName } = getRepoLocalPath(env);
44
- const repoUrl = getRepUrl(repoName);
45
- console.log(`Cloning repository: ${repoName}`);
46
- await $`git clone --depth 1 ${repoUrl}`;
47
- console.log(`Repository cloned to: ${repoPath}`);
48
- return repoPath;
49
- }
50
-
51
- export async function cloneRepository(repoSlug) {
52
- const { repoPath, repoName } = getRepoLocalPathByRepoSlug(repoSlug);
53
- const repoUrl = getRepUrl(repoName);
54
-
55
- await cleanUpRepoPath(repoPath)
56
-
57
- console.log(`Cloning repository: ${repoName}`);
58
- await $`git clone --depth 1 ${repoUrl}`;
59
- console.log(`Repository cloned to: ${repoPath}`);
60
- return repoPath;
61
- }
62
-
63
- function getConfigPath(application, env, site, name) {
64
- const { repoPath } = getRepoLocalPath(env);
65
- const deployConfigFilePath = path.join(
66
- repoPath,
67
- `dp/${site}/${application}.${name}.yaml`,
68
- );
69
-
70
- return { repoPath, deployConfigFilePath };
71
- }
72
-
73
- export async function readDeployConfig(application, env, site, name) {
74
- const { deployConfigFilePath } = getConfigPath(application, env, site, name);
75
-
76
- let deployConfig;
77
- try {
78
- deployConfig = yaml.load(fs.readFileSync(deployConfigFilePath, 'utf8'));
79
- console.log(`YAML file loaded from: ${deployConfigFilePath}`);
80
- } catch (error) {
81
- console.error(`Error reading YAML file: ${error.message}`);
82
- process.exit(1);
83
- }
20
+ console.log(`Cloning repository: ${REPO_NAME}`);
21
+ await $`git clone ${REPO_URL}`;
22
+ console.log(`Repository cloned to: ${repoPath}`);
84
23
 
85
- return { deployConfig, deployConfigFilePath };
86
- }
87
-
88
- export async function cloneAndReadDeployConfig(application, env, site) {
89
- const repoPath = await cloneEnvRepository(env);
90
-
91
- const { deployConfig, deployConfigFilePath } = await readDeployConfig(
92
- application,
93
- env,
94
- site,
95
- 'values',
96
- );
24
+ let deployConfig;
25
+ try {
26
+ deployConfig = yaml.load(fs.readFileSync(deployConfigFilePath, 'utf8'));
27
+ console.log(`YAML file loaded from: ${deployConfigFilePath}`);
28
+ } catch (error) {
29
+ console.error(`Error reading YAML file: ${error.message}`);
30
+ process.exit(1);
31
+ }
97
32
 
98
- return { repoPath, deployConfigFilePath, deployConfig };
33
+ return { repoPath, deployConfigFilePath, deployConfig };
99
34
  }
100
35
 
101
36
  /**
@@ -105,15 +40,15 @@ export async function cloneAndReadDeployConfig(application, env, site) {
105
40
  * @returns {object} - The updated YAML data.
106
41
  */
107
42
  export function setTag(deployConfig, tag) {
108
- if (deployConfig.image && deployConfig.image.tag) {
109
- console.log(`Current image tag: ${deployConfig.image.tag}`);
110
- deployConfig.image.tag = tag;
111
- console.log(`Updated image tag to: ${deployConfig.image.tag}`);
112
- } else {
113
- console.error('No "image.tag" field found in the YAML file.');
114
- process.exit(1);
115
- }
116
- return deployConfig;
43
+ if (deployConfig.image && deployConfig.image.tag) {
44
+ console.log(`Current image tag: ${deployConfig.image.tag}`);
45
+ deployConfig.image.tag = tag;
46
+ console.log(`Updated image tag to: ${deployConfig.image.tag}`);
47
+ } else {
48
+ console.error('No "image.tag" field found in the YAML file.');
49
+ process.exit(1);
50
+ }
51
+ return deployConfig;
117
52
  }
118
53
 
119
54
  /**
@@ -122,50 +57,25 @@ export function setTag(deployConfig, tag) {
122
57
  * @param {string} deployConfigFilePath - The path to the YAML file.
123
58
  * @param {object} deployConfig - The updated YAML data.
124
59
  */
60
+ export async function writeDeployConfig(repoPath, deployConfigFilePath, deployConfig) {
61
+ try {
62
+ fs.writeFileSync(deployConfigFilePath, yaml.dump(deployConfig), 'utf8');
63
+ console.log(`Updated YAML file saved at: ${deployConfigFilePath}`);
64
+ } catch (error) {
65
+ console.error(`Error writing YAML file: ${error.message}`);
66
+ process.exit(1);
67
+ }
125
68
 
126
- export async function pushDeployConfig(repoPath, commitMessage) {
127
- console.log('📌 Checking for updates to commit...');
128
- // Check if there are any changes to commit
129
- const status = (
130
- await $`cd ${repoPath} && git status --porcelain`
131
- ).stdout.trim();
132
- if (!status) {
133
- console.log('✅ No changes to commit. Exiting.');
134
- await $`rm -rf ${repoPath}`;
135
- console.log('🧹 Cleanup complete.');
136
- return;
137
- }
138
-
139
- console.log('📌 Committing changes to the repository...');
140
- await $`cd ${repoPath} && git config user.email "gitops@docupace.com"`;
141
- await $`cd ${repoPath} && git add .`;
142
- await $`cd ${repoPath} && git commit -m ${commitMessage}`;
143
- await $`cd ${repoPath} && git push`;
144
- console.log('✅ Changes pushed to the remote repository.');
145
-
146
- console.log('🧹 Cleaning up...');
147
- await $`rm -rf ${repoPath}`;
148
- console.log('✅ Cleanup complete.');
149
- }
150
-
151
- function writeDeployConfig(deployConfigFilePath, deployConfig) {
152
- try {
153
- fs.writeFileSync(deployConfigFilePath, yaml.dump(deployConfig), 'utf8');
154
- console.log(`✅ Updated YAML file saved at: ${deployConfigFilePath}`);
155
- } catch (error) {
156
- console.error(`❌ Error writing YAML file: ${error.message}`);
157
- process.exit(1);
158
- }
159
- }
69
+ console.log('Committing changes to the repository...');
70
+ await $`cd ${repoPath} && git config user.email "gitops@docupace.com"`;
71
+ await $`cd ${repoPath} && git add ${deployConfigFilePath}`;
72
+ await $`cd ${repoPath} && git commit -m "Update image tag to ${deployConfig.image.tag}"`;
73
+ await $`cd ${repoPath} && git push origin ${GITOPS_BRANCH}`;
74
+ console.log('Changes pushed to the remote repository.');
160
75
 
161
- export async function writeAndPushDeployConfig(
162
- repoPath,
163
- deployConfigFilePath,
164
- deployConfig,
165
- commitMessage,
166
- ) {
167
- writeDeployConfig(deployConfigFilePath, deployConfig);
168
- await pushDeployConfig(repoPath, commitMessage);
76
+ console.log('Cleaning up...');
77
+ await $`rm -rf ${repoPath}`;
78
+ console.log('Cleanup complete.');
169
79
  }
170
80
 
171
81
  /**
@@ -175,181 +85,34 @@ export async function writeAndPushDeployConfig(
175
85
  */
176
86
 
177
87
  async function getDeployTag() {
178
- const gitTag = (
179
- await $`git tag --points-at HEAD | grep '^v' | head -n 1`
180
- ).stdout.trim();
181
- const deployTag = gitTag || `build-${process.env.BITBUCKET_BUILD_NUMBER}`;
182
- return deployTag;
88
+ const gitTag = (await $`git tag --points-at HEAD | grep '^v' | head -n 1`).stdout.trim()
89
+ const deployTag = gitTag || `build-${process.env.BITBUCKET_BUILD_NUMBER}`;
90
+ return deployTag;
183
91
  }
184
92
 
185
93
  export async function deployTemplate(site) {
186
- const deployTag = await getDeployTag();
187
- console.log(`Deploying standard template for site: ${site}`);
188
- console.log(`Using deployment tag: ${deployTag}`);
189
- const { repoPath, deployConfigFilePath, deployConfig } =
190
- await cloneAndReadDeployConfig('graphql-server', 'dev', site);
191
-
192
- deployConfig.graphqlServer.standardConfigRemoteBranch = deployTag;
94
+ const deployTag = await getDeployTag();
95
+ console.log(`Deploying standard template for site: ${site}`);
96
+ console.log(`Using deployment tag: ${deployTag}`);
97
+ const { repoPath, deployConfigFilePath, deployConfig } = await readDeployConfig('graphql-server', site);
193
98
 
194
- await writeAndPushDeployConfig(
195
- repoPath,
196
- deployConfigFilePath,
197
- deployConfig,
198
- `Update template to ${deployConfig.graphqlServer.standardConfigRemoteBranch}`,
199
- );
200
- console.log('Deployment completed successfully.');
201
- }
202
-
203
- export async function deploy(application, site) {
204
- const deployTag = getDeployTag();
99
+ deployConfig.graphqlServer.standardConfigRemoteBranch = deployTag;
205
100
 
206
- console.log(`Deploying application: ${application} for site: ${site}`);
207
- console.log(`Using deployment tag: ${deployTag}`);
101
+ await writeDeployConfig(repoPath, deployConfigFilePath, deployConfig);
102
+ console.log('Deployment completed successfully.');
208
103
 
209
- const { repoPath, deployConfigFilePath, deployConfig } =
210
- await cloneAndReadDeployConfig(application, 'dev', site);
211
- const updatedConfigData = setTag(deployConfig, deployTag);
212
- await writeAndPushDeployConfig(
213
- repoPath,
214
- deployConfigFilePath,
215
- updatedConfigData,
216
- `Update image tag to ${deployConfig.image.tag}`,
217
- );
218
-
219
- console.log('Deployment completed successfully.');
220
104
  }
221
105
 
222
- async function getAppInfo(coreUrl) {
223
- const url = `${coreUrl}/b2b/rest/v1/appinfo`;
224
- return await axios.get(url);
225
- }
226
-
227
- function getBranchNameFromVersion(version) {
228
- const match = version.match(/(\d+\.\d+\.[^\-]+)(?:-(\d+)-g([a-f0-9]+))?/);
229
-
230
- if (!match) {
231
- throw new Error(`Invalid version format: ${version}`);
232
- }
233
-
234
- const fullVersion = match[1]; // e.g., 24.19.19, 24.20.alpha3, etc.
235
- const customBranch = match[2]; // e.g., 4, 58, or 0
236
- const commitHash = match[3]; // e.g., 668edef58e, 634cf6c904, etc.
237
-
238
- // If "alpha" is in the version or customBranch is non-zero, use the commit hash
239
- if (fullVersion.includes('alpha') || (customBranch && customBranch !== '0')) {
240
- return commitHash;
241
- }
242
-
243
- // Otherwise, use the full version
244
- return fullVersion;
245
- }
246
-
247
- async function getCoreBranchName(fromEnv, fromSite) {
248
- const envConfig = environmentConfig[fromEnv];
249
- const oldUrl = envConfig.oldUrl(fromSite);
250
- const newUrl = envConfig.newUrl(fromSite) + '/core';
251
-
252
- let appinfo;
253
- try {
254
- appinfo = await getAppInfo(oldUrl);
255
- } catch {
256
- try {
257
- appinfo = await getAppInfo(newUrl);
258
- } catch {
259
- throw new Error('Cannot get app info');
260
- }
261
- }
262
-
263
- const coreVersion = appinfo.data.core.version;
264
- const branchName = getBranchNameFromVersion(coreVersion);
265
- return branchName;
266
- }
267
106
 
268
- export async function deployFromSite(
269
- fromEnv,
270
- fromSite,
271
- toEnv,
272
- toSite,
273
- isDeployCore,
274
- ) {
275
- if (isDeployCore === 'true') {
276
- const branchName = await getCoreBranchName(fromEnv, fromSite);
277
-
278
- const coreEnv = toEnv == 'qa' ? 'preprod' : toEnv;
279
- await deployCore(coreEnv, toSite, 'true', branchName);
280
-
281
- // To be added back when splitting between on prem and in cloud
282
- /*await runPipeline('site-deploy', 'deploy-core', 'main', {
283
- ENV: toEnv,
284
- SITE: toSite,
285
- LIQUIBASE: 'true',
286
- BRANCH: branchName,
287
- });*/
288
- }
289
-
290
- // Clone repositories for source and target environments
291
- const fromRepoPath = await cloneEnvRepository(fromEnv);
292
- const toRepoPath =
293
- toEnv === fromEnv ? fromRepoPath : await cloneEnvRepository(toEnv);
294
-
295
- // Initialize a flag to track changes
296
- let changesMade = false;
297
-
298
- // Iterate over applications in appInfo
299
- for (const [application, appDetails] of Object.entries(appInfo)) {
300
- console.log(`Processing application: ${application}`);
301
-
302
- // Read the deployment configuration for the source environment and site
303
- const { deployConfig: fromDeployConfig } = await readDeployConfig(
304
- application,
305
- fromEnv,
306
- fromSite,
307
- 'values',
308
- );
309
-
310
- if (fromEnv !== toEnv) {
311
- await copy(application, fromEnv, toEnv, fromDeployConfig.image.tag);
312
- }
313
-
314
- // Read the deployment configuration for the target environment and site
315
- const {
316
- deployConfig: toDeployConfig,
317
- deployConfigFilePath: toDeployConfigFilePath,
318
- } = await readDeployConfig(application, toEnv, toSite, 'values');
319
-
320
- // Update target configuration using attributes specified in appInfo
321
- for (const attribute of appDetails.deployAttributes) {
322
- const sourceValue = lodash.get(fromDeployConfig, attribute);
323
-
324
- if (sourceValue !== undefined) {
325
- // Update the target configuration with the source value
326
- lodash.set(toDeployConfig, attribute, sourceValue);
327
- changesMade = true;
328
- }
329
- }
330
-
331
- const {
332
- deployConfig: toDeployAppConfig,
333
- deployConfigFilePath: toDeployAppConfigFilePath,
334
- } = await readDeployConfig(application, toEnv, toSite, 'app');
335
-
336
- toDeployAppConfig.revision = fromDeployConfig.image.tag;
337
-
338
- // Write updated configuration to the target YAML file
339
- writeDeployConfig(toDeployConfigFilePath, toDeployConfig);
107
+ export async function deploy(application, site) {
108
+ const deployTag = getDeployTag();
340
109
 
341
- writeDeployConfig(toDeployAppConfigFilePath, toDeployAppConfig);
110
+ console.log(`Deploying application: ${application} for site: ${site}`);
111
+ console.log(`Using deployment tag: ${deployTag}`);
342
112
 
343
- }
113
+ const { repoPath, deployConfigFilePath, deployConfig } = await readDeployConfig(application, site);
114
+ const updatedConfigData = setTag(deployConfig, deployTag);
115
+ await writeDeployConfig(repoPath, deployConfigFilePath, updatedConfigData);
344
116
 
345
- // Push all changes if any updates were made
346
- if (changesMade) {
347
- await pushDeployConfig(
348
- toRepoPath,
349
- `Updated deployment configurations from ${fromEnv}/${fromSite} to ${toEnv}/${toSite}`,
350
- );
351
- console.log('✅ All configurations updated and pushed successfully.');
352
- } else {
353
- console.log('✅ No changes detected. Nothing to push.');
354
- }
117
+ console.log('Deployment completed successfully.');
355
118
  }