@@ -5,14 +5,77 @@ set -o pipefail
55
66set -x # Turn on command tracing
77
8- SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
8+ # these are the default values of the emulator container.
9+ DEFAULT_COSMOS_ENDPOINT=" https://localhost:8081"
910
10- # Depending on the OS, we need to use a different command to start the emulator.
11- if [ " $( uname) " == " Darwin" ]; then
12- " ${SCRIPT_DIR} /start-cosmos-emulator-osx.sh"
13- elif [ " $( uname) " == " Linux" ]; then
14- " ${SCRIPT_DIR} /start-cosmos-emulator-linux.sh"
11+ echo " Starting Cosmos DB emulator..."
12+
13+ # Generate random container name
14+ CONTAINER_NAME=" local-cosmos-emulator-$( shuf -i 1000-9999 -n 1) "
15+
16+ # Choose container runtime (prefer podman, fallback to docker)
17+ CONTAINER_RUNTIME=" "
18+ if command -v podman > /dev/null 2>&1 ; then
19+ CONTAINER_RUNTIME=" podman"
20+ elif command -v docker > /dev/null 2>&1 ; then
21+ CONTAINER_RUNTIME=" docker"
1522else
16- echo " Unsupported OS "
23+ echo " Error: Neither podman nor docker found. Please install one of them. "
1724 exit 1
18- fi
25+ fi
26+
27+ echo " Using container runtime: ${CONTAINER_RUNTIME} "
28+
29+ # Stop any existing emulator first
30+ if ${CONTAINER_RUNTIME} ps -q --filter " name=local-cosmos-emulator-*" | grep -q . ; then
31+ echo " Found existing Cosmos DB emulator containers, stopping them..."
32+ ${CONTAINER_RUNTIME} ps -q --filter " name=local-cosmos-emulator-*" | xargs -r ${CONTAINER_RUNTIME} stop
33+ ${CONTAINER_RUNTIME} ps -aq --filter " name=local-cosmos-emulator-*" | xargs -r ${CONTAINER_RUNTIME} rm
34+ fi
35+
36+ echo " Starting Cosmos DB emulator with container name: ${CONTAINER_NAME} "
37+ ${CONTAINER_RUNTIME} run \
38+ --publish 8081:8081 \
39+ --publish 10250-10255:10250-10255 \
40+ -e AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=127.0.0.1 \
41+ --name " ${CONTAINER_NAME} " \
42+ --detach \
43+ mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest
44+
45+ # Wait for emulator to be ready by checking logs
46+ echo " Waiting for Cosmos DB emulator to be ready..."
47+ for i in {1..60}; do
48+ if ${CONTAINER_RUNTIME} logs " ${CONTAINER_NAME} " 2>&1 | grep -q " Started 11/11 partitions" ; then
49+ echo " Cosmos DB emulator is ready!"
50+ break
51+ fi
52+ if [ " $i " -eq 60 ]; then
53+ echo " Timeout waiting for Cosmos DB emulator to be ready"
54+ exit 1
55+ fi
56+ echo " Attempt $i /60: Waiting for emulator to start all partitions..."
57+ sleep 5
58+ done
59+
60+ netstat -anlp
61+
62+ # Wait for HTTPS endpoint to be available
63+ echo " Waiting for HTTPS endpoint to be available..."
64+ for i in {1..30}; do
65+ if curl --insecure -s " ${DEFAULT_COSMOS_ENDPOINT} /_explorer/emulator.pem" > /dev/null 2>&1 ; then
66+ echo " HTTPS endpoint is ready!"
67+ break
68+ fi
69+ if [ " $i " -eq 30 ]; then
70+ echo " Timeout waiting for HTTPS endpoint to be available, will continue and try anyway."
71+ break
72+ fi
73+ echo " Attempt $i /30: Waiting for HTTPS endpoint..."
74+ sleep 2
75+ done
76+
77+ echo " ✅ Cosmos DB emulator started successfully!"
78+ echo " Container name: ${CONTAINER_NAME} "
79+ echo " Endpoint: ${DEFAULT_COSMOS_ENDPOINT} "
80+ echo " "
81+ echo " To stop all Cosmos emulators, run: ./frontend/hack/stop-all-cosmos-emulators.sh"
0 commit comments