Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using Dapper;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
Expand All @@ -18,18 +19,17 @@
var stopwatch = Stopwatch.StartNew();
stopwatch.Start();

await using var dataSource = new YdbDataSource(
new YdbConnectionStringBuilder(connectionString)
{
CredentialsProvider = new MetadataProvider(loggerFactory: loggerFactory),
LoggerFactory = loggerFactory,
DisableDiscovery = true
}
);
await using var ydbDataSource = new YdbDataSource(new YdbConnectionStringBuilder(connectionString)
{
CredentialsProvider = new MetadataProvider(loggerFactory: loggerFactory),
LoggerFactory = loggerFactory,
DisableDiscovery = true,
EnableImplicitSession = true
});

await using var ydbCommand = dataSource.CreateCommand();
ydbCommand.CommandText = "SELECT 'Hello Serverless YDB from Yandex Cloud Serverless Container!'u";
var scalar = await ydbCommand.ExecuteScalarAsync();
await using var ydbConnection = await ydbDataSource.OpenRetryableConnectionAsync();
var scalar = await ydbConnection.ExecuteScalarAsync<string>(
"SELECT 'Hello Serverless YDB from Yandex Cloud Serverless Container!'u");
stopwatch.Stop();

logger.LogInformation("Success request! [Ms: {Ms}], {Select}", stopwatch.ElapsedMilliseconds, scalar);
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,32 @@ to [Yandex Cloud Serverless Containers](https://yandex.cloud/en/docs/serverless-
## Getting started

1. **Setup** [Yandex Container Registry](https://yandex.cloud/en/docs/container-registry/operations/registry/registry-create).
2. **Build and Push Docker Image**
2. **Configure YDB Connection String**. Update the `appsettings.json` file with your YDB connection details:
```json
{
"ConnectionStrings": {
"ServerlessYDB": "UseTls=true;Host=<your-ydb-host>;Port=2135;Database=<your-database-path>"
}
}
```
Replace `<your-ydb-host>` with your YDB endpoint host and `<your-database-path>` with your database path (e.g., `/ru-central1/b1g8ejbxxxxxxxx/etn8xxxxxxxx`).
3. **Build and Push Docker Image**
```bash
docker build . -t cr.yandex/<container-registry-id>/ado-net-app:latest
docker push cr.yandex/<container-registry-id>/ado-net-app:latest
```
Replace <container-registry-id> with your actual Container Registry ID.
3. **Grant Required Permissions**. To enable your Serverless Container to access both YDB and your container image in
4. **Grant Required Permissions**. To enable your Serverless Container to access both YDB and your container image in
the Container Registry, grant the following roles to your Service Account:

- `ydb.editor` — access to YDB,
- `container-registry.images.puller` — permission to pull images from Container Registry.

4. **Create a new revision**. After pushing your image, create a new version of the Serverless Container as described in
5. **Create a new revision**. After pushing your image, create a new version of the Serverless Container as described in
the [official guide](https://yandex.cloud/en/docs/serverless-containers/quickstart/container#create-revision).
Specify your image and the necessary environment variables and secrets.

5. **Running the Yandex Serverless Container**.
6. **Running the Yandex Serverless Container**.
After the new revision has been rolled out, you can use your container (e.g., for a health check) by executing the
following command:
```bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0"/>
<PackageReference Include="NLog.Extensions.Logging" Version="5.5.0"/>
<PackageReference Include="Ydb.Sdk.Yc.Auth" Version="0.2.0"/>
<PackageReference Include="Ydb.Sdk" Version="0.18.0"/>
<PackageReference Include="Ydb.Sdk" Version="0.24.0"/>
<PackageReference Include="Dapper" Version="2.1.35"/>

<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
Loading