diff --git a/README.md b/README.md index 4627833..b81b98c 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ These samples provide a starting point for how to integrate different services u ## Samples of Docker Compose applications with multiple integrated services - [`ASP.NET / MS-SQL`](https://github.com/docker/awesome-compose/tree/master/aspnet-mssql) - Sample ASP.NET core application with MS SQL server database. +- [`ASP.NET / Postgresql`](https://github.com/docker/awesome-compose/tree/master/aspnet-api-postgresql) - Sample ASP.NET core application +with Postgresql server database. - [`Elasticsearch / Logstash / Kibana`](https://github.com/docker/awesome-compose/tree/master/elasticsearch-logstash-kibana) - Sample Elasticsearch, Logstash, and Kibana stack. - [`Go / NGINX / MySQL`](https://github.com/docker/awesome-compose/tree/master/nginx-golang-mysql) - Sample Go application with an Nginx proxy and a MySQL database. diff --git a/aspnet-api-postgresql/.gitignore b/aspnet-api-postgresql/.gitignore new file mode 100644 index 0000000..1f3754d --- /dev/null +++ b/aspnet-api-postgresql/.gitignore @@ -0,0 +1,285 @@ + +# Created by https://www.gitignore.io/api/csharp + +### Csharp ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ +Properties/launchSettings.json + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/ +tools/Cake.CoreCLR +.vscode +tools +.dotnet + +# .env file contains default environment variables for docker +.env + +.DS_Store \ No newline at end of file diff --git a/aspnet-api-postgresql/README.md b/aspnet-api-postgresql/README.md new file mode 100644 index 0000000..ddb8685 --- /dev/null +++ b/aspnet-api-postgresql/README.md @@ -0,0 +1,62 @@ +## Compose sample application: ASP.Net API with Postgresql database + +Project Structure +``` +. +├── api +│ ├── appsettings.json +│ ├── ... +└── docker-compose.yaml +``` +[_docker-compose.yaml](docker-compose.yml) + +``` +services: + api: + image: mcr.microsoft.com/dotnet/sdk + container_name: "api" + ports: + - 5000:5000 + ... + db: + image: postgres:10.5 + restart: always + ... +``` + +The compose file defines an application with two services `api` and `db`. The api service is configured without a Dockerfile and to run using your local volume in `watch` mode. + +## Deploy with docker-compose + +``` +$ docker-compose up -d +Pulling db (postgres:10.5)... +10.5: Pulling from library/postgres +... +Status: Downloaded newer image for postgres:10.5 +Pulling api (mcr.microsoft.com/dotnet/sdk:)... +latest: Pulling from dotnet/sdk +... +Status: Downloaded newer image for mcr.microsoft.com/dotnet/sdk:latest +Creating aspnet-api-postgresql_db_1 ... done +Creating api ... done +``` + +## Expected result + +``` +$ docker ps +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +48c8a8911cfb mcr.microsoft.com/dotnet/sdk "dotnet watch run --…" About a minute ago Up About a minute 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp api +84082957734e postgres:10.5 "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp aspnet-api-postgresql_db_1 +``` + +After the application starts, navigate to http://localhost:5000/swagger/index.html in your web browser. + +![page](output.png) + +Stop and remove the containers + +``` +$ docker-compose down +``` \ No newline at end of file diff --git a/aspnet-api-postgresql/api/.dockerignore b/aspnet-api-postgresql/api/.dockerignore new file mode 100644 index 0000000..084da0b --- /dev/null +++ b/aspnet-api-postgresql/api/.dockerignore @@ -0,0 +1,284 @@ +# Created by https://www.gitignore.io/api/csharp + +### Csharp ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ +Properties/launchSettings.json + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/ +tools/Cake.CoreCLR +.vscode +tools +.dotnet +Dockerfile + +# .env file contains default environment variables for docker +.env +.git/ \ No newline at end of file diff --git a/aspnet-api-postgresql/api/Controllers/HealthCheckController.cs b/aspnet-api-postgresql/api/Controllers/HealthCheckController.cs new file mode 100644 index 0000000..8eefc8a --- /dev/null +++ b/aspnet-api-postgresql/api/Controllers/HealthCheckController.cs @@ -0,0 +1,36 @@ +using aspnet_api_postgresql.Infrastructure.Database; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace aspnet_api_postgresql.Controllers; + +[ApiController] +[Route("[controller]")] +public class HealthCheckController : ControllerBase +{ + private readonly ILogger _logger; + private readonly ApplicationDbContext _dbContext; + + public HealthCheckController(ApplicationDbContext dbContext, ILogger logger) + { + _logger = logger; + _dbContext = dbContext; + } + + [HttpGet] + public string Ping() + { + try + { + _dbContext.Database.OpenConnection(); + _dbContext.Database.ExecuteSqlRaw("SELECT 1"); + _dbContext.Database.CloseConnection(); + return "OK"; + } + catch (Exception ex) + { + _logger.LogError(ex, "Error connecting to database"); + return "Error connecting to database"; + } + } +} diff --git a/aspnet-api-postgresql/api/Infrastructure/ApplicationDbContext.cs b/aspnet-api-postgresql/api/Infrastructure/ApplicationDbContext.cs new file mode 100644 index 0000000..2a8e9f5 --- /dev/null +++ b/aspnet-api-postgresql/api/Infrastructure/ApplicationDbContext.cs @@ -0,0 +1,11 @@ +using Microsoft.EntityFrameworkCore; + +namespace aspnet_api_postgresql.Infrastructure.Database; +public class ApplicationDbContext : DbContext +{ + public ApplicationDbContext(DbContextOptions options) + : base(options) + { + } + +} \ No newline at end of file diff --git a/aspnet-api-postgresql/api/Infrastructure/Database/Migrations/20220411183355_InititalCreation.Designer.cs b/aspnet-api-postgresql/api/Infrastructure/Database/Migrations/20220411183355_InititalCreation.Designer.cs new file mode 100644 index 0000000..04a53b6 --- /dev/null +++ b/aspnet-api-postgresql/api/Infrastructure/Database/Migrations/20220411183355_InititalCreation.Designer.cs @@ -0,0 +1,28 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using aspnet_api_postgresql.Infrastructure.Database; + +#nullable disable + +namespace aspnet_api_postgresql.Infrastructure.Database.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220411183355_InititalCreation")] + partial class InititalCreation + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); +#pragma warning restore 612, 618 + } + } +} diff --git a/aspnet-api-postgresql/api/Infrastructure/Database/Migrations/20220411183355_InititalCreation.cs b/aspnet-api-postgresql/api/Infrastructure/Database/Migrations/20220411183355_InititalCreation.cs new file mode 100644 index 0000000..c265d42 --- /dev/null +++ b/aspnet-api-postgresql/api/Infrastructure/Database/Migrations/20220411183355_InititalCreation.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace aspnet_api_postgresql.Infrastructure.Database.Migrations +{ + public partial class InititalCreation : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/aspnet-api-postgresql/api/Infrastructure/Database/Migrations/ApplicationDbContextModelSnapshot.cs b/aspnet-api-postgresql/api/Infrastructure/Database/Migrations/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 0000000..249398a --- /dev/null +++ b/aspnet-api-postgresql/api/Infrastructure/Database/Migrations/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,26 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using aspnet_api_postgresql.Infrastructure.Database; + +#nullable disable + +namespace aspnet_api_postgresql.Infrastructure.Database.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); +#pragma warning restore 612, 618 + } + } +} diff --git a/aspnet-api-postgresql/api/Program.cs b/aspnet-api-postgresql/api/Program.cs new file mode 100644 index 0000000..f12a5a8 --- /dev/null +++ b/aspnet-api-postgresql/api/Program.cs @@ -0,0 +1,49 @@ +using System.Reflection; +using aspnet_api_postgresql.Infrastructure.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.OpenApi.Models; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddDbContext(options => + options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")) + .UseSnakeCaseNamingConvention()); + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(_ => +{ + _.SwaggerDoc("v1", new OpenApiInfo + { + Version = "v1", + Title = "ASP.NET Core Web API", + }); + + var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + _.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); + +}); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + using (var scope = app.Services.CreateScope()) + { + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.Migrate(); + } + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/aspnet-api-postgresql/api/Properties/launchSettings.json b/aspnet-api-postgresql/api/Properties/launchSettings.json new file mode 100644 index 0000000..b69d0c9 --- /dev/null +++ b/aspnet-api-postgresql/api/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:47446", + "sslPort": 44370 + } + }, + "profiles": { + "aspnet_api_postgresql": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7234;http://localhost:5260", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/aspnet-api-postgresql/api/appsettings.Development.json b/aspnet-api-postgresql/api/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/aspnet-api-postgresql/api/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/aspnet-api-postgresql/api/appsettings.json b/aspnet-api-postgresql/api/appsettings.json new file mode 100644 index 0000000..2aa172f --- /dev/null +++ b/aspnet-api-postgresql/api/appsettings.json @@ -0,0 +1,12 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "ConnectionStrings": { + "DefaultConnection": "Host=db;Username=postgres;Password=postgres;Database=aspnetapipostgresqldb" + } +} \ No newline at end of file diff --git a/aspnet-api-postgresql/api/aspnet-api-postgresql.csproj b/aspnet-api-postgresql/api/aspnet-api-postgresql.csproj new file mode 100644 index 0000000..9511ce4 --- /dev/null +++ b/aspnet-api-postgresql/api/aspnet-api-postgresql.csproj @@ -0,0 +1,26 @@ + + + + net6.0 + enable + enable + aspnet_api_postgresql + + + true + $(NoWarn);1591 + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + diff --git a/aspnet-api-postgresql/aspnet-api-postgresql.sln b/aspnet-api-postgresql/aspnet-api-postgresql.sln new file mode 100644 index 0000000..34b5309 --- /dev/null +++ b/aspnet-api-postgresql/aspnet-api-postgresql.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "aspnet-api-postgresql", "api\aspnet-api-postgresql.csproj", "{8260F100-34F4-4DC3-B6A5-FCF28A4DBEC4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8260F100-34F4-4DC3-B6A5-FCF28A4DBEC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8260F100-34F4-4DC3-B6A5-FCF28A4DBEC4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8260F100-34F4-4DC3-B6A5-FCF28A4DBEC4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8260F100-34F4-4DC3-B6A5-FCF28A4DBEC4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/aspnet-api-postgresql/docker-compose.yml b/aspnet-api-postgresql/docker-compose.yml new file mode 100644 index 0000000..38e60eb --- /dev/null +++ b/aspnet-api-postgresql/docker-compose.yml @@ -0,0 +1,28 @@ +version: '3.7' +services: + api: + image: mcr.microsoft.com/dotnet/sdk + container_name: "api" + ports: + - 5000:5000 + working_dir: /api + volumes: + - ./api:/api + command: ["dotnet", "watch", "run", "--urls=http://0.0.0.0:5000/"] + depends_on: + - "db" + db: + image: postgres:10.5 + restart: always + environment: + POSTGRES_USER: "postgres" + POSTGRES_PASSWORD: "postgres" + POSTGRES_DB: "aspnetapipostgresqldb" + logging: + options: + max-size: 10m + max-file: "3" + ports: + - '5432:5432' + volumes: + - ./postgres-data:/var/lib/postgresql/data \ No newline at end of file diff --git a/aspnet-api-postgresql/output.png b/aspnet-api-postgresql/output.png new file mode 100644 index 0000000..1f660dc Binary files /dev/null and b/aspnet-api-postgresql/output.png differ