Skip to content

fix: DB URL override fails in some cases#34206

Merged
sharat87 merged 2 commits intoreleasefrom
fix/db-url-override
Jun 12, 2024
Merged

fix: DB URL override fails in some cases#34206
sharat87 merged 2 commits intoreleasefrom
fix/db-url-override

Conversation

@sharat87
Copy link
Member

@sharat87 sharat87 commented Jun 12, 2024

The current fallback implementation doesn't work in the below case:

The APPSMITH_MONGODB_URI is set outside the container, and APPSMITH_DB_URL is set in the docker.env.

This scenario will be showing up a lot more now that the docker.env.sh that generates new docker.env files has APPSMITH_DB_URL in it.

Problem is that since we load env variables from both outside and docker.env individually, we end up loading both APPSMITH_MONGODB_URI and APPSMITH_DB_URL. And in this case, the APPSMITH_DB_URL will be from the just-generated docker.env, so we'll end up with a localhost URL, even though APPSMITH_MONGODB_URI was set to an external endpoint outside the container.

This is the problem we were facing with our DPs recently.

This PR fixes this problem by doing the env name "rename" separately for outside env variables, and once for docker.env env variables.

/test sanity

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/9481037167
Commit: c6ce2a8
Cypress dashboard url: Click here!

Summary by CodeRabbit

  • Chores
    • Improved environment variable handling to ensure APPSMITH_DB_URL is correctly set, enhancing database connection reliability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 12, 2024

Walkthrough

The recent updates ensure that the environment variable APPSMITH_DB_URL is correctly set by falling back to APPSMITH_MONGODB_URI if it is not defined. This change enhances backward compatibility as the system transitions to using Postgres. The modifications span across multiple scripts, including entrypoint.sh and a Node.js utility script, to handle this fallback mechanism consistently.

Changes

File Path Change Summary
deploy/docker/fs/opt/appsmith/entrypoint.sh Reassigned APPSMITH_MONGODB_URI to APPSMITH_DB_URL if not empty, loaded env vars from docker.env and pre-define.env
deploy/docker/fs/opt/appsmith/utils/bin/index.js Ensured APPSMITH_DB_URL is set by falling back to APPSMITH_MONGODB_URI if it's not defined

Sequence Diagram(s)

The changes are straightforward and do not significantly alter the control flow, so no sequence diagrams are necessary.

Possibly related issues

Poem

In the scripts where data flows,
A fallback now, for what it knows.
Mongo's URI, a guiding light,
To set the DB URL right.
With backward steps, it paves the way,
For Postgres dawn, a brighter day.
🌟🐰✨

Warning

Review ran into problems

Problems (1)
  • Git: Failed to clone repository. Please contact CodeRabbit support.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@github-actions github-actions bot added the Bug Something isn't working label Jun 12, 2024
@sharat87
Copy link
Member Author

/build-deploy-preview skip-tests=true

@github-actions
Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/9480979769.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 34206.
recreate: .

@sharat87 sharat87 marked this pull request as ready for review June 12, 2024 10:30
@sharat87 sharat87 requested review from abhvsn and mohanarpit June 12, 2024 10:31
mohanarpit
mohanarpit previously approved these changes Jun 12, 2024
@sharat87 sharat87 added the ok-to-test Required label for CI label Jun 12, 2024
@github-actions
Copy link

Deploy-Preview-URL: https://ce-34206.dp.appsmith.com

Copy link
Contributor

@abhvsn abhvsn left a comment

Choose a reason for hiding this comment

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

Minor clarification!

@sharat87 sharat87 requested a review from abhvsn June 12, 2024 10:43
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: 9

Outside diff range and nitpick comments (2)
deploy/docker/fs/opt/appsmith/utils/bin/index.js (1)

Line range hint 33-33: Refactor to move the return statements inside the respective command functions to avoid illegal return statements outside of a function.

- return;
+ // Move the return statement inside the respective functions.

Also applies to: 42-42, 47-47, 52-52, 57-57, 61-61

Tools
Biome

[error] 16-16: Avoid the delete operator which can impact performance. (lint/performance/noDelete)

Unsafe fix: Use an undefined assignment instead.

deploy/docker/fs/opt/appsmith/entrypoint.sh (1)

Line range hint 62-62: Declare and assign separately to avoid masking return values, which can lead to hidden bugs.

- local generated_appsmith_mongodb_password=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13; echo "")
+ local generated_appsmith_mongodb_password
+ generated_appsmith_mongodb_password=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13; echo "")

Also applies to: 66-66, 70-70, 74-74

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1d80c06 and c6ce2a8.

Files selected for processing (2)
  • deploy/docker/fs/opt/appsmith/entrypoint.sh (3 hunks)
  • deploy/docker/fs/opt/appsmith/utils/bin/index.js (1 hunks)
Additional context used
Biome
deploy/docker/fs/opt/appsmith/utils/bin/index.js

[error] 33-33: Illegal return statement outside of a function (parse)


[error] 42-42: Illegal return statement outside of a function (parse)


[error] 47-47: Illegal return statement outside of a function (parse)


[error] 52-52: Illegal return statement outside of a function (parse)


[error] 57-57: Illegal return statement outside of a function (parse)


[error] 61-61: Illegal return statement outside of a function (parse)


[error] 16-16: Avoid the delete operator which can impact performance. (lint/performance/noDelete)

Unsafe fix: Use an undefined assignment instead.

Shellcheck
deploy/docker/fs/opt/appsmith/entrypoint.sh

[warning] 62-62: Declare and assign separately to avoid masking return values. (SC2155)


[warning] 66-66: Declare and assign separately to avoid masking return values. (SC2155)


[warning] 70-70: Declare and assign separately to avoid masking return values. (SC2155)


[warning] 74-74: Declare and assign separately to avoid masking return values. (SC2155)


[warning] 86-86: ShellCheck can't follow non-constant source. Use a directive to specify location. (SC1090)

@sharat87 sharat87 requested a review from mohanarpit June 12, 2024 11:10
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c6ce2a8 and 1f05722.

Files selected for processing (1)
  • deploy/docker/fs/opt/appsmith/utils/bin/index.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • deploy/docker/fs/opt/appsmith/utils/bin/index.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working ok-to-test Required label for CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants