Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run/time/env/variables #2996

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open

run/time/env/variables #2996

wants to merge 9 commits into from

Conversation

pratapalakshmi
Copy link
Collaborator

@pratapalakshmi pratapalakshmi commented Jan 28, 2025

Summary by CodeRabbit

  • Configuration Updates

    • Added new environment variables for configuration management across multiple applications.
    • Introduced centralized environment configuration through a global config.js script.
    • Updated Dockerfiles to include new entrypoint scripts for enhanced initialization.
  • Build Process Improvements

    • Modified build scripts to clean distribution directories before compilation.
    • Enhanced environment variable handling for development and production environments.
  • Infrastructure Changes

    • Implemented consistent configuration approach across backoffice, KYB, and workflows dashboard applications.
    • Added support for dynamic environment variable injection at runtime.

Copy link

changeset-bot bot commented Jan 28, 2025

⚠️ No Changeset found

Latest commit: 3d8ddef

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Jan 28, 2025

Walkthrough

This pull request introduces a comprehensive update to environment variable management across multiple applications. The changes involve adding a new MODE environment variable, modifying Dockerfiles to include an entrypoint.sh script, and updating how environment variables are accessed globally. The modifications span several applications including backoffice-v2, kyb-app, and workflows-dashboard, with consistent changes to configuration handling and deployment setup.

Changes

