@docupace/pipeline 1.0.2-3.test7 → 1.0.2-3.test8

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,199 +1,187 @@
1
1
  import 'zx/globals'; // npm i zx
2
2
  import fs from 'fs-extra';
3
3
  import path from 'path';
4
- import axios from 'axios';
5
4
  import { $ } from 'zx';
6
5
 
7
-
8
-
9
- import {
10
- cloneEnvRepository,
11
- cloneRepository
12
- } from './deploy.js';
13
-
14
-
15
6
  import { getVaultSecrets } from '../auth0/vault.js';
16
7
 
17
- import {
18
- getVaultSecretsConfigs,
19
- environmentConfig
20
- } from './config.js';
21
-
22
- process.env.COMMON_VAULT_PATH = process.env.COMMON_VAULT_PATH || 'secret/data/common/config';
8
+ process.env.COMMON_VAULT_PATH =
9
+ process.env.COMMON_VAULT_PATH || 'secret/data/common/config';
23
10
  process.env.VAULT_SKIP_VERIFY = process.env.VAULT_SKIP_VERIFY || 'true';
24
11
  process.env.CONNECT_DIR = process.env.CONNECT_DIR || 'connect';
25
12
  const vaultToken = process.env.VAULT_TOKEN;
26
13
  const vaultAddr = process.env.VAULT_ADDR;
27
14
 
