Search code examples
asp.net-core.net-6.0abp-framework

How do you deploy ABP.IO application template projects?


I have some tiered ABP.IO application template project deployment questions - but they may be ASP.NET Core deployment questions.

Background

I'm a bit confused as to whether I need to create appsettings.Production.json files to mirror the appsettings.json files in my class library projects (MyProduct.Application, MyProduct.Application.Contracts, etc.) AND my four ASP.NET projects (MyProduct.HttpApi.Host, MyProduct.IdentityServer, MyProduct.Web, and MyProduct.Web.Public) OR whether I just need to create them for ONLY the four ASP.NET projects and make sure that the settings that are in the class library projects are represented in the ones for the ASP.NET projects.

Questions

  1. Should I create appsettings.Production.json files in my class library/DLL projects?
  2. If yes to 1, will the launchSettings.json file be the right place to ensure that the libraries are built with the production configuration?
  3. If yes to 2, are there any considerations when deploying to production? I know I need to use an environment variable on the server.
  4. If no to 1 or 2, how do I build my libraries to use the production configuration?
  5. Is it possible to replace the client secrets wherever they may appear? It would seem like it would be necessary but there's no help on this in the documentation. Are there any considerations toward doing this? Is a simple search and replace of all the default secrets sufficient or are there code changes necessary?
  6. Is it possible to replace all references to localhost with the FQDN of the respective site (Host/API, IdentityServer, Web, Web.Public)? The application template would require this, correct? I am doing an IIS deployment currently - not a Docker or Kubernetes deployment.
  7. What else am I missing?

Thanks for taking the time to comment. If you have a resource to share with me, please do. I cannot find a deployment guide or checklist on the ABP Framework site, ABP Commercial site, Community Forum, or Discord channel.

UPDATE

I have been through these two resources and I am a lot more educated about configuration in ASP.NET Core but I still cannot find the answer to my question about configuring class libraries in production. 1 - https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-6.0 2 - https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-6.0

FINAL UPDATE

Eventually I just had to figure things out but Omer's answers make a lot of sense in hindsight.

My solution was to add the appsettings.Production.json files to each of the deployable projects as suggested below. You can read Omer's answer for details. I pretty much did everything that Omer suggested but I had not thought about the one shot seeding of the Identity Server database tables. That was truly helpful. My final hurdle was figuring out a way to perform DB Migrations on my local DB instance and my remote servers with just a click.

Through various posts, I eventually figured out that I could use the Launch Profile editor buried under the Debug section of the DbMigrator project properties, to create myself two Launch Profiles. I have one for local development and one for production - although through this mechanism, I don't see why you couldn't create one for each part of your staging pipeline.

It should be noted that I deleted the default profile which was named using the project name/namespace.

Here is the Launch Profile editor screen for the Development profile:

Development profile

And here is the Launch Profile editor screen for the Production profile:

Production profile

Of primary importance is the ASPNETCORE_ENVIRONMENT=Development environment variable in development and the ASPNETCORE_ENVIRONMENT=Production environment variable in production.

Exiting the editor produces the Properties folder and the contained launchSettings.json file.

launchSettings.json file

You could create this folder and file yourself without going through the editor. Here is the text of that file:

{
  "profiles": {
    "EnvironmentConfiguration.Cli (Development)": {
      "commandName": "Project",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "EnvironmentConfiguration.Cli (Production)": {
      "commandName": "Project",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Production"
      }
    }
  }
}

Now when I want to run a schema migration, I can simply select the DbMigrator project as the startup project...

Startup Project Selection

...and I will have two launch profiles in my debug menu:

Profile Selection

Does anyone know of a better way?


Solution

  • I am using ABP with Blazor Wasm and IdentityServer is not seperated. So I am publishing only .Host and .Blazor projects.

    1. No, you only need them for published projects (.Host, .Web, .Blazor etc)

    Should I create appsettings.Production.json files in my class library/DLL projects?

    1. Libraries are not standalone projects. They are used by other projects (By .Host project or they can be used by another library project) So, they will take these configuration settings from live application (.Host, .Web, .Blazor etc)

    If no to 1 or 2, how do I build my libraries to use the production configuration?

    1. These keys are using by IdentityServer and I think they are seeded to Database on initial migration. If you want to change them, you need to change them from appsettings.json files and change value in database also. By the way, it is encrypted and you need to change value in DB with new encrypted value. (https://support.abp.io/QA/Questions/441/About-changing-client-secrets)

    Is it possible to replace the client secrets wherever they may appear? It would seem like it would be necessary but there's no help on this in the documentation. Are there any considerations toward doing this? Is a simple search and replace of all the default secrets sufficient or are there code changes necessary?

    1. Change "localhost" values to your FQDN in all appsettings.json files. Also there should be some changes in database for IdentityServer. Because in the initial migration, it is written on DB.
      [dbo].[IdentityServerClientCorsOrigins].[Origin]
      [dbo].[IdentityServerClientPostLogoutRedirectUris].[PostLogoutRedirectUri] [dbo].[IdentityServerClientRedirectUris].[RedirectUri]

    Is it possible to replace all references to localhost with the FQDN of the respective site (Host/API, IdentityServer, Web, Web.Public)? The application template would require this, correct? I am doing an IIS deployment currently - not a Docker or Kubernetes deployment.

    1. Do not forget to install SSL. If you are using Cloudflare disable SSL from Cloudflare (If you have also in server) Because it may conflict.
      Another important thing is to remove Webdav if you are using IIS. Because Webdav occurs error for put request. (https://stackoverflow.com/a/59235862/2178028)
      Also, I dont know why but for the first publish of Blazor projects, it gives 403 error for .dll files in ISS. Then I follow this link (https://www.eugenechiang.com/2021/12/12/failed-to-find-a-valid-digest-in-the-integrity-attribute-for-resource-in-blazor-app/) and problem is solved.

    What else am I missing?