Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion scripts/deploy_preview.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ kubectl get pods

# Optional cleanup logic
if [[ -n "${RECREATE-}" ]]; then
mongosh "mongodb+srv://$DB_USERNAME:$DB_PASSWORD@$DB_URL/$DBNAME?retryWrites=true&minPoolSize=1&maxPoolSize=10&maxIdleTimeMS=900000&authSource=admin" --eval 'db.dropDatabase()'
echo "Wiping the DP from MongoDB and Kubernetes since the reset flag was set"
pod_name="$(kubectl get pods -n "$NAMESPACE" -o json | jq -r '.items[0].metadata.name')"
# execute this db.dropDatabase() from the k8s cluster because there's network restrictions on Atlas cluster.
# The \$ is used to escape the $ character in the APPSMITH_DB_URL environment variable so it's interpolated inside the kubectl exec command.
kubectl exec "$pod_name" -n "$NAMESPACE" -- bash -c "mongosh \$APPSMITH_DB_URL --eval 'db.dropDatabase()'"
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

Quote the DB URL before passing it to mongosh.
APPSMITH_DB_URL contains multiple & query parameters. When bash -c expands the current string, those & characters background the preceding command and treat the remainder (minPoolSize=...) as separate shell commands, so mongosh never executes with the full URL and the drop fails. Wrap the variable in quotes inside the remote command.

-  kubectl exec "$pod_name" -n "$NAMESPACE" -- bash -c "mongosh \$APPSMITH_DB_URL --eval 'db.dropDatabase()'"
+  kubectl exec "$pod_name" -n "$NAMESPACE" -- bash -c "mongosh \"\$APPSMITH_DB_URL\" --eval 'db.dropDatabase()'"
🤖 Prompt for AI Agents
In scripts/deploy_preview.sh around line 56, the kubectl exec remote command
passes $APPSMITH_DB_URL unquoted so embedded & characters break the shell; fix
by ensuring the DB URL is quoted inside the remote bash -c string so the entire
URL is delivered as a single argument to mongosh (i.e., wrap the variable in
double quotes inside the inner command and escape those quotes so the remote
shell sees them), leaving the rest of the command unchanged.

kubectl exec "$pod_name" -n "$NAMESPACE" -- bash -c "rm -rf /appsmith-stacks/*"
kubectl delete ns "$NAMESPACE" || true
kubectl patch pv "$NAMESPACE-appsmith" -p '{"metadata":{"finalizers":null}}' || true
kubectl delete pv "$NAMESPACE-appsmith" --grace-period=0 --force || true
echo "DP wiped from MongoDB and Kubernetes"
fi

# Create namespace and image pull secret
Expand Down