Reputation: 679
How to run Azure cosmos DB Emulator in Azure devops with spring boot Integration testing (java)?
Currently the cosmos DB emulator only supports Windows server not linux?
Any suggestion how to proceed here?
Update:1 For windows build agent, below task can be used which is from azure pipelines.
- task: CosmosDbEmulator@2
inputs:
containerName: 'azure-cosmosdb-emulator'
enableAPI: 'SQL'
portMapping: '8081:8081, 8901:8901, 8902:8902, 8979:8979, 10250:10250, 10251:10251, 10252:10252, 10253:10253, 10254:10254, 10255:10255, 10256:10256, 10350:10350'
hostDirectory: '$(Build.BinariesDirectory)\azure-cosmosdb-emulator'
For Linux: I am using the same as of @Ricardo
Upvotes: 1
Views: 1431
Reputation: 3475
I wrote a blog post about running Spring Boot apps' Integration Tests with Testcontainers and the Cosmos DB Docker emulator.
https://tech.asimio.net/2024/02/28/Cosmos-DB-Spring-Boot-2-Integration-Tests-Testcontainers.html
It also adds the Cosmos DB self-signed cert to a temp truststore the integration tests use, preventing the use of keytool to manually add the cert to a truststore.
It's a long blog post to place snippets and explanation here.
The code snippets might get you an idea to get started or finish yours.
It doesn't cover Azure Devops, but the tests run with a simple Maven command: mvn clean verify
Upvotes: 0
Reputation: 31
There is an attempt of CosmosDB emulator for linux: here
They provide commands to run it on a linux machine, we've just put them together in a bash step to be able to run it in our yaml pipelines:
*The sleep is there to give the emulator time to start inside the container
- bash: |
ipaddr="`ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}' | head -n 1`"
ifconfig | grep "inet " | grep -Fv 127.0.0.1
docker pull mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
docker run -p 8081:8081 -p 10251:10251 -p 10252:10252 -p 10253:10253 -p 10254:10254 -m 4g --cpus=2.0 --name=test-linux-emulator -e AZURE_COSMOS_EMULATOR_PARTITION_COUNT=10 -e AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=false -e AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=$ipaddr -d -it mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
sleep 30
curl -k https://localhost:8081/_explorer/emulator.pem > /tmp/emulatorcert.crt
keytool -cacerts -storepass changeit -noprompt -importcert -alias emulator_cert -file /tmp/emulatorcert.crt
displayName: Install CosmosDB Emulator Docker
Upvotes: 3