Stage of production or production?

Are there any services in the runtime that will tell me if I'm currently working on "Staging" or "Production"? Manually reconfiguring in and out of production seems a bit cumbersome.

+44
azure azure-cloud-services
Dec 01 '10 at 19:53
source share
6 answers

You really should not change your configurations when you are based on if you are in Prod or Staging. The staging area is not intended for the QA environment, but only the storage area before deployment.

When you download a new deployment, the current deployment slot into which you download your package is destroyed and ends for 10-15 minutes when the virtual machine boots and starts. If you load directly into production, this is 15 minutes of production downtime. Thus, the setting area was created: you load into the stage, check the material and click the "swap" button, and your setting environment magically becomes a production (virtual IP exchange). Thus, your production should be really 100% the same as your production.

What I think you are looking for is a QA / test environment? You must open a new service for the testing environment using your own Prod / Staging. In this case, you will need to support several sets of configuration files, one for each deployment environment (Production, Testing, etc.).

There are many ways to manage the hell configuration, especially with Azure, which has its own * .cscfg files on top of .config files. The way I prefer to do this with an Azure project is as follows: Set up a small Config project, create folders there that match the deployment types. Inside each folder, * .config and * .cscfg files are installed that correspond to the specific deployment environment: Debug, Test, Release ... they are also configured in Visual Studio, as well as target types. I have a small xcopy command that occurs during each compig of the Config project, which copies all the files from the Create Target folder of the Config project to the root folder of the Config project.

Then, every other project in the solution is associated with a .config or .cscfg file from the Config project root folder.

Voila, my configs magically adapt to each build configuration automatically. I also use .config transformations to manage debugging information for Release and non-Release purposes.

If you read all this and still want to get Production vs. Staging at runtime , then: Get the deploymentId from RoleEnvironment.DeploymentId Then use the management API with the correct X509 certificate to get the Azure structure of your Service value and call the GetDeployments method (it remains api, but there is an abstraction library).

Hope this helps

Edit: blog post asking for customization of configuration lines and switching between environments @ http://www.paraleap.com/blog/post/Managing-environments-in-a-distributed-Azure-or-other-cloud-based- NET-solution.aspx

+74
Dec 02 2018-10-12T00:
source share

Sometimes I want people to just answer a question .. donโ€™t explain ethics or best practices ...

Microsoft has posted sample code that does just that here: https://code.msdn.microsoft.com/windowsazure/CSAzureDeploymentSlot-1ce0e3b5

image showing Staging instance

