这是场景:
- 太多的网站具有相同的源代码和自己的数据库(每个客户都有自己的系统和自己的数据库,但所有客户都使用相同的源代码)
- 我只有一个 TFS 项目,因为所有客户都使用相同的代码(不是物理上的,因为我必须在每个网站上部署到每个客户)
问题:我如何部署到一个网站(来自 VS 2012 - Web Deploy)并自动更新所有其他网站,正确更改 web.config(目前,每个部署设置都有其配置来更改 web.config 连接字符串) 。
为了简化,目前,我拥有所有部署设置(Customer1 - WEb Deploy,Customer2 - Web Deploy...)
它有效,但我必须部署到每个客户......
我想做的是,通过单击一次创建一个循环来部署到所有客户)。
我们采用了非常相似的流程,对 50 多个网站使用相同的代码库。我们使用Azure REST 管理 API http://msdn.microsoft.com/en-us/library/windowsazure/ee460799来完成部署。我建议将站点特定设置从 web.config 移动到单独的 ServiceConfiguration..cscfg 文件,然后使用CloudConfigurationManager.GetSetting("settingsKey")
获取配置值。创建一个简单的密钥列表,可能基于域来访问您的设置。
Azure 团队提供了一个很棒的代码示例,介绍了如何使用管理API在这里 http://code.msdn.microsoft.com/windowsazure/Windows-Azure-CSManage-e3f1882c。我们针对我们的代码库进行了调整,以创建控制台应用程序并在 TFS 构建过程中调用该控制台应用程序。以下是我们用来获取订阅中托管服务列表,然后更新每个托管服务部署的相关代码:
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);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)