@docupace/pipeline 1.0.39-matttest.19 → 1.0.39-matttest.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/next/execute.sh +2 -8
- package/package.json +1 -1
- package/src/next/publish.js +31 -43
- package/src/next/util.js +26 -23
package/next/execute.sh
CHANGED
|
@@ -53,14 +53,8 @@ copy() {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
publish() {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
SLUG_SUFFIX="-${APP_NAME}"
|
|
59
|
-
fi
|
|
60
|
-
|
|
61
|
-
BUILD_IMAGE_NAME="${BITBUCKET_REPO_SLUG}${SLUG_SUFFIX}:build-${BITBUCKET_BUILD_NUMBER}"
|
|
62
|
-
IMAGE_NAME="${BITBUCKET_REPO_SLUG}${SLUG_SUFFIX}:sha-${GIT_SHA}"
|
|
63
|
-
|
|
56
|
+
BUILD_IMAGE_NAME="${BITBUCKET_REPO_SLUG}:build-${BITBUCKET_BUILD_NUMBER}"
|
|
57
|
+
IMAGE_NAME="${BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}"
|
|
64
58
|
export DOCKER_HOST=""
|
|
65
59
|
|
|
66
60
|
echo "Publishing Docker image ${IMAGE_NAME}..."
|
package/package.json
CHANGED
package/src/next/publish.js
CHANGED
|
@@ -1,60 +1,48 @@
|
|
|
1
1
|
import { $ } from 'zx';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
BITBUCKET_REPO_SLUG,
|
|
9
|
-
BITBUCKET_BUILD_NUMBER,
|
|
10
|
-
APP_NAME,
|
|
11
|
-
} = process.env;
|
|
12
|
-
|
|
13
|
-
const JF_REGISTRY_FULL_URL = `${JF_REGISTRY_URL}/${JF_REGISTRY_REPO_NAME}`;
|
|
14
|
-
|
|
15
|
-
async function loginRegistry() {
|
|
16
|
-
await $`echo ${JF_REGISTRY_PASSWORD_DEV} | docker login --username ${JF_REGISTRY_USER_DEV} --password-stdin ${JF_REGISTRY_URL}`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async function logoutRegistry() {
|
|
20
|
-
await $`docker logout ${JF_REGISTRY_URL}`;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function publish(gitSha) {
|
|
24
|
-
const SLUG_SUFFIX = APP_NAME ? `-${APP_NAME}` : '';
|
|
25
|
-
const BUILD_IMAGE_NAME = `${BITBUCKET_REPO_SLUG}${SLUG_SUFFIX}:build-${BITBUCKET_BUILD_NUMBER}`;
|
|
26
|
-
const IMAGE_NAME = `${BITBUCKET_REPO_SLUG}${SLUG_SUFFIX}:sha-${gitSha}`;
|
|
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}`;
|
|
27
8
|
|
|
28
|
-
console.log(`Publishing Docker image ${IMAGE_NAME}
|
|
9
|
+
console.log(`Publishing Docker image: ${IMAGE_NAME}`);
|
|
29
10
|
|
|
30
|
-
|
|
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}`;
|
|
31
13
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.catch(() => null);
|
|
36
|
-
|
|
37
|
-
if (manifestCheck?.exitCode === 0) {
|
|
14
|
+
// Check if the image already exists
|
|
15
|
+
try {
|
|
16
|
+
await $`docker manifest inspect ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
|
|
38
17
|
console.log(
|
|
39
|
-
`Tag sha-${
|
|
18
|
+
`Tag sha-${GIT_SHA} already exists in the remote repository. Skipping push.`,
|
|
40
19
|
);
|
|
41
|
-
}
|
|
20
|
+
} catch {
|
|
42
21
|
await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
|
|
43
22
|
await $`docker push ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
|
|
44
23
|
}
|
|
45
24
|
|
|
25
|
+
// Tag and push build image
|
|
46
26
|
await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
|
|
47
27
|
await $`docker push ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
|
|
48
28
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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.');
|
|
57
44
|
}
|
|
58
45
|
|
|
59
|
-
|
|
46
|
+
// Docker logout
|
|
47
|
+
await $`docker logout ${process.env.JF_REGISTRY_URL}`;
|
|
60
48
|
}
|
package/src/next/util.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { existsSync } from 'fs';
|
|
2
2
|
import { join } from 'path';
|
|
3
3
|
import { $, nothrow } from 'zx';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
|
|
6
|
-
const GIT_SHA = (await $`git log --pretty=format:'%h' -n 1`).stdout.trim();
|
|
7
4
|
|
|
8
5
|
export function isMonoRepo() {
|
|
9
6
|
// Check for the presence of turbo.json which indicates a Turborepo monorepo
|
|
@@ -18,21 +15,34 @@ export function isMonoRepo() {
|
|
|
18
15
|
*/
|
|
19
16
|
export async function getChangedPackagesInternal(fromRef, toRef) {
|
|
20
17
|
try {
|
|
21
|
-
console.log(process.cwd());
|
|
22
18
|
// Run the turbo command to get changed packages between branches
|
|
23
19
|
const filterArg = `[${fromRef}...${toRef}]`;
|
|
24
20
|
const turboDryOutput =
|
|
25
21
|
await $`turbo run build --filter=${filterArg} --dry=json`;
|
|
22
|
+
const packageNames =
|
|
23
|
+
await $`echo ${turboDryOutput} | jq -r '.tasks[].taskId' | cut -d'#' -f1 | sort -u`;
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
// If we didn't get any package names, return empty array
|
|
26
|
+
if (!packageNames.stdout.trim()) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
// For each package name, get its path
|
|
31
|
+
const packages = [];
|
|
32
|
+
const packageNamesList = packageNames.stdout.trim().split('\n');
|
|
30
33
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
for (const packageName of packageNamesList) {
|
|
35
|
+
if (packageName) {
|
|
36
|
+
const packagePath =
|
|
37
|
+
await $`pnpm m ls -r --json | jq -r --arg name ${packageName} '.[] | select(.name == $name) | .path'`;
|
|
38
|
+
if (packagePath.stdout.trim()) {
|
|
39
|
+
packages.push({
|
|
40
|
+
name: packageName,
|
|
41
|
+
path: packagePath.stdout.trim(),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
36
46
|
|
|
37
47
|
return packages;
|
|
38
48
|
} catch (error) {
|
|
@@ -45,37 +55,30 @@ export async function getChangedPackages() {
|
|
|
45
55
|
const branch = process.env.BITBUCKET_BRANCH;
|
|
46
56
|
const destBranch = process.env.BITBUCKET_PR_DESTINATION_BRANCH;
|
|
47
57
|
|
|
48
|
-
await $`git fetch origin ${destBranch}:${destBranch}`;
|
|
49
|
-
console.log(`Getting changed packages for [${destBranch}...${branch}]`);
|
|
50
58
|
const changedPackages = await getChangedPackagesInternal(destBranch, branch);
|
|
51
|
-
console.log('Changed Packages:\n', JSON.stringify(changedPackages, null, 2));
|
|
52
59
|
return changedPackages;
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
export async function getChangedAppPackages() {
|
|
56
63
|
const changedPackages = await getChangedPackages();
|
|
57
64
|
const appPackages = changedPackages.filter((appPackage) =>
|
|
58
|
-
appPackage.
|
|
65
|
+
appPackage.name.endsWith('-app'),
|
|
59
66
|
);
|
|
60
67
|
return appPackages;
|
|
61
68
|
}
|
|
62
69
|
|
|
63
70
|
export async function buildChangePackages() {
|
|
64
71
|
const appPackages = await getChangedAppPackages();
|
|
65
|
-
if (appPackages.length == 0) {
|
|
66
|
-
throw new Error('Nothing to build');
|
|
67
|
-
}
|
|
68
72
|
for (const appPackage of appPackages) {
|
|
69
|
-
await dockerBuild(appPackage);
|
|
73
|
+
await dockerBuild(appPackage.path);
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
|
|
73
|
-
export async function dockerBuild(
|
|
77
|
+
export async function dockerBuild(path) {
|
|
74
78
|
process.env.DOCKER_HOST = '';
|
|
75
|
-
const
|
|
76
|
-
const imageName = `${process.env.BITBUCKET_REPO_SLUG}-${shortName}:sha-${GIT_SHA}-withMaps`;
|
|
79
|
+
const imageName = `${process.env.BITBUCKET_REPO_SLUG}:sha-${process.env.GIT_SHA}-withMaps`;
|
|
77
80
|
console.log(`Building Docker image ${imageName}...`);
|
|
78
|
-
await $`docker build --secret id=npm_token,env=DOCUPACE_NPM_TOKEN
|
|
81
|
+
await $`docker build --secret id=npm_token,env=DOCUPACE_NPM_TOKEN ${path} --file Dockerfile --target builder --tag ${imageName}`;
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
export async function setGitInfo() {
|