Skip to content

Commit 8863296

Browse files
Fix build on Linux
1 parent 1bff1cc commit 8863296

4 files changed

+16
-6
lines changed

install-azure-cosmos-emulator-linux-certificates.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#!/bin/bash
22

3+
ipaddr="`ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}' | head -n 1`"
4+
certfile=~/emulatorcert.crt
5+
echo "Certificate file: ${certfile}"
6+
37
result=1
48
count=0
59

610
while [[ "$result" != "0" && "$count" < "5" ]]; do
711
echo "Trying to download certificate ..."
8-
curl -k https://localhost:8081/_explorer/emulator.pem > ~/emulatorcert.crt 2> /dev/null
12+
curl -k https://$ipaddr:8081/_explorer/emulator.pem > $certfile
913
result=$?
1014
let "count++"
1115

@@ -19,8 +23,8 @@ done
1923
if [[ $result -eq 0 ]]
2024
then
2125
echo "Updating CA certificates ..."
22-
cp ~/emulatorcert.crt /usr/local/share/ca-certificates/
23-
update-ca-certificates
26+
sudo cp $certfile /usr/local/share/ca-certificates
27+
sudo update-ca-certificates
2428
else
2529
echo "Could not download CA certificate!"
2630
fi

run-docker-azure-cosmos-emulator-linux.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Determine the IP address of the local machine.
44
# This step is required when Direct mode setting is configured using Cosmos DB SDKs.
5-
# ipaddr="`ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}' | head -n 1`"
5+
ipaddr="`ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}' | head -n 1`"
66

77
# Pull the azure-cosmos-emulator Docker image for Linux from the registry.
88
docker pull mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
@@ -19,4 +19,5 @@ docker run \
1919
--name=azure-cosmos-emulator-linux \
2020
-e AZURE_COSMOS_EMULATOR_PARTITION_COUNT=3 \
2121
-e AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true \
22+
-e AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=$ipaddr \
2223
mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator

src/Examples/CosmosDbExample/Startup.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.AspNetCore.Authentication;
77
using Microsoft.AspNetCore.Builder;
88
using Microsoft.AspNetCore.Hosting;
9+
using Microsoft.Azure.Cosmos;
910
using Microsoft.EntityFrameworkCore;
1011
using Microsoft.Extensions.Configuration;
1112
using Microsoft.Extensions.DependencyInjection;
@@ -35,7 +36,11 @@ public void ConfigureServices(IServiceCollection services)
3536

3637
services.AddDbContext<AppDbContext>(options =>
3738
{
38-
options.UseCosmos(_connectionString, "TodoItemDB");
39+
options.UseCosmos(_connectionString, "TodoItemDB", builder =>
40+
{
41+
// Required for connection to Azure Cosmos Emulator Docker container on Linux.
42+
builder.ConnectionMode(ConnectionMode.Gateway);
43+
});
3944
#if DEBUG
4045
options.EnableSensitiveDataLogging();
4146
options.EnableDetailedErrors();

start-cosmos-db-emulator.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function StartCosmosDbEmulatorDockerContainer {
1919

2020
Write-Host "Installing Cosmos DB Emulator certificates ..."
2121
Start-Sleep -Seconds 30
22-
Start-Process nohup 'bash ./install-azure-cosmos-emulator-linux-certificates.sh'
22+
Start-Process -FilePath ".\install-azure-cosmos-emulator-linux-certificates.sh"
2323
}
2424

2525
function StartCosmosDbEmulatorForWindows {

0 commit comments

Comments
 (0)