image showing Production instance

 protected void Page_Load(object sender, EventArgs e) { // You basic information of the Deployment of Azure application. string deploymentId = RoleEnvironment.DeploymentId; string subscriptionID = "<Your subscription ID>"; string thrumbnail = "<Your certificate thumbnail print>"; string hostedServiceName = "<Your hosted service name>"; string productionString = string.Format( "https://management.core.windows.net/{0}/services/hostedservices/{1}/deploymentslots/{2}", subscriptionID, hostedServiceName, "Production"); Uri requestUri = new Uri(productionString); // Add client certificate. X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine); store.Open(OpenFlags.OpenExistingOnly); X509Certificate2Collection collection = store.Certificates.Find( X509FindType.FindByThumbprint, thrumbnail, false); store.Close(); if (collection.Count != 0) { X509Certificate2 certificate = collection[0]; HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(requestUri); httpRequest.ClientCertificates.Add(certificate); httpRequest.Headers.Add("x-ms-version", "2011-10-01"); httpRequest.KeepAlive = false; HttpWebResponse httpResponse = httpRequest.GetResponse() as HttpWebResponse; // Get response stream from Management API. Stream stream = httpResponse.GetResponseStream(); string result = string.Empty; using (StreamReader reader = new StreamReader(stream)) { result = reader.ReadToEnd(); } if (result == null || result.Trim() == string.Empty) { return; } XDocument document = XDocument.Parse(result); string serverID = string.Empty; var list = from item in document.Descendants(XName.Get("PrivateID", "http://schemas.microsoft.com/windowsazure")) select item; serverID = list.First().Value; Response.Write("Check Production: "); Response.Write("DeploymentID : " + deploymentId + " ServerID :" + serverID); if (deploymentId.Equals(serverID)) lbStatus.Text = "Production"; else { // If the application not in Production slot, try to check Staging slot. string stagingString = string.Format( "https://management.core.windows.net/{0}/services/hostedservices/{1}/deploymentslots/{2}", subscriptionID, hostedServiceName, "Staging"); Uri stagingUri = new Uri(stagingString); httpRequest = (HttpWebRequest)HttpWebRequest.Create(stagingUri); httpRequest.ClientCertificates.Add(certificate); httpRequest.Headers.Add("x-ms-version", "2011-10-01"); httpRequest.KeepAlive = false; httpResponse = httpRequest.GetResponse() as HttpWebResponse; stream = httpResponse.GetResponseStream(); result = string.Empty; using (StreamReader reader = new StreamReader(stream)) { result = reader.ReadToEnd(); } if (result == null || result.Trim() == string.Empty) { return; } document = XDocument.Parse(result); serverID = string.Empty; list = from item in document.Descendants(XName.Get("PrivateID", "http://schemas.microsoft.com/windowsazure")) select item; serverID = list.First().Value; Response.Write(" Check Staging:"); Response.Write(" DeploymentID : " + deploymentId + " ServerID :" + serverID); if (deploymentId.Equals(serverID)) { lbStatus.Text = "Staging"; } else { lbStatus.Text = "Do not find this id"; } } httpResponse.Close(); stream.Close(); } } 
+44
Oct 29 '14 at 18:26
source share

Staging is a temporary deployment slot used primarily for updates without downtime and the ability to roll back updates.

It is recommended not to associate your system (either in code or in the config) with such Azure features.

+8
Dec 02 '10 at 6:53
source share

Since the Windows Azure Management Libraries and thanks @GuaravMantri answer to another question, you can do it like this:

 using System; using System.Linq; using System.Security.Cryptography.X509Certificates; using Microsoft.Azure; using Microsoft.WindowsAzure.Management.Compute; using Microsoft.WindowsAzure.Management.Compute.Models; namespace Configuration { public class DeploymentSlotTypeHelper { static string subscriptionId = "<subscription-id>"; static string managementCertContents = "<Base64 Encoded Management Certificate String from Publish Setting File>";// copy-paste it static string cloudServiceName = "<your cloud service name>"; // lowercase static string ns = "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"; public DeploymentSlot GetSlotType() { var managementCertificate = new X509Certificate2(Convert.FromBase64String(managementCertContents)); var credentials = new CertificateCloudCredentials(subscriptionId, managementCertificate); var computeManagementClient = new ComputeManagementClient(credentials); var response = computeManagementClient.HostedServices.GetDetailed(cloudServiceName); return response.Deployments.FirstOrDefault(d => d.DeploymentSlot == DeploymentSlot.Production) == null ? DeploymentSlot.Staging : DeploymentSlot.Production; } } } 
+4
Jun 29 '15 at 11:51
source share

An easy way to solve this problem is to install a key in your instances to determine the environment in which it is running.

1) Install in your working slot: Install it Settings โ†’ Application Settings โ†’ Application Settings And create a key called SLOT_NAME and evaluate "production". IMPORTANT: check the slot setting.

2) Install in your intermediate slot: Install it Settings โ†’ Application settings โ†’ Application settings And create a key with the name SLOT_NAME and evaluate the "stage". IMPORTANT: check the slot setting.

Access from your application to a variable and determine the environment in which the application runs. In Java, you can access:

 String slotName = System.getenv("APPSETTING_SLOT_NAME"); 
+2
Mar 03 '16 at
source share

Here are 4 points to consider.

  • VIP swap only makes sense when your service is facing the outside world. AKA when it provides an API and responds to requests.
  • If your service really removes messages from the queue and processes them, your services are active, and a VIP exchange is not a good solution for you.
  • If your service is reactive and proactive, you can review your design. It is possible to split the service into two different services.
  • Ericโ€™s suggestion to modify the cscfg pre and post-VIP files is good if the proactive part of your service can take a short downtime (since you first set up both Staging and Production so that you donโ€™t get messages, then do VIP Swap and then update the production configuration to start pulling messages).
+1
Oct 24 '14 at 17:11
source share



All Articles