YetaWF Documentation


Blue/Green Deployment

Blue/Green deployment is a technique that can be used with private hosting and many other cloud hosting providers. While your current production site is active and running, you start up a second instance before switching over to the new instance. IIS can be used with a simple proxy that redirects traffic to the new instance. Or tools like nginx can be used to route the traffic.

IIS Proxy

First off, a proxy is defined that accepts all traffic for http://yoursite.com:80 and https://yoursite.com:443.

The proxy doesn't execute any YetaWF code. It merely redirects traffic using the following web.config example:

<?xml version="1.0" encoding="UTF-8"?>
        <rule name="www" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="HTTP_HOST" pattern="^www\.(.*)" />
          <action type="Redirect" url="https://yoursite.com/R:0" />
        <rule name="Redirect to HTTPS" stopProcessing="true">
          <match url="(.*)" />
            <add input="HTTPS" pattern="^OFF$" />
          <action type="Redirect" url="https://HTTP_HOST/R:1" redirectType="SeeOther" />
        <rule name="ReverseProxyInboundRule1" stopProcessing="true">
          <match url="(.*)" />
          <action type="Rewrite" url="https://HTTP_HOST:5001/R:1" />
            <set name="X-Forwarded-For" value="REMOTE_ADDR" />

This sample web.config is very close to what you would use for your site. Of course, you need to change yoursite.com to your actual site name. You also need to change the port number, 5001 in this example, to the port number you want to use for your site. You'll need to reserve two ports for your site (One "blue" and one "green").

This example also includes support to redirect all traffic for www.yoursite.com to yoursite.com (rule "www"). And it also redirects traffic for http://yoursite.com to https://yoursite.com (rule "Redirect to HTTPS"). You may want to keep this as https is preferred. If you need a free certificate for your site, take a look at letsencrypt.org.

The only rule you really need is the rule named "ReverseProxyInboundRule1" in this example. It redirects all traffic for your site to the site of the same name at port 5001. It also includes the X-Forwarded-For header so the receiving blue/green site can respond correctly. This header includes the IP address of the request, which can be used by the receiving site. When the blue/green site renders a page, all the links refer to the real site name (not port 5001 or whatever you chose). In the Site Settings you would still define port 80/443 as the ports used, even though your blue/green site uses another port (5001 in this example).

Once a new site is deployed you just need to replace the web.config in your proxy with a new port number in the rule named "ReverseProxyInboundRule1". The proxy restarts automatically and all traffic is redirected to your new site.

YetaWF includes sample proxy web-BLUE.config and web-GREEN.config in the root folder of the solution. You'll need to update the site name and port numbers.

IIS Blue/Green Sites

In addition to the proxy site, you would define two sites in IIS, yoursite-BLUE and yoursite-GREEN with bindings for yoursite:5001 and yoursite:5002 (or whatever ports you're really using). If your proxy redirects all traffic to https://yoursite.com:5001 you only need to including bindings for https and port 5001. http is not used.

This means you have to site folders. You deploy YetaWF to the appropriate folder as usual. You don't need to change any settings in the deployed site (no need to adjust for ports, etc.).

The CopySite utility used for deployment can assist with Blue/Green deployment as it accepts a command line parameter to deploy either Blue or Green.

.\Softelvdm.CopySite.exe" Backup ".\CopySite FROM DEV BLUEGREEN.txt" [Blue|Green]

Instead of using the provided .bat files .\Utilities\CopySite\CopySite FROM DEV.bat and CopySite TO PROD.bat you would use .\Utilities\CopySite\CopySite FROM DEV BLUE.bat and CopySite TO PROD BLUE.bat (or GREEN depending on deployment).

The files defining the actions are named CopySite FROM DEV BLUEGREEN.txt and CopySite TO PROD BLUEGREEN.txt. These need to be updated as documented in Private Hosting. When deploying Blue/Green, the text {BLUEGREEN} and {-BLUEGREEN} in these text files is replaced with the current site deployment (Blue or Green).

These sample files also show how to stop IIS apppools and how to update the health check files.