开发者

How to speed up Azure deployment from Visual Studio 2010

开发者 https://www.devze.com 2023-01-31 13:12 出处:网络
I have Visual Studio 2010 solution with an Azure Service and an ASP.NET MVC 3 solution that serves as a Web Role for the Azure service. No other roles attached to the service other than that.

I have Visual Studio 2010 solution with an Azure Service and an ASP.NET MVC 3 solution that serves as a Web Role for the Azure service. No other roles attached to the service other than that.

Every deployment to the Azure staging (or production, for that matter) environment takes up to 20 minutes to complete, form the moment I click publish on Visual Studio until all instances (2) are started.

As you can imagine this makes it a PITA to publish often, or to开发者_如何转开发 quick-fix some bugs. Is there a way to speed the process up? Would it be faster to upload the package to de Blob storage and upgrade from there? How would I go about achieving that?

I feel on-line docs on Azure leave a lot to be desired. Particularly when it comes to troubleshooting by the way.

Thanks.


One idea for reducing the need (and frequency) for redeploying is to move static content into blob storage, external to the package. For instance, move your css and javascript to blob storage, along with images. Once this is done, you'd only have to recompile / redeploy for .NET code changes. You can upload updated css, at any time, to blob storage. If you want to test this in staging first, you could always have a staging vs. production container name for your static content and store that container name in a config setting.

This doesn't change the deployment time when you do need to redeploy, but at least you can reduce how often you go through that process...


You should enable Web Deploy in your Azure project. It works this way :

1/ Create a RDP account (don't forget, you need to upload a certificate with its private key so that Azure can decipher the password). That is hidden in the Deploy Dialog Box for your Azure deployment project.

2/ Enable Web Deployment - same place

Once you've published the app that way, right-click in the web application (not the azure deployment project) and select Publish. The pop-up has everything defined except the password, enter that as well and you'll upload your changes to Azure in a matter of seconds.

CAVEAT : this is meant for single-instance web apps, definitely not the way to go for a production upgrade strategy, and the Blob storage answer already mentioned is the best option in that case.

Pierre


My solution to this problem is only to push a new package when I am changing code in the RoleEntryPoint or with the Service Definition. In Azure 1.3 you now have the ability to use Remote Desktop Connection. Using RDC, I will compile my code locally and use copy/paste to place it on the Azure server in the appropriate directory. Once the production code is running correctly, I can then push the fully tested version to staging and then do a VIP swap. This limits the number of times I actually have to deploy a package.

You actually have quite a long window in which you can keep modifying your code in Azure before you have to publish a new package. The new package is only really needed for those cases where Azure has to shutdown/restart your role instance.


It's a nice idea to try uploading your project to blob storage first, but unfortunately this is what Visual Studio is doing for you behind the scene anyway. As has been pointed out elsewhere, most of the time in doing the deploy is not the upload itself, but the stopping and starting of all of your update domains.

If you're just running this site in a development environment, then the only way I know to speed it up is to run just one instance. If this is the live environment, then... sorry, I think you're out of luck.

So that I don't have to deploy to the cloud to test minor changes, what I've found works quite well is to engineer the site so that it works when running in local IIS just like any other MVC site.

The biggest barrier to this working are settings that you have in the cloud config. The way we get around this is to make a copy of all of the settings in your cloud config and put them in your web.config in the appSettings. Then rather than using RoleEnvironment.GetConfigurationSettingValue() create a wrapper class that you call instead. This wrapper class checks RoleEnvironment.IsAvailable to see if it is running in the Azure fabric, if it is, it calls the usual config function above, if not, it calls WebConfigurationManager.AppSettings[].

There are a few other things that you'll want to do around getting the config setting change events which hopefully you can figure out from the code below:

public class SmartConfigurationManager
{
    private static bool _addConfigChangeEvents;
    private static string _configName;

    private static Func<string, bool> _configSetter;

    public static bool AddConfigChangeEvents
    {
        get { return _addConfigChangeEvents; }
        set
        {
            _addConfigChangeEvents = value;

            if (value)
            {
                RoleEnvironment.Changing += RoleEnvironmentChanging;
            }
            else
            {
                RoleEnvironment.Changing -= RoleEnvironmentChanging;
            }
        }
    }

    public static string Setting(string configName)
    {
        if (RoleEnvironment.IsAvailable)
        {
            return RoleEnvironment.GetConfigurationSettingValue(configName);
        }
        return WebConfigurationManager.AppSettings[configName];
    }

    public static Action<string, Func<string, bool>> GetConfigurationSettingPublisher()
    {
        if (RoleEnvironment.IsAvailable)
        {
            return AzureSettingsGet;
        }
        return WebAppSettingsGet;
    }

    public static void WebAppSettingsGet(string configName, Func<string, bool> configSetter)
    {
        configSetter(WebConfigurationManager.AppSettings[configName]);
    }

    public static void AzureSettingsGet(string configName, Func<string, bool> configSetter)
    {
        // We have to store these to be used in the RoleEnvironment Changed handler
        _configName = configName;
        _configSetter = configSetter;

        // Provide the configSetter with the initial value
        configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));

        if (AddConfigChangeEvents)
        {
            RoleEnvironment.Changed += RoleEnvironmentChanged;
        }
    }


    private static void RoleEnvironmentChanged(object anotherSender, RoleEnvironmentChangedEventArgs arg)
    {

        if ((arg.Changes.OfType<RoleEnvironmentConfigurationSettingChange>().Any(change => change.ConfigurationSettingName == _configName)))
        {
            if ((_configSetter(RoleEnvironment.GetConfigurationSettingValue(_configName))))
            {
                RoleEnvironment.RequestRecycle();
            }
        }
    }


    private static void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
    {
        // If a configuration setting is changing
        if ((e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange)))
        {
            // Set e.Cancel to true to restart this role instance
            e.Cancel = true;
        }
    }
}


The uploading itself takes a bit more than a minute most of the time. It's the starting up of the instances that take up most of the time.

What you can do is to deploy your fixes to staging first (note that it costs money so don't let it be there for too long). Swapping from staging to production only takes a couple of seconds. So while your application's still running you can upload the patched version, let your testers test it on staging and when they give the go then simply swap it to production.

I haven't tested your possible alternative approach by first uploading to blob storage first. But I think that's overhead as it doesn't speed up starting up the instances.

0

精彩评论

暂无评论...
验证码 换一张
取 消