create aspnet api with postgresql
This version added a compose application using: * ASP.Net API Core * EntityFramework Core * Postgresql Signed-off-by: Eduardo Silva <eduardo.lour.silva@gmail.com>
This commit is contained in:
		
				
					committed by
					
						 Eduardo Silva
						Eduardo Silva
					
				
			
			
				
	
			
			
			
						parent
						
							bc95525543
						
					
				
				
					commit
					4eef6ec88c
				
			| @@ -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 | ## 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 | - [`ASP.NET / MS-SQL`](https://github.com/docker/awesome-compose/tree/master/aspnet-mssql) - Sample ASP.NET core application | ||||||
| with MS SQL server database. | 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. | - [`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 | - [`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. | with an Nginx proxy and a MySQL database. | ||||||
|   | |||||||
							
								
								
									
										285
									
								
								aspnet-api-postgresql/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										285
									
								
								aspnet-api-postgresql/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -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 | ||||||
							
								
								
									
										62
									
								
								aspnet-api-postgresql/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								aspnet-api-postgresql/README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -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. | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | Stop and remove the containers | ||||||
|  |  | ||||||
|  | ``` | ||||||
|  | $ docker-compose down | ||||||
|  | ``` | ||||||
							
								
								
									
										284
									
								
								aspnet-api-postgresql/api/.dockerignore
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										284
									
								
								aspnet-api-postgresql/api/.dockerignore
									
									
									
									
									
										Normal file
									
								
							| @@ -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/ | ||||||
| @@ -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<HealthCheckController> _logger; | ||||||
|  |     private readonly ApplicationDbContext _dbContext; | ||||||
|  |  | ||||||
|  |     public HealthCheckController(ApplicationDbContext dbContext, ILogger<HealthCheckController> 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"; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,11 @@ | |||||||
|  | using Microsoft.EntityFrameworkCore; | ||||||
|  |  | ||||||
|  | namespace aspnet_api_postgresql.Infrastructure.Database; | ||||||
|  | public class ApplicationDbContext : DbContext | ||||||
|  | { | ||||||
|  |     public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) | ||||||
|  |         : base(options) | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -0,0 +1,28 @@ | |||||||
|  | // <auto-generated /> | ||||||
|  | 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 | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -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) | ||||||
|  |         { | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,26 @@ | |||||||
|  | // <auto-generated /> | ||||||
|  | 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 | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										49
									
								
								aspnet-api-postgresql/api/Program.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								aspnet-api-postgresql/api/Program.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -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<ApplicationDbContext>(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<ApplicationDbContext>(); | ||||||
|  |         db.Database.Migrate(); | ||||||
|  |     } | ||||||
|  |     app.UseSwagger(); | ||||||
|  |     app.UseSwaggerUI(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | app.UseHttpsRedirection(); | ||||||
|  |  | ||||||
|  | app.UseAuthorization(); | ||||||
|  |  | ||||||
|  | app.MapControllers(); | ||||||
|  |  | ||||||
|  | app.Run(); | ||||||
							
								
								
									
										31
									
								
								aspnet-api-postgresql/api/Properties/launchSettings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								aspnet-api-postgresql/api/Properties/launchSettings.json
									
									
									
									
									
										Normal file
									
								
							| @@ -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" | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										8
									
								
								aspnet-api-postgresql/api/appsettings.Development.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								aspnet-api-postgresql/api/appsettings.Development.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | { | ||||||
|  |   "Logging": { | ||||||
|  |     "LogLevel": { | ||||||
|  |       "Default": "Information", | ||||||
|  |       "Microsoft.AspNetCore": "Warning" | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										12
									
								
								aspnet-api-postgresql/api/appsettings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								aspnet-api-postgresql/api/appsettings.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | { | ||||||
|  |   "Logging": { | ||||||
|  |     "LogLevel": { | ||||||
|  |       "Default": "Information", | ||||||
|  |       "Microsoft.AspNetCore": "Warning" | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  |   "AllowedHosts": "*", | ||||||
|  |   "ConnectionStrings": { | ||||||
|  |     "DefaultConnection": "Host=db;Username=postgres;Password=postgres;Database=aspnetapipostgresqldb" | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										26
									
								
								aspnet-api-postgresql/api/aspnet-api-postgresql.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								aspnet-api-postgresql/api/aspnet-api-postgresql.csproj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | <Project Sdk="Microsoft.NET.Sdk.Web"> | ||||||
|  |  | ||||||
|  |   <PropertyGroup> | ||||||
|  |     <TargetFramework>net6.0</TargetFramework> | ||||||
|  |     <Nullable>enable</Nullable> | ||||||
|  |     <ImplicitUsings>enable</ImplicitUsings> | ||||||
|  |     <RootNamespace>aspnet_api_postgresql</RootNamespace> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup> | ||||||
|  |     <GenerateDocumentationFile>true</GenerateDocumentationFile> | ||||||
|  |     <NoWarn>$(NoWarn);1591</NoWarn> | ||||||
|  |   </PropertyGroup> | ||||||
|  |  | ||||||
|  |   <ItemGroup> | ||||||
|  |     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> | ||||||
|  |     <PackageReference Include="EFCore.NamingConventions" Version="6.0.0" /> | ||||||
|  |     <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1"> | ||||||
|  |       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||||||
|  |       <PrivateAssets>all</PrivateAssets> | ||||||
|  |     </PackageReference> | ||||||
|  |     <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.2" /> | ||||||
|  |  | ||||||
|  |  | ||||||
|  |   </ItemGroup> | ||||||
|  |  | ||||||
|  | </Project> | ||||||
							
								
								
									
										22
									
								
								aspnet-api-postgresql/aspnet-api-postgresql.sln
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								aspnet-api-postgresql/aspnet-api-postgresql.sln
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||||
							
								
								
									
										28
									
								
								aspnet-api-postgresql/docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								aspnet-api-postgresql/docker-compose.yml
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||||
							
								
								
									
										
											BIN
										
									
								
								aspnet-api-postgresql/output.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								aspnet-api-postgresql/output.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 44 KiB | 
		Reference in New Issue
	
	Block a user