Search code examples
asp.netdockerjenkinsamazon-ecs

Web.Config transforms for Multi-Tenant deployment of WebForms app in docker over AWS ECS


Environment

  • ASP.NET WebForms app over IIS
  • Docker container host
  • AWS ECS hosting platform
  • Each client hosting its own copy of the app with private database connection string

Background

In the non-docker environment, each copy is a virtual directory under IIS, and thus have their own individual web.config pointing to dedicated databases. The underlying codebase is the same for each client, with no client-specific customization involved. The route becomes / here.

In the docker environment (one container per client), each copy goes over as a central root application.

Challange

Since the root image is going to be the same, how to have the web.config overridden for each client deployment.

We shouldn't create multiple images (one per client) as that will mean having extra deployment jobs and losing out on centralization. The connection strings should ideally be stored in some kind of dictionary storage applicable at ECS level which can provide client-specific values upon loading of corresponding containers.


Solution

  • Presenting the approach we used to solve this issue. Hope it may help others struck in similar cases.

    With the problem statement tied to having a single root image and having any customization being applied at runtime, we knew that there needs to be a transformation of web.config at time of loading of the corresponding containers.

    The solution was to use a PowerShell script that will read the web.config and get replace the specific values which were having a custom prefix embedded to the key. The values got passed from custom environmental variables within ECS and the web.config also got updated to have the keys with the prefix added.

    Now since the docker container can have only a single entry point, a new base image was created which instantiated an IIS server and called a PowerShell script as startup. The called script called this transformation script and then set the ServiceMonitor on the w3cwp.

    Thanks a lot for this article https://anthonychu.ca/post/overriding-web-config-settings-environment-variables-containerized-aspnet-apps/