-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Managed Identity support for connecting to Cosmos DB, Update dependencies with latest. #71
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Template scaled-object for using KEDA external scaler for Azure Cosmos DB. | ||
|
||
apiVersion: keda.sh/v1alpha1 | ||
kind: ScaledObject | ||
metadata: | ||
name: <scaledobject-name> | ||
namespace: default | ||
spec: | ||
pollingInterval: 20 | ||
scaleTargetRef: | ||
name: <application-deployment-name> | ||
triggers: | ||
- type: external | ||
metadata: | ||
scalerAddress: external-scaler-azure-cosmos-db.keda:4050 | ||
connection: <connection-string-of-monitored-container-account> | ||
databaseId: <database-id> | ||
containerId: <container-id> | ||
leaseConnection: <connection-string-of-lease-container-account> | ||
leaseDatabaseId: <lease-database-id> | ||
leaseContainerId: <lease-container-id> | ||
processorName: <processor-name> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
# https://hub.docker.com/_/microsoft-dotnet | ||
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. | ||
|
||
FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base | ||
WORKDIR /app | ||
|
||
# Restore, build and publish project. | ||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build | ||
WORKDIR / | ||
COPY src/Scaler.Demo/OrderGenerator/ src/Scaler.Demo/OrderGenerator/ | ||
COPY src/Scaler.Demo/Shared/ src/Scaler.Demo/Shared/ | ||
ARG BUILD_CONFIGURATION=Release | ||
WORKDIR /src | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should WORKDIR be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On second thought, the earlier Dockerfile was small and used to work. Can you minimize the changes to each Dockerfile, and keep it close to the original? |
||
COPY ["Scaler.Demo/OrderGenerator/Keda.CosmosDb.Scaler.Demo.OrderGenerator.csproj", "Scaler.Demo/OrderGenerator/"] | ||
COPY ["Scaler.Demo/Shared/Keda.CosmosDb.Scaler.Demo.Shared.csproj", "Scaler.Demo/Shared/"] | ||
RUN dotnet restore "./Scaler.Demo/OrderGenerator/Keda.CosmosDb.Scaler.Demo.OrderGenerator.csproj" | ||
COPY . . | ||
WORKDIR "/src/Scaler.Demo/OrderGenerator" | ||
RUN dotnet build "./Keda.CosmosDb.Scaler.Demo.OrderGenerator.csproj" -c $BUILD_CONFIGURATION -o /app/build | ||
|
||
WORKDIR /src/Scaler.Demo/OrderGenerator | ||
RUN dotnet publish --configuration Release --output /app | ||
FROM build AS publish | ||
ARG BUILD_CONFIGURATION=Release | ||
RUN dotnet publish "./Keda.CosmosDb.Scaler.Demo.OrderGenerator.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false | ||
|
||
# Stage application. | ||
FROM mcr.microsoft.com/dotnet/runtime:6.0 | ||
FROM base AS final | ||
WORKDIR /app | ||
COPY --from=build /app . | ||
ENTRYPOINT ["dotnet", "Keda.CosmosDb.Scaler.Demo.OrderGenerator.dll"] | ||
COPY --from=publish /app/publish . | ||
ENTRYPOINT ["dotnet", "Keda.CosmosDb.Scaler.Demo.OrderGenerator.dll"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Project Sdk="Microsoft.NET.Sdk;Microsoft.NET.Sdk.Publish"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||
<DockerfileContext>..\..</DockerfileContext> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Bogus" Version="34.0.2" /> | ||
<PackageReference Include="Bogus" Version="35.5.1" /> | ||
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.40.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Shared\Keda.CosmosDb.Scaler.Demo.Shared.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="appsettings.json" CopyToOutputDirectory="PreserveNewest" /> | ||
</ItemGroup> | ||
</Project> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"CosmosDbConfig": { | ||
"Connection": "<connection-string-of-monitored-container-account>", | ||
"Endpoint": "https://{Cosmos Account Name}.documents.azure.com:443/", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either keep just the 'Endpoint' config or make it clear that either one of the two properties are required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case of Order Generator, we are not deploying it on AKS. It just used locally to generate CosmosDB records and trigger the Change Feed, hence Order Generator is using connection string method to authenticate. |
||
"Connection": "<Delete this line if using managed identity to connect to Cosmos DB, else update with connection-string-of-monitored-container-account>", | ||
"DatabaseId": "StoreDatabase", | ||
"ContainerId": "OrderContainer", | ||
"ContainerThroughput": 11000 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
# https://hub.docker.com/_/microsoft-dotnet | ||
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. | ||
|
||
FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base | ||
WORKDIR /app | ||
|
||
# Restore, build and publish project. | ||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build | ||
WORKDIR / | ||
COPY src/Scaler.Demo/OrderProcessor/ src/Scaler.Demo/OrderProcessor/ | ||
COPY src/Scaler.Demo/Shared/ src/Scaler.Demo/Shared/ | ||
ARG BUILD_CONFIGURATION=Release | ||
WORKDIR /src | ||
COPY ["Scaler.Demo/OrderProcessor/Keda.CosmosDb.Scaler.Demo.OrderProcessor.csproj", "Scaler.Demo/OrderProcessor/"] | ||
COPY ["Scaler.Demo/Shared/Keda.CosmosDb.Scaler.Demo.Shared.csproj", "Scaler.Demo/Shared/"] | ||
RUN dotnet restore "./Scaler.Demo/OrderProcessor/Keda.CosmosDb.Scaler.Demo.OrderProcessor.csproj" | ||
COPY . . | ||
WORKDIR "/src/Scaler.Demo/OrderProcessor" | ||
RUN dotnet build "./Keda.CosmosDb.Scaler.Demo.OrderProcessor.csproj" -c $BUILD_CONFIGURATION -o /app/build | ||
|
||
WORKDIR /src/Scaler.Demo/OrderProcessor | ||
RUN dotnet publish --configuration Release --output /app | ||
FROM build AS publish | ||
ARG BUILD_CONFIGURATION=Release | ||
RUN dotnet publish "./Keda.CosmosDb.Scaler.Demo.OrderProcessor.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false | ||
|
||
# Stage application. | ||
FROM mcr.microsoft.com/dotnet/runtime:6.0 | ||
FROM base AS final | ||
WORKDIR /app | ||
COPY --from=build /app . | ||
ENTRYPOINT ["dotnet", "Keda.CosmosDb.Scaler.Demo.OrderProcessor.dll"] | ||
COPY --from=publish /app/publish . | ||
ENTRYPOINT ["dotnet", "Keda.CosmosDb.Scaler.Demo.OrderProcessor.dll"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,8 @@ | |
} | ||
}, | ||
"CosmosDbConfig": { | ||
"Connection": "<connection-string-of-monitored-container-account>", | ||
"DatabaseId": "StoreDatabase", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You only need it for local development. In AKS all config is passed via YAML. We use Endpoint in case of AAD and Connection in case of CS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We ensured that local development is possible, that we will stop supporting with the change. Please ensure that all demo steps for connection string-based demo and connection string-based scaler continue to work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want these settings in the appsettings.json of the docker images, if add these here the user will have to explicitly delete it before publishing. I can add it in appsettings.development.json. Does that work? |
||
"ContainerId": "OrderContainer", | ||
"LeaseConnection": "<connection-string-of-lease-container-account>", | ||
"LeaseDatabaseId": "StoreDatabase", | ||
"LeaseContainerId": "OrderProcessorLeases", | ||
"ProcessorName": "OrderProcessor" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Deploy order processor application. | ||
|
||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: cosmosdb-order-processor | ||
namespace: default | ||
spec: | ||
replicas: 1 # A replica is required to be up momentarily to initialize the change-feed. | ||
selector: | ||
matchLabels: | ||
app: cosmosdb-order-processor | ||
template: | ||
metadata: | ||
labels: | ||
app: cosmosdb-order-processor | ||
spec: | ||
containers: | ||
- name: cosmosdb-order-processor | ||
image: <docker-id>/cosmosdb-order-processor:latest | ||
imagePullPolicy: Always | ||
env: | ||
- name: CosmosDbConfig__Connection | ||
value: <connection-string-of-monitored-container> | ||
- name: CosmosDbConfig__LeaseConnection | ||
value: <connection-string-of-lease-container> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Create KEDA scaled object to scale order processor application. | ||
|
||
apiVersion: keda.sh/v1alpha1 | ||
kind: ScaledObject | ||
metadata: | ||
name: cosmosdb-order-processor-scaledobject | ||
namespace: default | ||
spec: | ||
pollingInterval: 20 | ||
scaleTargetRef: | ||
name: cosmosdb-order-processor | ||
triggers: | ||
- type: external | ||
metadata: | ||
scalerAddress: cosmosdb-scaler.default:4050 | ||
connection: <connection-string-of-monitored-container-account> | ||
databaseId: StoreDatabase | ||
containerId: OrderContainer | ||
leaseConnection: <connection-string-of-lease-container-account> | ||
leaseDatabaseId: StoreDatabase | ||
leaseContainerId: OrderProcessorLeases | ||
processorName: OrderProcessor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this Dockerfile generated using Visual Studio?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the original was not working. So, had to overwrite with VS generated Docker.