Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on:
branches:
- main
- develop
- copilot/add-github-actions-for-docker
- ershov/deploy-test
tags:
- 'v*'

Expand Down
30 changes: 27 additions & 3 deletions Meethub/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c => { c.OperationFilter<AddTelegramHeadersOperationFilter>(); });
builder.Services.AddNpgsql<DatabaseContext>(
builder.Configuration.GetConnectionString("DefaultConnection"),

var connectionString = GetConnectionString(builder.Configuration);
builder.Services.AddNpgsql<DatabaseContext>(connectionString,
optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(DatabaseContext).Assembly.FullName));

// builder.Services.AddNpgsql<DatabaseContext>(
// builder.Configuration.GetConnectionString("DefaultConnection"),
// optionsBuilder => optionsBuilder.MigrationsAssembly(typeof(DatabaseContext).Assembly.FullName));
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = BotApiKeyAuthenticationHandler.SchemeName;
Expand Down Expand Up @@ -82,4 +87,23 @@
app.UseMiddleware<TelegramUserMiddleware>();
app.UseAuthorization();
app.MapControllers().RequireAuthorization();
app.Run();
app.Run();

static string GetConnectionString(IConfiguration configuration)
{
var host = Environment.GetEnvironmentVariable("POSTGRES_HOST");
var database = Environment.GetEnvironmentVariable("POSTGRES_DB");
var user = Environment.GetEnvironmentVariable("POSTGRES_USER");
var password = Environment.GetEnvironmentVariable("POSTGRES_PASSWORD");

// If all environment variables are present, use them (production/serverless)
if (!string.IsNullOrEmpty(host) && !string.IsNullOrEmpty(database) &&
!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(password))
{
return $"Server={host};Database={database};User Id={user};Password={password};";
}

// Fall back to appsettings.json for local development
return configuration.GetConnectionString("DefaultConnection")
?? throw new InvalidOperationException("Database connection string not configured");
}
2 changes: 1 addition & 1 deletion build/_build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[GitHubActions(
"docker-build-push",
GitHubActionsImage.UbuntuLatest,
OnPushBranches = ["main", "develop", "copilot/add-github-actions-for-docker"],
OnPushBranches = ["main", "develop", "ershov/deploy-test"],
OnPushTags = ["v*"],
InvokedTargets = [nameof(PushDockerImage)],
ImportSecrets = ["YC_REGISTRY_ID", "YC_SERVICE_ACCOUNT_KEY"],
Expand Down
Loading