@docupace/pipeline 1.0.4-4.8 → 1.0.4

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,48 +1,46 @@
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(`Tag sha-${GIT_SHA} already exists in the remote repository. Skipping push.`);
18
+ } catch {
19
+ await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
20
+ await $`docker push ${JF_REGISTRY_FULL_URL}/${IMAGE_NAME}`;
21
+ }
22
+
23
+ // Tag and push build image
24
+ await $`docker tag ${IMAGE_NAME} ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
25
+ await $`docker push ${JF_REGISTRY_FULL_URL}/${BUILD_IMAGE_NAME}`;
26
+
27
+ // Fetch Git tags pointing to the current HEAD
28
+ const gitTagsOutput = (await $`git tag --points-at HEAD`).stdout.trim();
29
+ const gitTags = gitTagsOutput.split('\n').filter((tag) => tag);
30
+
31
+ // Tag and push each Git tag as a Docker tag
32
+ if (gitTags.length > 0) {
33
+ console.log(`Found Git tags pointing to HEAD: ${gitTags.join(', ')}`);
34
+ for (const gitTag of gitTags) {
35
+ const dockerTag = `${JF_REGISTRY_FULL_URL}/${BITBUCKET_REPO_SLUG}:${gitTag}`;
36
+ console.log(`Tagging and pushing Docker image for Git tag: ${gitTag}`);
37
+ await $`docker tag ${IMAGE_NAME} ${dockerTag}`;
38
+ await $`docker push ${dockerTag}`;
39
+ }
40
+ } else {
41
+ console.log('No Git tags found pointing to the current HEAD.');
42
+ }
43
+
44
+ // Docker logout
45
+ await $`docker logout ${process.env.JF_REGISTRY_URL}`;
46
+ }
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
+ }
package/.prettierrc.cjs DELETED
@@ -1,12 +0,0 @@
1
- module.exports = {
2
- parser: 'typescript',
3
- trailingComma: 'all',
4
- tabWidth: 2,
5
- semi: true,
6
- singleQuote: true,
7
- printWidth: 80,
8
- tabs: false,
9
- jsxSingleQuote: false,
10
- bracketSameLine: true,
11
- arrowParens: 'always',
12
- };
@@ -1,58 +0,0 @@
1
- #!/bin/bash
2
- set -e
3
-
4
- ENV=$1
5
-
6
- if [ -z "$ENV" ]; then
7
- echo "Usage: $0 <environment>"
8
- exit 1
9
- fi
10
-
11
- TENANT_ID="docupace.onmicrosoft.com"
12
- CLIENT_ID=$ARM_CLIENT_ID
13
- CLIENT_SECRET=$ARM_CLIENT_SECRET
14
- NEW_REDIRECT="https://docupace-$ENV-$SITE_NAME.us.auth0.com/login/callback"
15
- APP_ID="auth0-$ENV-docupace"
16
- APP_SCOPE="https://graph.microsoft.com/.default"
17
- GRAPH_API="https://graph.microsoft.com/v1.0"
18
-
19
- ACCESS_TOKEN=$(curl -s -X POST \
20
- -H "Content-Type: application/x-www-form-urlencoded" \
21
- -d "grant_type=client_credentials&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&scope=$APP_SCOPE" \
22
- https://login.microsoftonline.com/$TENANT_ID/oauth2/v2.0/token | jq -r '.access_token')
23
-
24
- APP_DETAILS=$(curl -s -G "https://graph.microsoft.com/v1.0/applications" \
25
- -H "Authorization: Bearer $ACCESS_TOKEN" \
26
- -H "Content-Type: application/json" \
27
- --data-urlencode "\$filter=appId eq '$CLIENT_ID'")
28
-
29
- APP_ID=$(echo "$APP_DETAILS" | jq -r '.value[0].id')
30
- echo "Application ID: $APP_ID"
31
-
32
- CURRENT_REDIRECTS=$(echo "$APP_DETAILS" | jq -r '.value[0].web.redirectUris // []')
33
- echo "Current redirect URIs: $CURRENT_REDIRECTS"
34
-
35
- if echo "$CURRENT_REDIRECTS" | jq -e --arg uri "$NEW_REDIRECT" 'index($uri)' > /dev/null; then
36
- echo "Redirect URI '$NEW_REDIRECT' already exists. No update needed."
37
- else
38
- UPDATED_REDIRECTS=$(echo "$CURRENT_REDIRECTS" | jq --arg uri "$NEW_REDIRECT" '. + [$uri]')
39
- echo "Updated redirect URIs: $UPDATED_REDIRECTS"
40
-
41
- UPDATE_REDIRECTS=$(curl -fs -X PATCH \
42
- -H "Authorization: Bearer $ACCESS_TOKEN" \
43
- -H "Content-Type: application/json" \
44
- -d "{
45
- \"web\": {
46
- \"redirectUris\": $UPDATED_REDIRECTS
47
- }
48
- }" \
49
- "https://graph.microsoft.com/v1.0/applications/$APP_ID")
50
-
51
- if [ $? -eq 0 ]; then
52
- echo "Successfully updated redirect URIs"
53
- echo $UPDATE_REDIRECTS
54
- else
55
- echo "Failed to update redirect URIs"
56
- echo $UPDATE_REDIRECTS
57
- fi
58
- fi
package/eslint.config.js DELETED
@@ -1,26 +0,0 @@
1
- import globals from 'globals';
2
- import pluginJs from '@eslint/js';
3
- import prettierConfig from 'eslint-config-prettier';
4
- import prettierPlugin from 'eslint-plugin-prettier';
5
-
6
- /** @type {import('eslint').Linter.Config[]} */
7
- export default [
8
- {
9
- languageOptions: {
10
- globals: {
11
- ...globals.browser,
12
- ...globals.node, // Add Node.js globals
13
- },
14
- },
15
- },
16
- pluginJs.configs.recommended,
17
- {
18
- plugins: {
19
- prettier: prettierPlugin,
20
- },
21
- rules: {
22
- ...prettierConfig.rules,
23
- 'prettier/prettier': 'error',
24
- },
25
- },
26
- ];
@@ -1,72 +0,0 @@
1
- import axios from 'axios';
2
-
3
- import { createAlias } from '../next/alias.js';
4
-
5
- import { getAuth0AuthToken } from './configure.js';
6
-
7
- import { getVaultSecrets } from './vault.js';
8
-
9
- import { getVaultSecretsConfigs } from '../next/config.js';
10
-
11
- import { cloneEnvRepository, readDeployConfig } from '../next/deploy.js';
12
-
13
- export async function getCCAlias({ application, auth0Domain, auth0AuthToken }) {
14
- console.log(`Forming alias name for application ${application}...`);
15
-
16
- try {
17
- const auth0Response = await axios.get(
18
- `https://${auth0Domain}/api/v2/clients`,
19
- {
20
- headers: { authorization: `Bearer ${auth0AuthToken}` },
21
- },
22
- );
23
-
24
- const appAuth0ClientIdData = auth0Response.data.find(
25
- (client) => client.name === `${application}`,
26
- );
27
- const appAuth0ClientId = appAuth0ClientIdData.client_id;
28
-
29
- console.log(`Client Credentials Alias: ${appAuth0ClientId}@clients`);
30
- return `${appAuth0ClientId}@clients`;
31
- } catch (err) {
32
- console.error(
33
- `Failed to form alias name for application: ${application}: ${err.message}`,
34
- );
35
- }
36
- }
37
-
38
- export async function configureAlias(site, env, username, password, realm) {
39
- console.log(`Creating alias for site: ${site} in env: ${env}`);
40
- // Site Common Secrets
41
- const siteCommonSecretsPath =
42
- getVaultSecretsConfigs(site).siteCommonSecretsPath;
43
- console.log(`siteCommonSecretsPath => ${siteCommonSecretsPath}`);
44
- const siteCommonSecrets = await getVaultSecrets(siteCommonSecretsPath);
45
-
46
- const auth0Domain = `docupace-${env}-${site}.us.auth0.com`;
47
- const auth0ClientId = siteCommonSecrets.AUTH0_CLIENT_ID;
48
- const auth0ClientSecret = siteCommonSecrets.AUTH0_CLIENT_SECRET;
49
- const auth0Token = await getAuth0AuthToken(
50
- auth0Domain,
51
- auth0ClientId,
52
- auth0ClientSecret,
53
- );
54
-
55
- await cloneEnvRepository(env);
56
-
57
- const { deployConfig: deployGraphQLServerConfig } = await readDeployConfig(
58
- 'graphql-server',
59
- env,
60
- site,
61
- 'values',
62
- );
63
- const coreUrl = deployGraphQLServerConfig.graphqlServer.coreUrl;
64
-
65
- const clientCredentialsAlias = await getCCAlias({
66
- application: 'docupace-graphql-client-credentials',
67
- auth0Domain: auth0Domain,
68
- auth0AuthToken: auth0Token,
69
- });
70
-
71
- await createAlias(coreUrl, username, password, realm, clientCredentialsAlias);
72
- }
package/src/auth0/cli.js DELETED
@@ -1,76 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { Command } from 'commander';
4
- import { configureFromSite } from './configure.js';
5
- import { getVaultSecrets } from './vault.js';
6
-
7
- import dotenv from 'dotenv';
8
- import { configureAlias } from './alias.js';
9
- import { exportConf } from './export.js';
10
- import { getAuth0Metadata } from './metadata.js';
11
-
12
- dotenv.config({ path: ['.env.pipeline.local', 'config/.env.pipeline.local'] });
13
-
14
- const program = new Command();
15
-
16
- program
17
- .command(
18
- 'configureFromSite <fromSite> <toSite> <fromEnv> <toEnv> <deployUI> <deployGraphQLServer> <useNewDomain> <useS3> <deployCCUI>',
19
- )
20
- .description('Configure the Auth0 tenants in env for the given site')
21
- .action(
22
- async (
23
- fromSite,
24
- toSite,
25
- fromEnv,
26
- toEnv,
27
- deployUI,
28
- deployGraphQLServer,
29
- useNewDomain,
30
- useS3,
31
- deployCCUI,
32
- ) => {
33
- await configureFromSite(
34
- fromSite,
35
- toSite,
36
- fromEnv,
37
- toEnv,
38
- deployUI,
39
- deployGraphQLServer,
40
- useNewDomain,
41
- useS3 === 'true' || useS3 === true,
42
- deployCCUI,
43
- );
44
- },
45
- );
46
-
47
- program
48
- .command('getVaultSecrets <vaultPath>')
49
- .description('Get Secrets for Vault PATH')
50
- .action(async (vaultPath) => {
51
- const data = await getVaultSecrets(vaultPath);
52
- console.log(JSON.stringify(data, 'null', 2));
53
- });
54
-
55
- program
56
- .command('configureAlias <site> <env> <username> <password> <realm>')
57
- .description('Configure Core Alias for the given site')
58
- .action(async (site, env, username, password, realm) => {
59
- await configureAlias(site, env, username, password, realm);
60
- });
61
-
62
- program
63
- .command('exportConf <site> <env>')
64
- .description('Export Auth0 configuration for the given site')
65
- .action(async (site, env) => {
66
- await exportConf(site, env);
67
- });
68
-
69
- program
70
- .command('getAuth0Metadata <site> <env>')
71
- .description('Get Auth0 metadata for the given site')
72
- .action(async (site, env) => {
73
- await getAuth0Metadata(site, env);
74
- });
75
-
76
- program.parse(process.argv);