3
votes

Here is the scenario: - Too many web sites with the same source code and own database (Each customer has its own system with his own database, but all customers utilizes the same source code)

  • I have only one TFS Project because all customers use the same code (not physically because I have to deploy to each customer at each website)

The Question: How can I deploy to one website (from VS 2012 - Web Deploy) and it automatically updates all the other websites, changing correctly the web.config (currently, each deployment setting has its configuration to change the web.config connectionString).

TO Simplify, currently, I have all the deployment settings (Customer1 - WEb Deploy, Customer2 - Web Deploy....) It works, but I have to deploy to each single customer... What I want to do is, make a loop to deploy to all Customers by clicking just once)..

1
We used the Octopus project for such tasks.VMAtm
See also this questionVMAtm

1 Answers

3
votes

We do a very similar process, using the same code base for some 50+ sites. We use the Azure REST Management API to accomplish the deployments. I'd recommend moving the site specific settings from web.config to individual ServiceConfiguration..cscfg files and then using CloudConfigurationManager.GetSetting("settingsKey") to get the config value. Create a simple list of keys, probably domain based to access att your settings.

There is a great code sample from the Azure team on using the Management API here. We adapted this for our code base to create a console app and call that console app during a TFS build process. Here's the relevant code we use to get a list of hosted services in a subscription and then updated each hosted service deployment:

            var packageUrl = UploadFileToBlob(package);
            var services = new ListHostedServicesCommand();
            services.Run();
            hostedServices = services.HostedServices;

            var date = DateTime.UtcNow.ToString("yyyyMMdd-hhmmss-");
            var label = date + "some-deployment-name";
            var fileinfo = new FileInfo(config);

            if (!string.IsNullOrEmpty(packageUrl) && fileinfo.Exists)
            {
                // get the url of the package uploaded to blob
                AzureCommand.PackageLocation = packageUrl;
                AzureCommand.ConfigFileLocation = fileinfo.FullName;
                AzureCommand.DeploymentSlot = "production";
                AzureCommand.Mode = "auto";
                AzureCommand.Label = label;

                foreach (var hostedService in hostedServices)
                {
                    Console.WriteLine("updating: " + hostedService.ServiceName);
                    // get the deployment unique name - required for upgrade
                    AzureCommand.HostedServiceName = hostedService.ServiceName;
                    AzureCommand.DeploymentName = null;
                    var getDeployment = new GetDeploymentCommand();
                    getDeployment.Run();
                    AzureCommand.DeploymentName = getDeployment.Deployment.Name;

                    // upgrade the existing deployment    
                    var upgradeDeployment = new UpgradeDeploymentCommand();
                    upgradeDeployment.Run();
                    servicesOperations.Add(upgradeDeployment.TrackingId, upgradeDeployment.ServiceManagement);
                }

                // check status of all operations submitted
                foreach (var servicesOperation in servicesOperations)
                {
                    // check status of operations
                    AzureCommand.WaitForAsyncOperation(servicesOperation.Value, servicesOperation.Key);
                }
            }