fix: DB URL override fails in some cases (#34206)
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** <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/9481037167> > Commit: c6ce2a8dda4a13d3aab64adf8c9af08abd1cea62 > Cypress dashboard url: <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9481037167&attempt=1" target="_blank">Click here!</a> <!-- end of auto-generated comment: Cypress test results -->
This commit is contained in:
parent
6e5f3069f2
commit
981e720f77
|
|
@ -45,6 +45,11 @@ init_env_file() {
|
|||
ENV_PATH="$CONF_PATH/docker.env"
|
||||
TEMPLATES_PATH="/opt/appsmith/templates"
|
||||
|
||||
if [[ -n "$APPSMITH_MONGODB_URI" ]]; then
|
||||
export APPSMITH_DB_URL="$APPSMITH_MONGODB_URI"
|
||||
unset APPSMITH_MONGODB_URI
|
||||
fi
|
||||
|
||||
# Build an env file with current env variables. We single-quote the values, as well as escaping any single-quote characters.
|
||||
printenv | grep -E '^APPSMITH_|^MONGO_' | sed "s/'/'\\\''/g; s/=/='/; s/$/'/" > "$TMP/pre-define.env"
|
||||
|
||||
|
|
@ -75,8 +80,19 @@ init_env_file() {
|
|||
|
||||
|
||||
tlog "Load environment configuration"
|
||||
|
||||
# Load the ones in `docker.env` in the stacks folder.
|
||||
set -o allexport
|
||||
. "$ENV_PATH"
|
||||
set +o allexport
|
||||
|
||||
if [[ -n "$APPSMITH_MONGODB_URI" ]]; then
|
||||
export APPSMITH_DB_URL="$APPSMITH_MONGODB_URI"
|
||||
unset APPSMITH_MONGODB_URI
|
||||
fi
|
||||
|
||||
# Load the ones set from outside, should take precedence, and so will overwrite anything from `docker.env` above.
|
||||
set -o allexport
|
||||
. "$TMP/pre-define.env"
|
||||
set +o allexport
|
||||
}
|
||||
|
|
@ -172,11 +188,6 @@ configure_database_connection_url() {
|
|||
tlog "Configuring database connection URL"
|
||||
isPostgresUrl=0
|
||||
isMongoUrl=0
|
||||
# Check if APPSMITH_DB_URL is not set
|
||||
if [[ -z "${APPSMITH_DB_URL}" ]]; then
|
||||
# If APPSMITH_DB_URL is not set, fall back to APPSMITH_MONGODB_URI
|
||||
export APPSMITH_DB_URL="${APPSMITH_MONGODB_URI}"
|
||||
fi
|
||||
|
||||
if [[ "${APPSMITH_DB_URL}" == "postgresql:"* ]]; then
|
||||
isPostgresUrl=1
|
||||
|
|
|
|||
|
|
@ -10,12 +10,19 @@ const mongo_shell_utils = require("./mongo_shell_utils.js");
|
|||
|
||||
const APPLICATION_CONFIG_PATH = "/appsmith-stacks/configuration/docker.env";
|
||||
|
||||
// Loading latest application configuration
|
||||
require("dotenv").config({ path: APPLICATION_CONFIG_PATH });
|
||||
|
||||
// Check if APPSMITH_DB_URL is set, if not set, fall back to APPSMITH_MONGODB_URI
|
||||
if (!process.env.APPSMITH_DB_URL) {
|
||||
process.env.APPSMITH_DB_URL = process.env.APPSMITH_MONGODB_URI;
|
||||
delete process.env.APPSMITH_MONGODB_URI;
|
||||
}
|
||||
|
||||
// Loading latest application configuration
|
||||
require("dotenv").config({ path: APPLICATION_CONFIG_PATH });
|
||||
|
||||
// AGAIN: Check if APPSMITH_DB_URL is set, if not set, fall back to APPSMITH_MONGODB_URI
|
||||
if (!process.env.APPSMITH_DB_URL) {
|
||||
process.env.APPSMITH_DB_URL = process.env.APPSMITH_MONGODB_URI;
|
||||
delete process.env.APPSMITH_MONGODB_URI;
|
||||
}
|
||||
|
||||
const command = process.argv[2];
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user