【问题标题】:Windows Azure multiple deploymentWindows Azure 多重部署
【发布时间】:2013-03-10 16:36:01
【问题描述】:

这是场景: - 太多的网站使用相同的源代码和自己的数据库(每个客户都有自己的系统和自己的数据库,但所有客户都使用相同的源代码)

  • 我只有一个 TFS 项目,因为所有客户都使用相同的代码(不是物理上的,因为我必须在每个网站上部署到每个客户)

问题:我如何部署到一个网站(来自 VS 2012 - Web Deploy),它会自动更新所有其他网站,正确更改 web.config(目前,每个部署设置都有其配置来更改 web.config)。配置连接字符串)。

为了简化,目前,我拥有所有部署设置(Customer1 - WEB Deploy,Customer2 - Web Deploy....) 它有效,但我必须部署到每个客户...... 我想要做的是,只需单击一次即可循环部署到所有客户)..

【问题讨论】:

标签: .net deployment azure visual-studio-2012


【解决方案1】:

我们执行一个非常相似的过程,为大约 50 多个站点使用相同的代码库。我们使用Azure REST Management API 来完成部署。我建议将站点特定设置从 web.config 移动到单独的 ServiceConfiguration..cscfg 文件,然后使用 CloudConfigurationManager.GetSetting("settingsKey") 获取配置值。创建一个简单的密钥列表,可能基于域以访问您的设置。

Azure 团队提供了一个关于使用 Management API here 的出色代码示例。我们针对我们的代码库进行了调整,以创建一个控制台应用程序并在 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);
                }
            }

【讨论】:

  • 我得到了我想要的方式。我将所有网站链接到 TFS 帐户,并定义了我想要的构建定义...所以每当我签入解决方案时,它都会自动更新网站.. 我还可以安排构建.. 太棒了!
  • 干得好!你能分享一下构建定义的任何细节吗?
  • 它很简单,实际上...我将我的网站链接到同一个 TFS 帐户,默认情况下它会签入并在每次签入时更新网站.. 但是如果你去构建定义,你可以将每个网站设置为具有不同的定义,例如设置为每周一更新网站...有很多选项,请在 TFS -> Builds -> Build Definition 上查看
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-31
  • 2012-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多