@docupace/pipeline 1.0.39-matttest.2 → 1.0.39-matttest.21

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 CHANGED
@@ -53,8 +53,14 @@ copy() {
53
53
  }
54
54
 
55
55
  publish() {
56
- BUILD_IMAGE_NAME="${BITBUCKET_REPO_SLUG}:build-${BITBUCKET_BUILD_NUMBER}"
57
- IMAGE_NAME="${BITBUCKET_REPO_SLUG}:sha-${GIT_SHA}"
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docupace/pipeline",
3
- "version": "1.0.39-matttest.2",
3
+ "version": "1.0.39-matttest.21",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,48 +1,64 @@
1
1
  import { $ } from 'zx';
2
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}`;
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;
8
12
 
9
- console.log(`Publishing Docker image: ${IMAGE_NAME}`);
13
+ const JF_REGISTRY_FULL_URL = `${JF_REGISTRY_URL}/${JF_REGISTRY_REPO_NAME}`;
10
14
 
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}`;
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
+
26
+ console.log(JSON.stringify(process.env));
27
+
28
+ const IMAGE_PREFIX = APP_NAME ?? BITBUCKET_REPO_SLUG;
29
+ const BUILD_IMAGE_NAME = `${IMAGE_PREFIX}:build-${BITBUCKET_BUILD_NUMBER}`;
30
+ const IMAGE_NAME = `${IMAGE_PREFIX}:sha-${gitSha}`;
13
31
 
14
- // Check if the image already exists
15
- try {
16
- await $`docker manifest inspect ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
32
+ console.log(`Publishing Docker image ${IMAGE_NAME}...`);
33
+
34
+ await loginRegistry();
35
+
36
+ const manifestCheck =
37
+ await $`docker manifest inspect ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`
38
+ .quiet()
39
+ .catch(() => null);
40
+
41
+ if (manifestCheck?.exitCode === 0) {
17
42
  console.log(
18
- `Tag sha-${GIT_SHA} already exists in the remote repository. Skipping push.`,
43
+ `Tag sha-${gitSha} already exists in the remote repository. Skipping push.`,
19
44
  );
20
- } catch {
45
+ } else {
21
46
  await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
22
47
  await $`docker push ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
23
48
  }
24
49
 
25
- // Tag and push build image
26
50
  await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
27
51
  await $`docker push ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
28
52
 
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.');
53
+ const GIT_TAGS = (await $`git tag --points-at HEAD`).stdout
54
+ .trim()
55
+ .split('\n')
56
+ .filter(Boolean);
57
+ for (const GIT_TAG of GIT_TAGS) {
58
+ const tagName = `${BITBUCKET_REPO_SLUG}:${GIT_TAG}`;
59
+ await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${tagName}`;
60
+ await $`docker push ${JF_REGISTRY_FULL_URL}/${tagName}`;
44
61
  }
45
62
 
46
- // Docker logout
47
- await $`docker logout ${process.env.JF_REGISTRY_URL}`;
63
+ await logoutRegistry();
48
64
  }
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
- // If we didn't get any package names, return empty array
26
- if (!packageNames.stdout.trim()) {
27
- return [];
28
- }
27
+ const dryRunJson = turboDryOutput.stdout.trim();
29
28
 
30
- // For each package name, get its path
31
- const packages = [];
32
- const packageNamesList = packageNames.stdout.trim().split('\n');
29
+ const dryRun = JSON.parse(dryRunJson);
33
30
 
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
- }
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.name.endsWith('-app'),
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.path);
69
+ await dockerBuild(appPackage);
74
70
  }
75
71
  }
76
72
 
77
- export async function dockerBuild(path) {
73
+ export async function dockerBuild(appPackage) {
78
74
  process.env.DOCKER_HOST = '';
79
- const imageName = `${process.env.BITBUCKET_REPO_SLUG}:sha-${process.env.GIT_SHA}-withMaps`;
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} --file Dockerfile --target builder --tag ${imageName}`;
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() {