28
- const connectUIEnvMap= {
29
- 'dev': 'dev',
30
- 'qa': 'preprod',
31
- 'stg': 'stg',
32
- 'uat': 'uat',
33
- 'prd': 'prod-las'
15
+ const connectUIEnvMap = {
16
+ dev: 'dev',
17
+ qa: 'preprod',
18
+ stg: 'stg',
19
+ uat: 'uat',
20
+ prd: 'prod-las',
34
21
  };
35
22
 
36
23
  function log(msg) {
37
- console.log(`[*] ${msg}`);
38
- }
39
-
40
- /* --------------------------------
41
- * 1. GIT CHECKOUT
42
- * -------------------------------- */
43
- async function gitCheckout(repository, destDir, branch = 'master') {
44
- if (!(await fs.pathExists(destDir))) {
45
- log(`Directory ${destDir} does not exist. Cloning repository...`);
46
- } else {
47
- log(`Directory ${destDir} exists. Removing it...`);
48
- await fs.remove(destDir);
49
- log(`Cloning ${destDir} repository...`);
50
- }
51
-
52
- const username = process.env.BITBUCKET_USERNAME;
53
- const password = process.env.BITBUCKET_APP_PASSWORD;
54
-
55
- // Construct clone command
56
- const cloneUrl = `https://${username}:${password}@bitbucket.org/dp-cloud/${repository}.git`;
57
-
58
- log(`Perform cloning`);
59
- await $`git clone --branch=${branch} --depth 1 ${cloneUrl} ${destDir}`;
24
+ console.log(`[*] ${msg}`);
25
+ }
26
+
27
+ /* --------------------------------
28
+ * 1. GIT CHECKOUT
29
+ * -------------------------------- */
30
+ async function gitCheckout(repository, destDir, branch = 'master') {
31
+ if (!(await fs.pathExists(destDir))) {
32
+ log(`Directory ${destDir} does not exist. Cloning repository...`);
33
+ } else {
34
+ log(`Directory ${destDir} exists. Removing it...`);
35
+ await fs.remove(destDir);
36
+ log(`Cloning ${destDir} repository...`);
60
37
  }
61
-
62
-
63
38
 
39
+ const username = process.env.BITBUCKET_USERNAME;
40
+ const password = process.env.BITBUCKET_APP_PASSWORD;
64
41
 
65
-
42
+ // Construct clone command
43
+ const cloneUrl = `https://${username}:${password}@bitbucket.org/dp-cloud/${repository}.git`;
44
+
45
+ log(`Perform cloning`);
46
+ await $`git clone --branch=${branch} --depth 1 ${cloneUrl} ${destDir}`;
47
+ }
66
48
 
67
49
  export async function connectClone() {
68
- const connectFromEnv = connectUIEnvMap[process.env.BUILD_ENVIRONMENT];
69
- const connectToEnv = connectUIEnvMap[process.env.BUILD_ENVIRONMENT];
70
- if (!vaultToken || !vaultAddr) {
71
- console.error("Error: VAULT_TOKEN and VAULT_ADDR must be set.");
72
- throw new Error("VAULT_TOKEN and VAULT_ADDR must be set.");
73
- }
50
+ const connectFromEnv = connectUIEnvMap[process.env.BUILD_ENVIRONMENT];
51
+ const connectToEnv = connectUIEnvMap[process.env.BUILD_ENVIRONMENT];
52
+ if (!vaultToken || !vaultAddr) {
53
+ console.error('Error: VAULT_TOKEN and VAULT_ADDR must be set.');
54
+ throw new Error('VAULT_TOKEN and VAULT_ADDR must be set.');
55
+ }
74
56
 
75
- const site = process.env.BUILD_SITE;
76
- if (!site) {
77
- log('Error: BUILD_SITE is not set');
78
- process.exit(1);
79
- }
80
- const siteCommonVaultPath = `secret/data/${site}/common/config`;
81
-
82
-
83
- // 2) getVaultSecrets
84
- const secretsJson = await getVaultSecrets(siteCommonVaultPath);
85
- if (!secretsJson.AUTH0_CLIENT_ID) {
86
- log('Failed to retrieve secret data.');
87
- process.exit(1);
88
- }
89
- const siteCommonSecrets = secretsJson;
90
-
91
- // 3) Export secrets as environment variables
92
- process.env.AUTH0_CLIENT_ID = siteCommonSecrets.AUTH0_CLIENT_ID;
93
- process.env.AUTH0_CLIENT_SECRET = siteCommonSecrets.AUTH0_CLIENT_SECRET;
94
-
95
-
96
- process.env.AUTH0_REGION_DOMAIN="us.auth0.com";
97
-
98
- log(`BUILD_ENVIRONMENT: ${connectToEnv}`);
99
- log(`BUILD_SITE: ${process.env.BUILD_SITE}`);
100
- log(`AUTH0_SUBDOMAIN: ${process.env.AUTH0_SUBDOMAIN}`);
101
- log(`AUTH0_REGION_DOMAIN: ${process.env.AUTH0_REGION_DOMAIN}`);
102
- log(`AUTH0_CLIENT_ID: ${process.env.AUTH0_CLIENT_ID}`);
103
-
104
- process.env.AUTH0_DOMAIN = `docupace-${process.env.BUILD_ENVIRONMENT}-${process.env.BUILD_SITE}.${process.env.AUTH0_REGION_DOMAIN}`;
105
-
106
-
107
- const projectRoot = process.cwd();
108
- // 4) Clone 'connect-deploy' into CONNECT_DIR
109
-
110
-
111
- await gitCheckout('connect-deploy', process.env.CONNECT_DIR);
112
-
113
- await gitCheckout(`${connectToEnv}-site-settings`, `${process.env.CONNECT_DIR}/${connectToEnv}-site-settings`);
114
-
115
- // 5) Create site clone (emulating the dock.sh call)
116
- const cloneFrom = path.join(projectRoot,process.env.CONNECT_DIR,`envs`,`${connectFromEnv}/${process.env.FROM_BUILD_SITE}`);
117
- const cloneTo = path.join(projectRoot,process.env.CONNECT_DIR,`envs`,`${connectToEnv}/${process.env.BUILD_SITE}`);
118
-
119
- const connectHome = path.join(projectRoot,process.env.CONNECT_DIR);
120
- if (!(await fs.pathExists(cloneFrom))) {
121
- log('Clone template directory not found:');
122
- process.exit(1);
123
- }
124
-
125
-
126
- if (!(await fs.pathExists(cloneTo))) {
127
- log('New site does not exist. Performing cloning...');
128
-
129
- process.env.IMAGE_VERSION=await $`cd ${cloneFrom} && grep -E '^IMAGE_VERSION=' dock.sh | cut -f2 -d=`
130
- log(`Image version: ${process.env.IMAGE_VERSION}` );
131
- //await $`cd ${cloneFrom} && bash dock.sh clone ${process.env.BUILD_ENVIRONMENT} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
132
- await (async () => {
133
- try {
134
- // Execute the shell command
135
- const result = await $`cd ${cloneFrom} && bash dock.sh clone ${connectToEnv} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
136
- console.log('Command succeeded:');
137
- console.log('stdout:', result.stdout); // Standard output
138
- console.log('stderr:', result.stderr); // Standard error
139
- } catch (error) {
140
- console.error('Command failed:');
141
- console.error('Exit Code:', error._code); // Exit code of the command
142
- console.error('Signal:', error._signal); // Signal that caused termination (if any)
143
- console.error('stdout:', error._stdout); // Standard output
144
- console.error('stderr:', error._stderr); // Standard error
145
- }
146
- })();
147
-
148
-
149
- } else {
150
- log('Site already exists. Continuing Auth0 setup...');
151
- }
152
-
153
-
57
+ const site = process.env.BUILD_SITE;
58
+ if (!site) {
59
+ log('Error: BUILD_SITE is not set');
60
+ process.exit(1);
61
+ }
62
+ const siteCommonVaultPath = `secret/data/${site}/common/config`;
63
+
64
+ // 2) getVaultSecrets
65
+ const secretsJson = await getVaultSecrets(siteCommonVaultPath);
66
+ if (!secretsJson.AUTH0_CLIENT_ID) {
67
+ log('Failed to retrieve secret data.');
68
+ process.exit(1);
69
+ }
70
+ const siteCommonSecrets = secretsJson;
71
+
72
+ // 3) Export secrets as environment variables
73
+ process.env.AUTH0_CLIENT_ID = siteCommonSecrets.AUTH0_CLIENT_ID;
74
+ process.env.AUTH0_CLIENT_SECRET = siteCommonSecrets.AUTH0_CLIENT_SECRET;
75
+
76
+ process.env.AUTH0_REGION_DOMAIN = 'us.auth0.com';
77
+
78
+ log(`BUILD_ENVIRONMENT: ${connectToEnv}`);
79
+ log(`BUILD_SITE: ${process.env.BUILD_SITE}`);
80
+ log(`AUTH0_SUBDOMAIN: ${process.env.AUTH0_SUBDOMAIN}`);
81
+ log(`AUTH0_REGION_DOMAIN: ${process.env.AUTH0_REGION_DOMAIN}`);
82
+ log(`AUTH0_CLIENT_ID: ${process.env.AUTH0_CLIENT_ID}`);
83
+
84
+ process.env.AUTH0_DOMAIN = `docupace-${process.env.BUILD_ENVIRONMENT}-${process.env.BUILD_SITE}.${process.env.AUTH0_REGION_DOMAIN}`;
85
+
86
+ const projectRoot = process.cwd();
87
+ // 4) Clone 'connect-deploy' into CONNECT_DIR
88
+
89
+ await gitCheckout('connect-deploy', process.env.CONNECT_DIR);
90
+
91
+ await gitCheckout(
92
+ `${connectToEnv}-site-settings`,
93
+ `${process.env.CONNECT_DIR}/${connectToEnv}-site-settings`,
94
+ );
95
+
96
+ // 5) Create site clone (emulating the dock.sh call)
97
+ const cloneFrom = path.join(
98
+ projectRoot,
99
+ process.env.CONNECT_DIR,
100
+ `envs`,
101
+ `${connectFromEnv}/${process.env.FROM_BUILD_SITE}`,
102
+ );
103
+ const cloneTo = path.join(
104
+ projectRoot,
105
+ process.env.CONNECT_DIR,
106
+ `envs`,
107
+ `${connectToEnv}/${process.env.BUILD_SITE}`,
108
+ );
109
+
110
+ if (!(await fs.pathExists(cloneFrom))) {
111
+ log('Clone template directory not found:');
112
+ process.exit(1);
113
+ }
114
+
115
+ if (!(await fs.pathExists(cloneTo))) {
116
+ log('New site does not exist. Performing cloning...');
117
+
118
+ process.env.IMAGE_VERSION =
119
+ await $`cd ${cloneFrom} && grep -E '^IMAGE_VERSION=' dock.sh | cut -f2 -d=`;
120
+ log(`Image version: ${process.env.IMAGE_VERSION}`);
121
+ //await $`cd ${cloneFrom} && bash dock.sh clone ${process.env.BUILD_ENVIRONMENT} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
154
122
  await (async () => {
155
123
  try {
156
- // Execute the shell command
157
- const result = await $`cd ${cloneTo} && bash dock.sh getAuth0Metadata`;
158
- console.log('Command succeeded:');
159
- console.log('stdout:', result.stdout); // Standard output
160
- console.log('stderr:', result.stderr); // Standard error
124
+ // Execute the shell command
125
+ const result =
126
+ await $`cd ${cloneFrom} && bash dock.sh clone ${connectToEnv} ${process.env.BUILD_SITE} ${process.env.IMAGE_VERSION}`;
127
+ console.log('Command succeeded:');
128
+ console.log('stdout:', result.stdout); // Standard output
129
+ console.log('stderr:', result.stderr); // Standard error
161
130
  } catch (error) {
162
- console.error('Command failed:');
163
- console.error('Exit Code:', error._code); // Exit code of the command
164
- console.error('Signal:', error._signal); // Signal that caused termination (if any)
165
- console.error('stdout:', error._stdout); // Standard output
166
- console.error('stderr:', error._stderr); // Standard error
131
+ console.error('Command failed:');
132
+ console.error('Exit Code:', error._code); // Exit code of the command
133
+ console.error('Signal:', error._signal); // Signal that caused termination (if any)
134
+ console.error('stdout:', error._stdout); // Standard output
135
+ console.error('stderr:', error._stderr); // Standard error
167
136
  }
168
- })();
169
-
137
+ })();
138
+ } else {
139
+ log('Site already exists. Continuing Auth0 setup...');
140
+ }
170
141
 
171
- // 7) Check conf files, print logs
172
- await $`grep "auth0" ${path.join(cloneTo, 'conf/application.conf')}`;
173
- await $`ls -all ${path.join(cloneTo, 'conf')}`;
174
- await $`ls -all ${path.join(cloneTo, 'conf/saml')}`;
175
- await $`cat ${path.join(cloneTo, 'conf/saml/auth0.xml')}`;
176
-
177
- // 8) Git add, commit, push
178
- await $`cd ${cloneTo} && git checkout master && git pull --ff-only`;
179
- await $`cd ${cloneTo} && git remote -v`;
180
- await $`cd ${cloneTo} && git branch`;
181
- await $`cd ${cloneTo} && git status`;
182
- await $`cd ${cloneTo} && git add . ../sites.sh`;
183
- await $`cd ${cloneTo} && git status`;
184
-
185
- const numChanges = (
186
- await $`cd ${cloneTo} && git diff-index HEAD`
187
- ).stdout.split('\n').filter(Boolean).length;
188
-
189
- if (numChanges > 0) {
190
- const jiraTicket = process.env.JIRA_TICKET || 'NO_JIRA';
191
- const message = `${jiraTicket} usdoc-s-builui job download_auth0_metadata for ${connectToEnv}/${process.env.BUILD_SITE}`;
192
- log('About to commit changes to git');
193
- await $`cd ${cloneTo} && git commit -m ${message}`;
194
- await $`cd ${cloneTo} && git push -u origin master`;
195
- } else {
196
- log('No changes have been made. The site likely already has the correct configuration.');
142
+ await (async () => {
143
+ try {
144
+ // Execute the shell command
145
+ const result = await $`cd ${cloneTo} && bash dock.sh getAuth0Metadata`;
146
+ console.log('Command succeeded:');
147
+ console.log('stdout:', result.stdout); // Standard output
148
+ console.log('stderr:', result.stderr); // Standard error
149
+ } catch (error) {
150
+ console.error('Command failed:');
151
+ console.error('Exit Code:', error._code); // Exit code of the command
152
+ console.error('Signal:', error._signal); // Signal that caused termination (if any)
153
+ console.error('stdout:', error._stdout); // Standard output
154
+ console.error('stderr:', error._stderr); // Standard error
197
155
  }
156
+ })();
157
+
158
+ // 7) Check conf files, print logs
159
+ await $`grep "auth0" ${path.join(cloneTo, 'conf/application.conf')}`;
160
+ await $`ls -all ${path.join(cloneTo, 'conf')}`;
161
+ await $`ls -all ${path.join(cloneTo, 'conf/saml')}`;
162
+ await $`cat ${path.join(cloneTo, 'conf/saml/auth0.xml')}`;
163
+
164
+ // 8) Git add, commit, push
165
+ await $`cd ${cloneTo} && git checkout master && git pull --ff-only`;
166
+ await $`cd ${cloneTo} && git remote -v`;
167
+ await $`cd ${cloneTo} && git branch`;
168
+ await $`cd ${cloneTo} && git status`;
169
+ await $`cd ${cloneTo} && git add . ../sites.sh`;
170
+ await $`cd ${cloneTo} && git status`;
171
+
172
+ const numChanges = (await $`cd ${cloneTo} && git diff-index HEAD`).stdout
173
+ .split('\n')
174
+ .filter(Boolean).length;
175
+
176
+ if (numChanges > 0) {
177
+ const jiraTicket = process.env.JIRA_TICKET || 'NO_JIRA';
178
+ const message = `${jiraTicket} usdoc-s-builui job download_auth0_metadata for ${connectToEnv}/${process.env.BUILD_SITE}`;
179
+ log('About to commit changes to git');
180
+ await $`cd ${cloneTo} && git commit -m ${message}`;
181
+ await $`cd ${cloneTo} && git push -u origin master`;
182
+ } else {
183
+ log(
184
+ 'No changes have been made. The site likely already has the correct configuration.',
185
+ );
198
186
  }
199
-
187
+ }
@@ -6,7 +6,7 @@ import lodash from 'lodash';
6
6
  import { appInfo, environmentConfig, getRepUrl } from './config.js';
7
7
  import { copy2 } from './copy.js';
8
8
  import axios from 'axios';
9
- import { deployCore } from './jenkins.js';
9
+ import { deployCore, deployConnect } from './jenkins.js';
10
10
 
11
11
  /**
12
12
  * Clone the repository, read the YAML file, and return the parsed data and file paths.
@@ -21,6 +21,62 @@ function getRepoLocalPath(env) {
21
21
  return { repoPath, repoName };
22
22
  }
23
23
 
24
+ async function updateAndCommitConnectVersion(
25
+ toEnv,
26
+ toSite,
27
+ getComparedVersion,
28
+ connectDeployPath,
29
+ ) {
30
+ const filePath = path.join(
31
+ connectDeployPath,
32
+ 'envs',
33
+ toEnv,
34
+ toSite,
35
+ 'dock.sh',
36
+ );
37
+
38
+ try {
39
+ let content = fs.readFileSync(filePath, 'utf8');
40
+ content = content.replace(
41
+ /IMAGE_VERSION=.*/,
42
+ `IMAGE_VERSION=${getComparedVersion}`,
43
+ );
44
+ fs.writeFileSync(filePath, content, 'utf8');
45
+
46
+ // Git commands to stage, commit and push changes
47
+ await $`cd ${connectDeployPath}`;
48
+ await $`git add ${filePath}`;
49
+ await $`git commit -m "Update Connect version for ${toSite} in ${toEnv} to ${getComparedVersion}"`;
50
+ await $`git push`;
51
+ } catch (error) {
52
+ console.error('Error updating Connect version:', error);
53
+ throw error;
54
+ }
55
+ }
56
+
57
+ async function compareGetConnectSiteVersions(fromEnv, fromSite, toEnv, toSite) {
58
+ try {
59
+ const fromResponse = await axios.get(
60
+ `https://${fromSite}.${fromEnv}.dpai.tech/connect/loginFooter`,
61
+ );
62
+ const toResponse = await axios.get(
63
+ `https://${toSite}.${toEnv}.dpai.tech/connect/loginFooter`,
64
+ );
65
+
66
+ const fromMatch = fromResponse.data.match(/UI Build: ([a-f0-9]*)/);
67
+ const toMatch = toResponse.data.match(/UI Build: ([a-f0-9]*)/);
68
+
69
+ if (fromMatch && fromMatch[1] && toMatch && toMatch[1]) {
70
+ if (fromMatch[1] !== toMatch[1]) {
71
+ return fromMatch[1];
72
+ }
73
+ }
74
+ return false;
75
+ } catch (error) {
76
+ console.error('Error fetching Connect versions:', error);
77
+ throw error;
78
+ }
79
+ }
24
80
  function getRepoLocalPathByRepoSlug(repoSlug) {
25
81
  const repoName = `${repoSlug}`;
26
82
  const repoPath = path.join(process.cwd(), repoName);
@@ -347,6 +403,8 @@ export async function deployFromSite(
347
403
  toEnv,
348
404
  toSite,
349
405
  isDeployCore,
406
+ isDeployConnect,
407
+ runLiquibase,
350
408
  ) {
351
409
  if (isDeployCore === 'true') {
352
410
  const branchName = await getCoreBranchName(fromEnv, fromSite);
@@ -363,6 +421,28 @@ export async function deployFromSite(
363
421
  });*/
364
422
  }
365
423
 
424
+ if (isDeployConnect === 'true') {
425
+ const branch = '';
426
+ const getComparedVersion = await compareGetConnectSiteVersions(
427
+ fromEnv,
428
+ fromSite,
429
+ toEnv,
430
+ toSite,
431
+ );
432
+ if (getComparedVersion) {
433
+ const connectDeployPath = await cloneRepository('connect-deploy');
434
+ // update target version set to git-commit-${getCommparedVersion}}
435
+ await updateAndCommitConnectVersion(
436
+ toEnv,
437
+ toSite,
438
+ getComparedVersion,
439
+ connectDeployPath,
440
+ );
441
+ // save and deploy
442
+ await deployConnect(toEnv, toSite, runLiquibase, branch);
443
+ }
444
+ }
445
+
366
446
  // Clone repositories for source and target environments
367
447
  const fromRepoPath = await cloneEnvRepository(fromEnv);
368
448
  const toRepoPath =
@@ -99,7 +99,6 @@ export async function runPipeline(
99
99
  return;
100
100
  }
101
101
 
102
-
103
102
  let status = '';
104
103
  do {
105
104
  console.log('Checking pipeline status...');
@@ -1,48 +1,48 @@
1
- import { $ } from 'zx';
2
-
3
- export async function publish(GIT_SHA) {
4
- const BITBUCKET_REPO_SLUG = process.env.BITBUCKET_REPO_SLUG;
5
- const BUILD_IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:build-${process.env.BITBUCKET_BUILD_NUMBER}`;
6
- const IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}`;
7
- const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
8
-
9
- console.log(`Publishing Docker image: ${IMAGE_NAME}`);
10
-
11
- // Docker login
12
- await $`echo ${process.env.JF_REGISTRY_PASSWORD_DEV} | docker login --username ${process.env.JF_REGISTRY_USER_DEV} --password-stdin ${process.env.JF_REGISTRY_URL}`;
13
-
14
- // Check if the image already exists
15
- try {
16
- await $`docker manifest inspect ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
17
- console.log(
18
- `Tag sha-${GIT_SHA} already exists in the remote repository. Skipping push.`,
19
- );
20
- } catch {
21
- await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
22
- await $`docker push ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
23
- }
24
-
25
- // Tag and push build image
26
- await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
27
- await $`docker push ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
28
-
29
- // Fetch Git tags pointing to the current HEAD
30
- const gitTagsOutput = (await $`git tag --points-at HEAD`).stdout.trim();
31
- const gitTags = gitTagsOutput.split('\n').filter((tag) => tag);
32
-
33
- // Tag and push each Git tag as a Docker tag
34
- if (gitTags.length > 0) {
35
- console.log(`Found Git tags pointing to HEAD: ${gitTags.join(', ')}`);
36
- for (const gitTag of gitTags) {
37
- const dockerTag = `${JF_REGISTRY_FULL_URL}/${BITBUCKET_REPO_SLUG}:${gitTag}`;
38
- console.log(`Tagging and pushing Docker image for Git tag: ${gitTag}`);
39
- await $`docker tag ${IMAGE_NAME} ${dockerTag}`;
40
- await $`docker push ${dockerTag}`;
41
- }
42
- } else {
43
- console.log('No Git tags found pointing to the current HEAD.');
44
- }
45
-
46
- // Docker logout
47
- await $`docker logout ${process.env.JF_REGISTRY_URL}`;
48
- }
1
+ import { $ } from 'zx';
2
+
3
+ export async function publish(GIT_SHA) {
4
+ const BITBUCKET_REPO_SLUG = process.env.BITBUCKET_REPO_SLUG;
5
+ const BUILD_IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:build-${process.env.BITBUCKET_BUILD_NUMBER}`;
6
+ const IMAGE_NAME = `${BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}`;
7
+ const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
8
+
9
+ console.log(`Publishing Docker image: ${IMAGE_NAME}`);
10
+
11
+ // Docker login
12
+ await $`echo ${process.env.JF_REGISTRY_PASSWORD_DEV} | docker login --username ${process.env.JF_REGISTRY_USER_DEV} --password-stdin ${process.env.JF_REGISTRY_URL}`;
13
+
14
+ // Check if the image already exists
15
+ try {
16
+ await $`docker manifest inspect ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
17
+ console.log(
18
+ `Tag sha-${GIT_SHA} already exists in the remote repository. Skipping push.`,
19
+ );
20
+ } catch {
21
+ await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
22
+ await $`docker push ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
23
+ }
24
+
25
+ // Tag and push build image
26
+ await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
27
+ await $`docker push ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
28
+
29
+ // Fetch Git tags pointing to the current HEAD
30
+ const gitTagsOutput = (await $`git tag --points-at HEAD`).stdout.trim();
31
+ const gitTags = gitTagsOutput.split('\n').filter((tag) => tag);
32
+
33
+ // Tag and push each Git tag as a Docker tag
34
+ if (gitTags.length > 0) {
35
+ console.log(`Found Git tags pointing to HEAD: ${gitTags.join(', ')}`);
36
+ for (const gitTag of gitTags) {
37
+ const dockerTag = `${JF_REGISTRY_FULL_URL}/${BITBUCKET_REPO_SLUG}:${gitTag}`;
38
+ console.log(`Tagging and pushing Docker image for Git tag: ${gitTag}`);
39
+ await $`docker tag ${IMAGE_NAME} ${dockerTag}`;
40
+ await $`docker push ${dockerTag}`;
41
+ }
42
+ } else {
43
+ console.log('No Git tags found pointing to the current HEAD.');
44
+ }
45
+
46
+ // Docker logout
47
+ await $`docker logout ${process.env.JF_REGISTRY_URL}`;
48
+ }
package/src/next/pull.js CHANGED
@@ -1,7 +1,7 @@
1
- import { $ } from 'zx';
2
-
3
- export async function pull(imageName) {
4
- const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
5
- console.log(`Pulling Docker image: ${JF_REGISTRY_FULL_URL}/${imageName}`);
6
- await $`docker pull ${JF_REGISTRY_FULL_URL}/${imageName}`;
7
- }
1
+ import { $ } from 'zx';
2
+
3
+ export async function pull(imageName) {
4
+ const JF_REGISTRY_FULL_URL = `${process.env.JF_REGISTRY_URL}/${process.env.JF_REGISTRY_REPO_NAME}`;
5
+ console.log(`Pulling Docker image: ${JF_REGISTRY_FULL_URL}/${imageName}`);
6
+ await $`docker pull ${JF_REGISTRY_FULL_URL}/${imageName}`;
7
+ }
package/src/next/sonar.js CHANGED
@@ -1,23 +1,23 @@
1
- import { $ } from 'zx';
2
-
3
- export async function sonar(GIT_SHA) {
4
- const IMAGE_NAME = `${process.env.BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}`;
5
- const SONAR_CONTAINER_NAME = `${process.env.BITBUCKET_REPO_SLUG}-${GIT_SHA}`;
6
-
7
- console.log(`Running Sonar analysis on Docker image: ${IMAGE_NAME}`);
8
-
9
- // Remove existing container
10
- const existingContainer = (
11
- await $`docker ps -a --filter "name=${SONAR_CONTAINER_NAME}" --format "{{.Names}}"`
12
- ).stdout.trim();
13
- if (existingContainer) {
14
- await $`docker rm -f ${SONAR_CONTAINER_NAME}`;
15
- }
16
-
17
- await $`docker run --rm \
18
- -e BRANCH=${process.env.BITBUCKET_BRANCH} \
19
- -e PR_ID=${process.env.BITBUCKET_PR_ID} \
20
- -e PR_DESTINATION_BRANCH=${process.env.BITBUCKET_PR_DESTINATION_BRANCH} \
21
- -e SONAR_TOKEN=${process.env.SONAR_TOKEN} \
22
- --name ${SONAR_CONTAINER_NAME} ${IMAGE_NAME} pnpm sonar`;
23
- }
1
+ import { $ } from 'zx';
2
+
3
+ export async function sonar(GIT_SHA) {
4
+ const IMAGE_NAME = `${process.env.BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}`;
5
+ const SONAR_CONTAINER_NAME = `${process.env.BITBUCKET_REPO_SLUG}-${GIT_SHA}`;
6
+
7
+ console.log(`Running Sonar analysis on Docker image: ${IMAGE_NAME}`);
8
+
9
+ // Remove existing container
10
+ const existingContainer = (
11
+ await $`docker ps -a --filter "name=${SONAR_CONTAINER_NAME}" --format "{{.Names}}"`
12
+ ).stdout.trim();
13
+ if (existingContainer) {
14
+ await $`docker rm -f ${SONAR_CONTAINER_NAME}`;
15
+ }
16
+
17
+ await $`docker run --rm \
18
+ -e BRANCH=${process.env.BITBUCKET_BRANCH} \
19
+ -e PR_ID=${process.env.BITBUCKET_PR_ID} \
20
+ -e PR_DESTINATION_BRANCH=${process.env.BITBUCKET_PR_DESTINATION_BRANCH} \
21
+ -e SONAR_TOKEN=${process.env.SONAR_TOKEN} \
22
+ --name ${SONAR_CONTAINER_NAME} ${IMAGE_NAME} pnpm sonar`;
23
+ }