ASP.NET Core sample app illustrating how to use Entity Framework Core together with Steeltoe PostgreSQL Connector for connecting to a PostgreSQL service on CloudFoundry.
There is also an additional sample that illustrates how to use a NpgsqlConnection
to issue commands to the bound database.
- Installed .NET Core SDK
- Started PostgreSQL docker container
- Installed CloudFoundry (optionally with Windows support)
- Installed VMware Tanzu Cloud Service Broker
You must first create an instance of the PostgreSQL service in an org/space.
cf target -o your-org -s your-space
cf create-service csb-azure-postgresql small myPostgreSqlService
orcf create-service csb-google-postgres default myPostgreSqlService
cf target -o your-org -s your-space
cd samples/Connectors/src/PostgreSqlEFCore
- Push the app
- When using Windows containers:
- Publish app to a local directory, specifying the runtime:
dotnet restore --configfile nuget.config
dotnet publish -r win-x64 --self-contained
- Push the app using the appropriate manifest:
cf push -f manifest-windows.yml -p bin/Debug/net6.0/win-x64/publish
- Publish app to a local directory, specifying the runtime:
- Otherwise:
- Push the app using the appropriate manifest:
cf push -f manifest.yml
- Push the app using the appropriate manifest:
- When using Windows containers:
Note: The provided manifest(s) will create an app named
postgresqlefcore-connector
and attempt to bind the app to PostgreSQL servicemyPostgreSqlService
.
To see the logs as you startup and use the app: cf logs postgresqlefcore-connector
On a Windows cell, you should see something like this during startup:
2016-08-05T07:23:02.15-0600 [CELL/0] OUT Creating container
2016-08-05T07:23:03.81-0600 [CELL/0] OUT Successfully created container
2016-08-05T07:23:09.07-0600 [APP/0] OUT Running .\PostgreSqlEFCore
2016-08-05T07:23:14.68-0600 [APP/0] OUT Hosting environment: development
2016-08-05T07:23:14.68-0600 [APP/0] OUT Content root path: C:\containerizer\75E10B9301D2D9B4A8\user\app
2016-08-05T07:23:14.68-0600 [APP/0] OUT Application started. Press Ctrl+C to shut down.
2016-08-05T07:23:14.68-0600 [APP/0] OUT Now listening on: http://*:51217
This sample will be available at http://postgresqlefcore-connector.[your-cf-apps-domain]/.
Upon startup, the app inserts a couple of rows into the bound PostgreSQL database. They are displayed on the home page.
Pre-requisites:
- Kubernetes with Tanzu Application Platform installed
- Postgres services are set up for consumption by developers
Yaml files for creating the needed resources are included with this project, and their usage is specified below, but you are encouraged to review and/or customize the contents of the files before applying them.
- Create a Postgres Service Instance
- For complete instructions, follow the documentation
- For a simplified experience, use the yaml included with this project:
kubectl apply -f ./config/service-operator/postgres.yaml
- Create a Postgres Service Binding/Claim
- For complete instructions, follow the documentation
- For a simplified experience, use the yaml included with this project:
kubectl apply -f ./config/app-operator/postgres-resource-claim.yaml
- Optional: specify a resource claim policy (for using resources across namespaces):
kubectl apply -f ./config/app-operator/postgres-resource-claim-policy.yaml
cd samples/Connectors/src/PostgreSqlEFCore
- Optional: If you created your service or bindings without using the included yaml, modify the
serviceClaims
section of the includedworkload.yaml
with claim details to match what you created. - Publish app to a local directory, specifying the runtime:
dotnet restore --configfile nuget.config
dotnet publish -r linux-x64 --no-self-contained
- Push the app to TAP:
tanzu app workload apply --local-path ./bin/Debug/net6.0/linux-x64/publish --source-image <registry-reference> -f ./config/workload.yaml -y
- See the Tanzu Apps CLI documentation for details.