File/Directory Change Summary
apps/*/Dockerfile Added production stage working directory, copied entrypoint.sh, set executable permissions, and defined new entrypoint
apps/*/entrypoint.sh New script to configure and generate environment variables configuration file
apps/*/global.d.ts Added global env type declaration
apps/*/index.html Added script tag to include /config.js
apps/*/public/config.js Created global configuration object with environment variables
deploy/.env Added new environment variables: VITE_DOMAIN, VITE_ENVIRONMENT_NAME, VITE_IMAGE_LOGO_URL, MODE
deploy/docker-compose-build.yml Added environment variables for workflows dashboard service

Possibly related PRs

  • chore: run dist with environment variables kyb-app #2645: The changes in the main PR, which involve adding a new environment variable MODE to the .env.example file, are related to the retrieved PR as both involve modifications to environment variable handling and the introduction of a global env object for configuration purposes.
  • feat: use run time variables in dist in wf-dashboard #2476: The changes in the main PR, particularly the addition of the MODE environment variable and modifications to the entrypoint.sh script, are directly related to the changes in the retrieved PR, which also involves the entrypoint.sh script and the use of environment variables like MODE.
  • chore: backoffice run dist with environment variables #2643: The changes in the main PR are related to the modifications in the entrypoint.sh script and the handling of environment variables, which are also addressed in the retrieved PR's entrypoint.sh and Dockerfile.

Suggested reviewers

  • Omri-Levy
  • alonp99

Poem

🐰 Env vars dancing, config in flight,
Dockerfiles singing with deployment might!
MODE joins the party, scripts take their stand,
Configurations bloom across our land 🌈
A rabbit's code, precise and bright! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 16

🧹 Nitpick comments (8)
deploy/docker-compose-build.yml (1)

81-85: Maintain consistent environment variable naming.

The MODE variable doesn't follow the VITE_ prefix convention used by other variables. This inconsistency could lead to confusion.

Consider renaming MODE to VITE_MODE for consistency:

-      MODE: ${MODE}
+      VITE_MODE: ${VITE_MODE:-development}
apps/kyb-app/global.d.ts (1)

1-3: Consider creating shared type definitions.

This declaration is identical across multiple applications. Consider creating a shared types package to maintain consistency and reduce duplication.

Create a shared types package that can be imported by all applications:

// packages/shared-types/env.d.ts
export interface EnvConfig {
  VITE_API_URL: string;
  VITE_API_KEY: string;
  VITE_ENVIRONMENT_NAME: string;
  VITE_KYB_DEFINITION_ID?: string;  // kyb-app specific
  VITE_DEFAULT_EXAMPLE_TOKEN?: string;  // kyb-app specific
  VITE_SENTRY_AUTH_TOKEN?: string;
  VITE_SENTRY_DSN?: string;
  [key: string]: string | undefined;
}

declare global {
  export var env: EnvConfig;
}
apps/kyb-app/index.html (1)

10-10: Consider adding integrity hash and defer/async attributes.

The config.js script is loaded synchronously without integrity verification. Consider:

  1. Adding an integrity hash to prevent script tampering
  2. Using defer/async if possible to improve page load performance
apps/backoffice-v2/Dockerfile (1)

29-30: Consider using COPY --chmod instead of separate RUN chmod.

While the current implementation is correct, you can optimize the Dockerfile by combining the COPY and chmod operations.

-COPY --from=dev /app/entrypoint.sh /app/entrypoint.sh
-RUN chmod a+x /app/entrypoint.sh;
+COPY --from=dev --chmod=755 /app/entrypoint.sh /app/entrypoint.sh

Also applies to: 33-34

apps/workflows-dashboard/entrypoint.sh (1)

3-22: Add input validation for environment variables.

The script sets default values but doesn't validate the format or content of provided values.

 if [[ -z "$VITE_DOMAIN" ]]
 then
     VITE_DOMAIN="http://localhost:3000"
+else
+    # Validate domain format
+    if ! echo "$VITE_DOMAIN" | grep -qE '^https?://[^/]+$'; then
+        echo "Error: VITE_DOMAIN must be a valid HTTP/HTTPS URL"
+        exit 1
+    fi
 fi
apps/kyb-app/entrypoint.sh (1)

1-46: Reduce code duplication across entrypoint scripts.

This script shares similar code with other entrypoint scripts. Consider creating a shared script.

Create a shared script at the root level:

  1. Move common functions to scripts/generate-config.sh
  2. Source it from individual entrypoint scripts
  3. Only keep app-specific configurations in entrypoint scripts
apps/backoffice-v2/index.html (1)

11-11: Add defer attribute to config.js script.

The script might block rendering. Consider adding the defer attribute if the configuration is not needed immediately.

-    <script type="text/javascript" src="/config.js"></script>
+    <script type="text/javascript" src="/config.js" defer></script>
apps/workflows-dashboard/package.json (1)

11-11: Use cross-platform clean command.

While cleaning the dist directory before build is good practice, rm -rf isn't cross-platform. Consider:

  1. Using rimraf for cross-platform compatibility
  2. Moving clean step to a separate script for better maintainability
-    "build": "rm -rf dist && tsc && vite build",
+    "clean": "rimraf dist",
+    "build": "npm run clean && tsc && vite build",

Don't forget to add rimraf to devDependencies:

   "devDependencies": {
+    "rimraf": "^5.0.0",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0e018fe and 0056c87.

📒 Files selected for processing (23)
  • apps/backoffice-v2/.env.example (1 hunks)
  • apps/backoffice-v2/Dockerfile (1 hunks)
  • apps/backoffice-v2/entrypoint.sh (1 hunks)
  • apps/backoffice-v2/global.d.ts (1 hunks)
  • apps/backoffice-v2/index.html (1 hunks)
  • apps/backoffice-v2/public/config.js (1 hunks)
  • apps/backoffice-v2/src/common/env/env.ts (1 hunks)
  • apps/backoffice-v2/src/main.tsx (2 hunks)
  • apps/kyb-app/Dockerfile (1 hunks)
  • apps/kyb-app/entrypoint.sh (1 hunks)
  • apps/kyb-app/global.d.ts (1 hunks)
  • apps/kyb-app/index.html (1 hunks)
  • apps/kyb-app/public/config.js (1 hunks)
  • apps/kyb-app/src/common/utils/request.ts (1 hunks)
  • apps/workflows-dashboard/Dockerfile (1 hunks)
  • apps/workflows-dashboard/entrypoint.sh (1 hunks)
  • apps/workflows-dashboard/global.d.ts (1 hunks)
  • apps/workflows-dashboard/index.html (1 hunks)
  • apps/workflows-dashboard/package.json (1 hunks)
  • apps/workflows-dashboard/public/config.js (1 hunks)
  • apps/workflows-dashboard/src/lib/request/request.ts (1 hunks)
  • deploy/.env (1 hunks)
  • deploy/docker-compose-build.yml (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • apps/backoffice-v2/.env.example
  • apps/workflows-dashboard/index.html
  • apps/workflows-dashboard/public/config.js
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test_windows
  • GitHub Check: test_linux
  • GitHub Check: build (windows-latest)
  • GitHub Check: lint
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (10)
deploy/docker-compose-build.yml (1)

81-85: Verify environment variable validation.

Ensure that the entrypoint.sh script properly validates these environment variables before starting the application.

Run the following script to check the validation in entrypoint.sh:

✅ Verification successful

Environment variables are properly validated with defaults

The entrypoint.sh script includes appropriate validation for all environment variables:

  • Checks for empty values using -z test
  • Sets development-friendly defaults:
    • VITE_DOMAIN → "http://localhost:3000"
    • MODE → "development"
    • VITE_ENVIRONMENT_NAME → "local"
    • VITE_IMAGE_LOGO_URL → empty string
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if entrypoint.sh validates the new environment variables

# Search for environment variable validation in entrypoint.sh
rg -A 5 'VITE_DOMAIN|VITE_ENVIRONMENT_NAME|VITE_IMAGE_LOGO_URL|MODE' ../apps/workflows-dashboard/entrypoint.sh

Length of output: 194


Script:

#!/bin/bash
# Find entrypoint.sh files
echo "=== Searching for entrypoint.sh files ==="
fd entrypoint.sh

# Search for environment variable validation in Dockerfile and related files
echo -e "\n=== Searching for environment variables in Docker files ==="
rg -A 5 'VITE_DOMAIN|VITE_ENVIRONMENT_NAME|VITE_IMAGE_LOGO_URL|MODE' -g 'Dockerfile*' -g 'docker-compose*.yml'

# Search for environment variable validation patterns in the codebase
echo -e "\n=== Searching for environment variable validation patterns ==="
rg -A 5 'process\.env\.(VITE_DOMAIN|VITE_ENVIRONMENT_NAME|VITE_IMAGE_LOGO_URL|MODE)' -g '*.{js,ts,jsx,tsx}'

Length of output: 1740


Script:

#!/bin/bash
# Check content of workflows-dashboard entrypoint.sh
echo "=== Content of workflows-dashboard/entrypoint.sh ==="
cat apps/workflows-dashboard/entrypoint.sh

# Look for common validation patterns
echo -e "\n=== Checking for validation patterns ==="
rg -A 5 '(check|validate|require).*(env|environment)' apps/workflows-dashboard/

Length of output: 891

apps/workflows-dashboard/global.d.ts (1)

1-3: Same type safety concerns as other applications.

See previous comments about creating shared type definitions.

apps/backoffice-v2/src/common/env/env.ts (1)

13-13: Ensure environment variables are available before validation

The code assumes globalThis.env is already initialized, but there's no guarantee of initialization order.

Add initialization check and provide better error message:

-const _env = EnvSchema.safeParse(globalThis.env);
+if (!globalThis.env) {
+  throw new Error('Environment variables not initialized. Ensure config.js is loaded before env.ts');
+}
+const _env = EnvSchema.safeParse(globalThis.env);
apps/backoffice-v2/src/main.tsx (1)

20-20: Verify config.js loading order

The config.js import might not complete before the environment variables are accessed.

Consider moving the import to a separate initialization function:

async function initializeEnv() {
  await import('../public/config.js?url');
  if (!globalThis.env) {
    throw new Error('Environment variables not initialized');
  }
}
apps/kyb-app/src/common/utils/request.ts (1)

7-8: 🛠️ Refactor suggestion

Remove @ts-ignore by adding proper type definitions.

The @ts-ignore comment suggests missing type definitions for globalThis.env. This should be addressed by adding proper type definitions in a global.d.ts file.

✅ Verification successful

Remove @ts-ignore as type definition exists

The @ts-ignore comment is unnecessary since globalThis.env is already typed in global.d.ts. While the type could be more specific than { [key: string]: any }, it's valid and allows the current usage.

Optional improvement: Consider making the type definition more specific by listing expected environment variables:

declare global {
  export var env: {
    VITE_API_URL?: string;
    // ... other env vars
  };
}
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if proper type definitions exist for globalThis.env
echo "Checking for type definitions..."
fd -t f "global.d.ts" "apps/kyb-app/"

Length of output: 135


Script:

#!/bin/bash
# Check contents of global.d.ts for globalThis.env definitions
cat "apps/kyb-app/global.d.ts"

Length of output: 91

apps/workflows-dashboard/Dockerfile (1)

26-27: Verify entrypoint.sh existence and content.

The Dockerfile assumes entrypoint.sh exists in the dev stage. Please ensure:

  1. The script exists in the correct location
  2. The script contains proper environment variable handling

Also applies to: 30-31, 34-35

✅ Verification successful

✓ Entrypoint script verified and properly configured

The entrypoint.sh script exists in the correct location and properly handles environment variables with appropriate defaults. The script correctly generates the runtime configuration and handles container commands.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if entrypoint.sh exists and verify its content
echo "Checking for entrypoint.sh..."
fd -t f "entrypoint.sh" "apps/workflows-dashboard/"

Length of output: 157


Script:

#!/bin/bash
# Check content of entrypoint.sh
cat apps/workflows-dashboard/entrypoint.sh

Length of output: 597

apps/kyb-app/Dockerfile (2)

12-13: Verify build output and PATH modification.

The build step has been added, but please ensure:

  1. The build output directory matches the COPY command in the prod stage
  2. The PATH modification is necessary (it might be redundant as node_modules/.bin is typically already in PATH)

Also applies to: 15-15

✅ Verification successful

Build configuration and PATH modification are correctly implemented

The build output directory (/app/dist) matches the COPY command in the prod stage, and the PATH modification is necessary for the dev stage to ensure local binaries are accessible during development.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if build output directory exists and matches COPY command
echo "Checking build configuration..."
fd -t f "package.json" "apps/kyb-app/" -x jq .scripts.build {}

Length of output: 155


Script:

#!/bin/bash
# Check vite config and Dockerfile
echo "Checking vite configuration..."
fd -t f "vite.config" "apps/kyb-app/"
echo -e "\nChecking Dockerfile prod stage..."
cat apps/kyb-app/Dockerfile

Length of output: 842


27-28: Ensure entrypoint.sh configuration matches workflows-dashboard.

The entrypoint configuration mirrors workflows-dashboard, which is good for consistency. Verify that:

  1. The environment variables handled in both entrypoint scripts are consistent
  2. The scripts follow the same error handling patterns

Also applies to: 31-32, 35-36

✅ Verification successful

Entrypoint scripts are structurally consistent but have application-specific variables

The scripts follow identical patterns for environment variable handling and error management. The differences in environment variables (kyb-app handles Sentry configuration while workflows-dashboard handles MODE and logo URL) are justified by different application requirements rather than inconsistency issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Compare entrypoint.sh files between applications
echo "Comparing entrypoint.sh files..."
fd -t f "entrypoint.sh" "apps/" -x md5sum {}

Length of output: 320


Script:

#!/bin/bash
echo "=== kyb-app/entrypoint.sh ==="
cat apps/kyb-app/entrypoint.sh
echo -e "\n=== workflows-dashboard/entrypoint.sh ==="
cat apps/workflows-dashboard/entrypoint.sh

Length of output: 1673

apps/backoffice-v2/Dockerfile (2)

25-26: LGTM! Working directory setup follows Docker best practices.

The WORKDIR directive is appropriately used to set up the container's working environment.


37-38: Verify entrypoint.sh exists in the dev stage.

The Dockerfile copies entrypoint.sh from the dev stage, but we need to ensure it exists.

✅ Verification successful

Entrypoint script exists and is correctly located

The entrypoint.sh file exists at apps/backoffice-v2/entrypoint.sh, confirming it's available for the Dockerfile build process.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if entrypoint.sh exists in the source code
fd -t f "entrypoint.sh$" apps/backoffice-v2/

Length of output: 79

Comment on lines +81 to +85
environment:
VITE_DOMAIN: ${VITE_DOMAIN}
VITE_ENVIRONMENT_NAME: ${VITE_ENVIRONMENT_NAME}
VITE_IMAGE_LOGO_URL: ${VITE_IMAGE_LOGO_URL}
MODE: ${MODE}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add default values and document environment variables.

The new environment variables lack default values and documentation. This could lead to deployment issues if variables are not properly set.

Apply this diff to add defaults and comments:

     environment:
-      VITE_DOMAIN: ${VITE_DOMAIN}
-      VITE_ENVIRONMENT_NAME: ${VITE_ENVIRONMENT_NAME}
-      VITE_IMAGE_LOGO_URL: ${VITE_IMAGE_LOGO_URL}
-      MODE: ${MODE}
+      # Domain for API endpoints
+      VITE_DOMAIN: ${VITE_DOMAIN:-localhost}
+      # Environment name (e.g., development, staging, production)
+      VITE_ENVIRONMENT_NAME: ${VITE_ENVIRONMENT_NAME:-development}
+      # URL for the logo image
+      VITE_IMAGE_LOGO_URL: ${VITE_IMAGE_LOGO_URL:-/logo.png}
+      # Application mode
+      MODE: ${MODE:-development}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
environment:
VITE_DOMAIN: ${VITE_DOMAIN}
VITE_ENVIRONMENT_NAME: ${VITE_ENVIRONMENT_NAME}
VITE_IMAGE_LOGO_URL: ${VITE_IMAGE_LOGO_URL}
MODE: ${MODE}
environment:
# Domain for API endpoints
VITE_DOMAIN: ${VITE_DOMAIN:-localhost}
# Environment name (e.g., development, staging, production)
VITE_ENVIRONMENT_NAME: ${VITE_ENVIRONMENT_NAME:-development}
# URL for the logo image
VITE_IMAGE_LOGO_URL: ${VITE_IMAGE_LOGO_URL:-/logo.png}
# Application mode
MODE: ${MODE:-development}

Comment on lines +1 to +3
declare global {
export var env: { [key: string]: any };
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using a strongly typed interface instead of any.

Using { [key: string]: any } reduces type safety. Consider creating a specific interface that defines the expected environment variables and their types.

+interface EnvConfig {
+  VITE_API_URL: string;
+  VITE_API_KEY: string;
+  VITE_ENVIRONMENT_NAME: string;
+  VITE_SENTRY_AUTH_TOKEN?: string;
+  VITE_SENTRY_DSN?: string;
+  [key: string]: string | undefined;  // for other env vars
+}
+
 declare global {
-  export var env: { [key: string]: any };
+  export var env: EnvConfig;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
declare global {
export var env: { [key: string]: any };
}
interface EnvConfig {
VITE_API_URL: string;
VITE_API_KEY: string;
VITE_ENVIRONMENT_NAME: string;
VITE_SENTRY_AUTH_TOKEN?: string;
VITE_SENTRY_DSN?: string;
[key: string]: string | undefined; // for other env vars
}
declare global {
export var env: EnvConfig;
}

Comment on lines 1 to 9
globalThis.env = {
VITE_API_URL: 'http://localhost:3000/api/v1/',
VITE_KYB_DEFINITION_ID: 'kyb_parent_kyc_session_example',
VITE_API_KEY: 'secret',
VITE_ENVIRONMENT_NAME: 'local',
VITE_DEFAULT_EXAMPLE_TOKEN: '12345678-1234-1234-1234-123456789012',
VITE_SENTRY_AUTH_TOKEN: '',
VITE_SENTRY_DSN: '',
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add runtime validation for environment variables.

Consider adding runtime validation to ensure all required environment variables are present and have the correct format.

// validation.ts
import { z } from 'zod';

const envSchema = z.object({
  VITE_API_URL: z.string().url(),
  VITE_API_KEY: z.string().min(1),
  VITE_ENVIRONMENT_NAME: z.enum(['development', 'staging', 'production']),
  VITE_KYB_DEFINITION_ID: z.string().min(1),
  VITE_DEFAULT_EXAMPLE_TOKEN: z.string().optional(),
  VITE_SENTRY_AUTH_TOKEN: z.string().optional(),
  VITE_SENTRY_DSN: z.string().optional(),
});

export function validateEnv(env: unknown) {
  return envSchema.parse(env);
}

💡 Codebase verification

⚠️ Potential issue

Security: Remove hardcoded sensitive values but use build-time injection instead of process.env

The security concern about hardcoded sensitive values is valid, but the suggested fix needs adjustment:

  1. Found multiple config files with hardcoded API keys and tokens:

    • apps/kyb-app/public/config.js
    • apps/backoffice-v2/public/config.js
  2. Instead of using process.env (which won't work in browser), use build-time environment injection:

 globalThis.env = {
-  VITE_API_URL: 'http://localhost:3000/api/v1/',
-  VITE_KYB_DEFINITION_ID: 'kyb_parent_kyc_session_example',
-  VITE_API_KEY: 'secret',
-  VITE_ENVIRONMENT_NAME: 'local',
-  VITE_DEFAULT_EXAMPLE_TOKEN: '12345678-1234-1234-1234-123456789012',
+  VITE_API_URL: import.meta.env.VITE_API_URL,
+  VITE_KYB_DEFINITION_ID: import.meta.env.VITE_KYB_DEFINITION_ID,
+  VITE_API_KEY: import.meta.env.VITE_API_KEY,
+  VITE_ENVIRONMENT_NAME: import.meta.env.VITE_ENVIRONMENT_NAME || 'development',
+  VITE_DEFAULT_EXAMPLE_TOKEN: import.meta.env.VITE_DEFAULT_EXAMPLE_TOKEN,
   VITE_SENTRY_AUTH_TOKEN: '',
   VITE_SENTRY_DSN: '',
 };
🔗 Analysis chain

Security: Remove sensitive information from source control.

Several security concerns in the default configuration:

  1. API key should never be committed, even if it's a development value
  2. Example tokens should be clearly marked as non-production
  3. Localhost URL might cause issues in different environments

Consider this safer approach:

 globalThis.env = {
-  VITE_API_URL: 'http://localhost:3000/api/v1/',
-  VITE_KYB_DEFINITION_ID: 'kyb_parent_kyc_session_example',
-  VITE_API_KEY: 'secret',
-  VITE_ENVIRONMENT_NAME: 'local',
-  VITE_DEFAULT_EXAMPLE_TOKEN: '12345678-1234-1234-1234-123456789012',
+  VITE_API_URL: process.env.VITE_API_URL || '',
+  VITE_KYB_DEFINITION_ID: process.env.VITE_KYB_DEFINITION_ID || '',
+  VITE_API_KEY: process.env.VITE_API_KEY || '',
+  VITE_ENVIRONMENT_NAME: process.env.VITE_ENVIRONMENT_NAME || 'development',
+  VITE_DEFAULT_EXAMPLE_TOKEN: process.env.VITE_DEFAULT_EXAMPLE_TOKEN || 'example-only-do-not-use',
   VITE_SENTRY_AUTH_TOKEN: '',
   VITE_SENTRY_DSN: '',
 };

Let's verify if sensitive information exists in other configuration files:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for potential hardcoded secrets in config files
echo "Checking for potential secrets in config files..."
rg -g '*.js' -g '*.ts' -g '*.json' -i '(secret|token|key|password|credential)' apps/

Length of output: 66330

Comment on lines 1 to 9
globalThis.env = {
VITE_API_URL: 'http://localhost:3000/api/v1/internal',
VITE_KYB_DEFINITION_ID: 'kyb_parent_kyc_session_example',
VITE_API_KEY: 'secret',
VITE_ENVIRONMENT_NAME: 'local',
VITE_DEFAULT_EXAMPLE_TOKEN: '12345678-1234-1234-1234-123456789012',
VITE_SENTRY_AUTH_TOKEN: '',
VITE_SENTRY_DSN: '',
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical: Remove hardcoded sensitive values from client-side code

Storing sensitive values like API keys and URLs directly in client-side JavaScript poses several security risks:

  1. Values are exposed in source code
  2. Configuration can't be changed without rebuilding
  3. Different environments need different values

Consider these alternatives:

  1. Use environment variable substitution at build time
  2. Inject values at runtime through server-side rendered script
  3. Move sensitive values to secure backend endpoints

Example implementation using runtime injection:

globalThis.env = {
  VITE_API_URL: '{{VITE_API_URL}}',
  VITE_KYB_DEFINITION_ID: '{{VITE_KYB_DEFINITION_ID}}',
  VITE_API_KEY: '{{VITE_API_KEY}}',
  VITE_ENVIRONMENT_NAME: '{{VITE_ENVIRONMENT_NAME}}',
  VITE_DEFAULT_EXAMPLE_TOKEN: '{{VITE_DEFAULT_EXAMPLE_TOKEN}}',
  VITE_SENTRY_AUTH_TOKEN: '{{VITE_SENTRY_AUTH_TOKEN}}',
  VITE_SENTRY_DSN: '{{VITE_SENTRY_DSN}}',
};

Comment on lines 4 to 5
//@ts-ignore
baseURL: globalThis.env.VITE_API_URL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix type safety and ensure consistent environment variable access

  1. The @ts-ignore directive bypasses type checking, which could lead to runtime errors
  2. Inconsistent environment variable access: using globalThis.env for baseURL but import.meta.env in the interceptor

Consider these improvements:

  1. Add proper TypeScript types for globalThis.env
  2. Use consistent environment variable access method
  3. Add runtime checks for required environment variables
-  //@ts-ignore
-  baseURL: globalThis.env.VITE_API_URL,
+  baseURL: globalThis.env?.VITE_API_URL ?? throw new Error('VITE_API_URL is required'),

Also update the interceptor to use the same access method:

-    config.headers['Authorization'] = `Api-Key ${import.meta.env.VITE_API_KEY}`;
+    config.headers['Authorization'] = `Api-Key ${globalThis.env?.VITE_API_KEY}`;

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines 24 to 32
if [[ -z "$VITE_POLLING_INTERVAL" ]]
then
VITE_POLLING_INTERVAL=10
fi

if [[ -z "$VITE_ASSIGNMENT_POLLING_INTERVAL" ]]
then
VITE_ASSIGNMENT_POLLING_INTERVAL=5
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add validation for numeric environment variables.

The polling intervals should be validated to ensure:

  1. Values are numeric
  2. Values are within reasonable bounds
  3. ASSIGNMENT_POLLING_INTERVAL should not exceed POLLING_INTERVAL
 if [[ -z "$VITE_POLLING_INTERVAL" ]]
 then
     VITE_POLLING_INTERVAL=10
+else
+    if ! [[ "$VITE_POLLING_INTERVAL" =~ ^[0-9]+$ ]]; then
+        echo "Error: VITE_POLLING_INTERVAL must be a positive integer"
+        exit 1
+    fi
+    if (( VITE_POLLING_INTERVAL < 5 || VITE_POLLING_INTERVAL > 300 )); then
+        echo "Error: VITE_POLLING_INTERVAL must be between 5 and 300 seconds"
+        exit 1
+    fi
 fi

Apply similar validation to VITE_ASSIGNMENT_POLLING_INTERVAL.

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines 1 to 6
#!/usr/bin/env sh

if [[ -z "$VITE_DOMAIN" ]]
then
VITE_DOMAIN="http://localhost:3000"
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix shell compatibility and review default domain.

  1. The script uses sh but contains bash-specific syntax ([[]]). Either change the shebang to #!/bin/bash or use POSIX-compatible [ for better portability.
  2. The default domain points to localhost which might not be suitable for production environments.
-#!/usr/bin/env sh
+#!/usr/bin/env bash
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#!/usr/bin/env sh
if [[ -z "$VITE_DOMAIN" ]]
then
VITE_DOMAIN="http://localhost:3000"
fi
#!/usr/bin/env bash
if [[ -z "$VITE_DOMAIN" ]]
then
VITE_DOMAIN="http://localhost:3000"
fi

Comment on lines 39 to 51
cat << EOF > /usr/share/nginx/html/config.js
globalThis.env = {
VITE_API_URL: "$VITE_DOMAIN/api/v1/internal",
VITE_API_KEY: "$VITE_API_KEY",
VITE_AUTH_ENABLED: "$VITE_AUTH_ENABLED",
VITE_MOCK_SERVER: "$VITE_MOCK_SERVER",
VITE_POLLING_INTERVAL: "$VITE_POLLING_INTERVAL",
VITE_ASSIGNMENT_POLLING_INTERVAL: "$VITE_ASSIGNMENT_POLLING_INTERVAL",
VITE_FETCH_SIGNED_URL: "$VITE_FETCH_SIGNED_URL",
VITE_ENVIRONMENT_NAME: "local",
MODE: "production"
}
EOF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Security: Protect sensitive data and improve configuration handling.

Several issues with the config.js generation:

  1. Sensitive data (API key) is exposed to the client
  2. Environment variable values aren't escaped, potentially breaking the JS
  3. Environment name and mode are hardcoded, ignoring actual environment settings
 cat << EOF > /usr/share/nginx/html/config.js
 globalThis.env = {
   VITE_API_URL: "$VITE_DOMAIN/api/v1/internal",
-  VITE_API_KEY: "$VITE_API_KEY",
+  // Don't expose API key to client
   VITE_AUTH_ENABLED: "$VITE_AUTH_ENABLED",
   VITE_MOCK_SERVER: "$VITE_MOCK_SERVER",
   VITE_POLLING_INTERVAL: "$VITE_POLLING_INTERVAL",
   VITE_ASSIGNMENT_POLLING_INTERVAL: "$VITE_ASSIGNMENT_POLLING_INTERVAL",
   VITE_FETCH_SIGNED_URL: "$VITE_FETCH_SIGNED_URL",
-  VITE_ENVIRONMENT_NAME: "local",
-  MODE: "production"
+  VITE_ENVIRONMENT_NAME: "${VITE_ENVIRONMENT_NAME:-local}",
+  MODE: "${MODE:-production}"
 }
 EOF
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cat << EOF > /usr/share/nginx/html/config.js
globalThis.env = {
VITE_API_URL: "$VITE_DOMAIN/api/v1/internal",
VITE_API_KEY: "$VITE_API_KEY",
VITE_AUTH_ENABLED: "$VITE_AUTH_ENABLED",
VITE_MOCK_SERVER: "$VITE_MOCK_SERVER",
VITE_POLLING_INTERVAL: "$VITE_POLLING_INTERVAL",
VITE_ASSIGNMENT_POLLING_INTERVAL: "$VITE_ASSIGNMENT_POLLING_INTERVAL",
VITE_FETCH_SIGNED_URL: "$VITE_FETCH_SIGNED_URL",
VITE_ENVIRONMENT_NAME: "local",
MODE: "production"
}
EOF
cat << EOF > /usr/share/nginx/html/config.js
globalThis.env = {
VITE_API_URL: "$VITE_DOMAIN/api/v1/internal",
// Don't expose API key to client
VITE_AUTH_ENABLED: "$VITE_AUTH_ENABLED",
VITE_MOCK_SERVER: "$VITE_MOCK_SERVER",
VITE_POLLING_INTERVAL: "$VITE_POLLING_INTERVAL",
VITE_ASSIGNMENT_POLLING_INTERVAL: "$VITE_ASSIGNMENT_POLLING_INTERVAL",
VITE_FETCH_SIGNED_URL: "$VITE_FETCH_SIGNED_URL",
VITE_ENVIRONMENT_NAME: "${VITE_ENVIRONMENT_NAME:-local}",
MODE: "${MODE:-production}"
}
EOF

Comment on lines 8 to 11
if [[ -z "$VITE_API_KEY" ]]
then
VITE_API_KEY="secret"
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Security: Remove hardcoded API key and add validation.

Hardcoding a default API key value is a security risk. The script should:

  1. Fail fast if no API key is provided in production
  2. Validate the API key format/length
 if [[ -z "$VITE_API_KEY" ]]
 then
-    VITE_API_KEY="secret"
+    if [[ "${MODE}" == "production" ]]; then
+        echo "Error: VITE_API_KEY must be set in production"
+        exit 1
+    fi
+    VITE_API_KEY="development-only-key"
 fi

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines 13 to 22
if [[ -z "$VITE_AUTH_ENABLED" ]]
then
VITE_AUTH_ENABLED=true
fi


if [[ -z "$VITE_MOCK_SERVER" ]]
then
VITE_MOCK_SERVER=false
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Normalize boolean environment variables.

The script should normalize boolean values to prevent issues with string comparison:

  1. Convert input to lowercase
  2. Validate against known boolean values
  3. Normalize output to "true"/"false"
 if [[ -z "$VITE_AUTH_ENABLED" ]]
 then
     VITE_AUTH_ENABLED=true
+else
+    # Convert to lowercase
+    VITE_AUTH_ENABLED=$(echo "$VITE_AUTH_ENABLED" | tr '[:upper:]' '[:lower:]')
+    # Validate and normalize
+    case "$VITE_AUTH_ENABLED" in
+        true|1|yes) VITE_AUTH_ENABLED=true ;;
+        false|0|no) VITE_AUTH_ENABLED=false ;;
+        *) echo "Error: VITE_AUTH_ENABLED must be a boolean value"; exit 1 ;;
+    esac
 fi

Apply similar changes to other boolean variables (VITE_MOCK_SERVER, VITE_FETCH_SIGNED_URL).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [[ -z "$VITE_AUTH_ENABLED" ]]
then
VITE_AUTH_ENABLED=true
fi
if [[ -z "$VITE_MOCK_SERVER" ]]
then
VITE_MOCK_SERVER=false
fi
if [[ -z "$VITE_AUTH_ENABLED" ]]
then
VITE_AUTH_ENABLED=true
else
# Convert to lowercase
VITE_AUTH_ENABLED=$(echo "$VITE_AUTH_ENABLED" | tr '[:upper:]' '[:lower:]')
# Validate and normalize
case "$VITE_AUTH_ENABLED" in
true|1|yes) VITE_AUTH_ENABLED=true ;;
false|0|no) VITE_AUTH_ENABLED=false ;;
*) echo "Error: VITE_AUTH_ENABLED must be a boolean value"; exit 1 ;;
esac
fi
if [[ -z "$VITE_MOCK_SERVER" ]]
then
VITE_MOCK_SERVER=false
else
# Convert to lowercase
VITE_MOCK_SERVER=$(echo "$VITE_MOCK_SERVER" | tr '[:upper:]' '[:lower:]')
# Validate and normalize
case "$VITE_MOCK_SERVER" in
true|1|yes) VITE_MOCK_SERVER=true ;;
false|0|no) VITE_MOCK_SERVER=false ;;
*) echo "Error: VITE_MOCK_SERVER must be a boolean value"; exit 1 ;;
esac
fi

@pratapalakshmi pratapalakshmi changed the title Run/time/env/variables run/time/env/variables Jan 31, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
apps/workflows-dashboard/entrypoint.sh (2)

1-2: 🛠️ Refactor suggestion

Add shell safety options.

Add shell safety options to prevent common shell script issues.

 #!/usr/bin/env sh
+set -euo pipefail

25-32: ⚠️ Potential issue

Security: Avoid exposing sensitive configuration in client-side JavaScript.

The script generates a client-side JavaScript file with environment variables. This approach might expose sensitive configuration to client-side code.

Consider:

  1. Only exposing necessary non-sensitive variables to the client
  2. Using server-side configuration for sensitive data
  3. Implementing proper API endpoints for required dynamic configuration
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a005e3 and 9b28afe.

📒 Files selected for processing (2)
  • apps/workflows-dashboard/entrypoint.sh (1 hunks)
  • apps/workflows-dashboard/src/lib/request/request.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/workflows-dashboard/src/lib/request/request.ts
🧰 Additional context used
🪛 Shellcheck (0.10.0)
apps/workflows-dashboard/entrypoint.sh

[warning] 3-3: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 8-8: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 13-13: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 19-19: In POSIX sh, [[ ]] is undefined.

(SC3010)

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: test_windows
  • GitHub Check: build (windows-latest)
  • GitHub Check: test_linux
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: lint
  • GitHub Check: Analyze (javascript)
  • GitHub Check: spell_check
🔇 Additional comments (1)
apps/workflows-dashboard/entrypoint.sh (1)

34-35: LGTM!

The command execution follows container entrypoint best practices by using exec "$@" to properly handle signals and process management.

Comment on lines +3 to +22
if [[ -n "$VITE_DOMAIN" ]]
then
VITE_API_URL="$VITE_DOMAIN/api/v1/"
fi

if [[ -n "$MODE" ]]
then
MODE="$MODE"
fi

if [[ -n "$VITE_IMAGE_LOGO_URL" ]]
then
VITE_IMAGE_LOGO_URL="$VITE_IMAGE_LOGO_URL"
fi


if [[ -n "$VITE_ENVIRONMENT_NAME" ]]
then
VITE_ENVIRONMENT_NAME="$VITE_ENVIRONMENT_NAME"
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Fix POSIX compatibility and simplify variable handling.

  1. The [[ ]] syntax is not POSIX compliant. Use [ ] for better compatibility.
  2. The MODE variable block is redundant as it just assigns the variable to itself.
-if [[ -n "$VITE_DOMAIN" ]]
+if [ -n "$VITE_DOMAIN" ]
 then
     VITE_API_URL="$VITE_DOMAIN/api/v1/"
 fi

-if [[ -n "$MODE" ]]
-then
-    MODE="$MODE"
-fi

-if [[ -n "$VITE_IMAGE_LOGO_URL" ]]
+if [ -n "$VITE_IMAGE_LOGO_URL" ]
 then
     VITE_IMAGE_LOGO_URL="$VITE_IMAGE_LOGO_URL"
 fi

-if [[ -n "$VITE_ENVIRONMENT_NAME" ]]
+if [ -n "$VITE_ENVIRONMENT_NAME" ]
 then
     VITE_ENVIRONMENT_NAME="$VITE_ENVIRONMENT_NAME"
 fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [[ -n "$VITE_DOMAIN" ]]
then
VITE_API_URL="$VITE_DOMAIN/api/v1/"
fi
if [[ -n "$MODE" ]]
then
MODE="$MODE"
fi
if [[ -n "$VITE_IMAGE_LOGO_URL" ]]
then
VITE_IMAGE_LOGO_URL="$VITE_IMAGE_LOGO_URL"
fi
if [[ -n "$VITE_ENVIRONMENT_NAME" ]]
then
VITE_ENVIRONMENT_NAME="$VITE_ENVIRONMENT_NAME"
fi
if [ -n "$VITE_DOMAIN" ]
then
VITE_API_URL="$VITE_DOMAIN/api/v1/"
fi
if [ -n "$VITE_IMAGE_LOGO_URL" ]
then
VITE_IMAGE_LOGO_URL="$VITE_IMAGE_LOGO_URL"
fi
if [ -n "$VITE_ENVIRONMENT_NAME" ]
then
VITE_ENVIRONMENT_NAME="$VITE_ENVIRONMENT_NAME"
fi
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 3-3: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 8-8: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 13-13: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 19-19: In POSIX sh, [[ ]] is undefined.

(SC3010)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
apps/workflows-dashboard/entrypoint.sh (4)

1-2: Enhance Shell Safety Options

Consider adding shell safety options immediately after the shebang to improve script robustness. For example, add:

+set -euo pipefail

This catches unset variables, errors, and failures in pipelines.


8-11: Eliminate Redundant MODE Block & Use POSIX Test

The block checking MODE is redundant since it simply assigns the variable to itself. Also, update the test for POSIX compliance. You could remove this block entirely unless a transformation is intended:

-if [ -n "$MODE" ]
-then
-	MODE="$MODE"
-fi

If no processing is needed, it's best to remove these lines.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 8-8: In POSIX sh, [[ ]] is undefined.

(SC3010)


13-16: Refactor VITE_IMAGE_LOGO_URL Check for POSIX Compatibility

Similarly, update the test to use POSIX-compliant syntax. Also, the assignment is a no-op. Consider removing the redundant block if no processing is required:

-if [[ -n "$VITE_IMAGE_LOGO_URL" ]]
-then
-    VITE_IMAGE_LOGO_URL="$VITE_IMAGE_LOGO_URL"
-fi
+if [ -n "$VITE_IMAGE_LOGO_URL" ]
+then
+    : # Variable already set; no reassignment needed.
+fi

Alternatively, remove the conditional block if it serves no purpose.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 13-13: In POSIX sh, [[ ]] is undefined.

(SC3010)


19-22: Refactor VITE_ENVIRONMENT_NAME Check

Apply the same POSIX syntax fix for this block and consider its necessity:

-if [[ -n "$VITE_ENVIRONMENT_NAME" ]]
-then
-    VITE_ENVIRONMENT_NAME="$VITE_ENVIRONMENT_NAME"
-fi
+if [ -n "$VITE_ENVIRONMENT_NAME" ]
+then
+    : # No transformation; consider removing if redundant.
+fi

This ensures consistency and compatibility.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 19-19: In POSIX sh, [[ ]] is undefined.

(SC3010)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b28afe and 3d8ddef.

📒 Files selected for processing (2)
  • apps/workflows-dashboard/entrypoint.sh (1 hunks)
  • apps/workflows-dashboard/src/lib/request/request.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/workflows-dashboard/src/lib/request/request.ts
🧰 Additional context used
🪛 Shellcheck (0.10.0)
apps/workflows-dashboard/entrypoint.sh

[warning] 3-3: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 8-8: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 13-13: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 19-19: In POSIX sh, [[ ]] is undefined.

(SC3010)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test_windows
  • GitHub Check: test_linux
  • GitHub Check: build (windows-latest)
  • GitHub Check: lint
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
apps/workflows-dashboard/entrypoint.sh (3)

25-32: Review Client-Side Exposure of Environment Variables

The script writes environment variables to a JavaScript file (config.js), making them accessible in client-side code. Please verify that none of the environment variables (e.g., VITE_API_URL, VITE_ENVIRONMENT_NAME, MODE, VITE_IMAGE_LOGO_URL) contain sensitive information. If any variable is sensitive, consider masking it or moving its handling to the server side.


34-35: Confirm Execution Parameters

The use of exec "$@" is standard for passing the CMD arguments. Ensure that any command-line arguments (potentially provided via Docker CMD) are safely and correctly handled by the script.


3-7: 🛠️ Refactor suggestion

Ensure POSIX Compatibility for Environment Checks (VITE_DOMAIN)

The use of [[ ... ]] is not POSIX compliant. Replace it with [ ... ]. For instance:

-if [[ -n "$VITE_DOMAIN" ]]
+if [ -n "$VITE_DOMAIN" ]
 then
-    VITE_API_URL="$VITE_DOMAIN/api/v1/"
+    VITE_API_URL="$VITE_DOMAIN/api/v1/"
 fi

This alteration improves compatibility with /usr/bin/env sh.

Likely invalid or redundant comment.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 3-3: In POSIX sh, [[ ]] is undefined.

(SC3010)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
apps/kyb-app/entrypoint.sh (1)

35-44: ⚠️ Potential issue

Sensitive Data Exposure in Client-side Configuration

The generated /usr/share/nginx/html/config.js (lines 35-44) exposes several environment variables (e.g., VITE_API_KEY, VITE_SENTRY_AUTH_TOKEN, and VITE_SENTRY_DSN) to the client-side. This replicates concerns from previous reviews regarding the exposure of sensitive data. Please ensure that either these values are safe to expose or consider removing/masking them in the client configuration.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3d8ddef and aa5ae15.

📒 Files selected for processing (2)
  • apps/kyb-app/entrypoint.sh (1 hunks)
  • apps/kyb-app/src/common/utils/request.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/kyb-app/src/common/utils/request.ts
🧰 Additional context used
🪛 Shellcheck (0.10.0)
apps/kyb-app/entrypoint.sh

[warning] 3-3: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 9-9: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 14-14: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 20-20: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 25-25: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 30-30: In POSIX sh, [[ ]] is undefined.

(SC3010)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test_windows
  • GitHub Check: test_linux
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: lint
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
apps/kyb-app/entrypoint.sh (1)

46-47: CMD Execution Handling

The use of exec "$@" (lines 46-47) to forward the CMD arguments is correctly implemented and allows proper container command execution.

Comment on lines +3 to +33
if [[ -n "$VITE_DOMAIN" ]]
then
VITE_API_URL="$VITE_DOMAIN/api/v1/"
fi


if [[ -n "$VITE_API_KEY" ]]
then
VITE_API_KEY="$VITE_API_KEY"
fi

if [[ -n "$VITE_ENVIRONMENT_NAME" ]]
then
VITE_ENVIRONMENT_NAME="$VITE_ENVIRONMENT_NAME"
fi


if [[ -n "$VITE_DEFAULT_EXAMPLE_TOKEN" ]]
then
VITE_DEFAULT_EXAMPLE_TOKEN="$VITE_DEFAULT_EXAMPLE_TOKEN"
fi

if [[ -n "$VITE_SENTRY_AUTH_TOKEN" ]]
then
VITE_SENTRY_AUTH_TOKEN="$VITE_SENTRY_AUTH_TOKEN"
fi

if [[ -n "$VITE_SENTRY_DSN" ]]
then
VITE_SENTRY_DSN="$VITE_SENTRY_DSN"
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

POSIX Compatibility Issue: Replace Non-POSIX Conditionals

The script’s shebang (#!/usr/bin/env sh, line 1) indicates a POSIX shell, but the conditional checks use the non-POSIX [[ ... ]] syntax. This will cause incompatibility issues in pure POSIX environments. Please update all conditionals (lines 3, 9, 14, 20, 25, and 30) to use [ ... ] instead. For example:

- if [[ -n "$VITE_DOMAIN" ]]
+ if [ -n "$VITE_DOMAIN" ]

Apply similar changes for the other if blocks.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [[ -n "$VITE_DOMAIN" ]]
then
VITE_API_URL="$VITE_DOMAIN/api/v1/"
fi
if [[ -n "$VITE_API_KEY" ]]
then
VITE_API_KEY="$VITE_API_KEY"
fi
if [[ -n "$VITE_ENVIRONMENT_NAME" ]]
then
VITE_ENVIRONMENT_NAME="$VITE_ENVIRONMENT_NAME"
fi
if [[ -n "$VITE_DEFAULT_EXAMPLE_TOKEN" ]]
then
VITE_DEFAULT_EXAMPLE_TOKEN="$VITE_DEFAULT_EXAMPLE_TOKEN"
fi
if [[ -n "$VITE_SENTRY_AUTH_TOKEN" ]]
then
VITE_SENTRY_AUTH_TOKEN="$VITE_SENTRY_AUTH_TOKEN"
fi
if [[ -n "$VITE_SENTRY_DSN" ]]
then
VITE_SENTRY_DSN="$VITE_SENTRY_DSN"
fi
if [ -n "$VITE_DOMAIN" ]
then
VITE_API_URL="$VITE_DOMAIN/api/v1/"
fi
if [ -n "$VITE_API_KEY" ]
then
VITE_API_KEY="$VITE_API_KEY"
fi
if [ -n "$VITE_ENVIRONMENT_NAME" ]
then
VITE_ENVIRONMENT_NAME="$VITE_ENVIRONMENT_NAME"
fi
if [ -n "$VITE_DEFAULT_EXAMPLE_TOKEN" ]
then
VITE_DEFAULT_EXAMPLE_TOKEN="$VITE_DEFAULT_EXAMPLE_TOKEN"
fi
if [ -n "$VITE_SENTRY_AUTH_TOKEN" ]
then
VITE_SENTRY_AUTH_TOKEN="$VITE_SENTRY_AUTH_TOKEN"
fi
if [ -n "$VITE_SENTRY_DSN" ]
then
VITE_SENTRY_DSN="$VITE_SENTRY_DSN"
fi
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 3-3: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 9-9: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 14-14: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 20-20: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 25-25: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 30-30: In POSIX sh, [[ ]] is undefined.

(SC3010)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/backoffice-v2/entrypoint.sh (1)

3-37: Refactor Environment Variable Checks
Multiple conditionals (lines 3–37) use the bash-specific [[ … ]] operator. After changing the shebang, these checks will work as intended. In addition, for maintainability you might consider refactoring these repeated checks into a function or loop. For example, if many environment variables are processed similarly, a loop over a list of variable names could reduce duplication and simplify future updates.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 3-3: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 8-8: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 13-13: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 18-18: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 23-23: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 28-28: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 33-33: In POSIX sh, [[ ]] is undefined.

(SC3010)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aa5ae15 and 2ac6504.

📒 Files selected for processing (3)
  • apps/backoffice-v2/entrypoint.sh (1 hunks)
  • apps/backoffice-v2/src/common/env/env.ts (1 hunks)
  • apps/backoffice-v2/src/main.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/backoffice-v2/src/main.tsx
  • apps/backoffice-v2/src/common/env/env.ts
🧰 Additional context used
🪛 Shellcheck (0.10.0)
apps/backoffice-v2/entrypoint.sh

[warning] 3-3: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 8-8: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 13-13: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 18-18: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 23-23: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 28-28: In POSIX sh, [[ ]] is undefined.

(SC3010)


[warning] 33-33: In POSIX sh, [[ ]] is undefined.

(SC3010)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test_windows
  • GitHub Check: test_linux
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: lint
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
apps/backoffice-v2/entrypoint.sh (3)

52-53: Verify Execution Flow
The script ends with exec "$@", which is a standard pattern to hand over control to the command provided as arguments. Ensure that any necessary pre-execution checks or setups (such as the validations discussed in earlier reviews for numeric values) are completed before this step.


1-1: 🛠️ Refactor suggestion

⚠️ Potential issue

Update Shebang for Shell Compatibility
The script is currently using #!/usr/bin/env sh, yet it employs bash‑specific constructs (such as [[ … ]]). This can lead to errors when running in a strictly POSIX shell. I recommend updating the shebang to bash.

-#!/usr/bin/env sh
+#!/usr/bin/env bash

Likely invalid or redundant comment.


38-50: 🛠️ Refactor suggestion

Enhance Configuration File Generation
The script generates /usr/share/nginx/html/config.js by directly injecting environment variables. Consider the following improvements:

  • Security: Avoid exposing sensitive values like VITE_API_KEY if they are not meant for client-side consumption.
  • Flexibility: Instead of hardcoding VITE_ENVIRONMENT_NAME and MODE, use the environment variables with sensible defaults (e.g., use "${VITE_ENVIRONMENT_NAME:-local}" and "${MODE:-production}"). This makes the configuration adaptable to various deployment environments.
-  VITE_ENVIRONMENT_NAME: "local",
-  MODE: "production"
+  VITE_ENVIRONMENT_NAME: "${VITE_ENVIRONMENT_NAME:-local}",
+  MODE: "${MODE:-production}"

[security]

Likely invalid or redundant comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant