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