tag:help.appveyor.com,2012-11-13:/discussions/questions/3450-automatic-deployment-to-a-load-balanced-environmentAppVeyor: Discussion 2018-08-25T02:15:48Ztag:help.appveyor.com,2012-11-13:Comment/421464262017-03-13T18:15:12Z2017-03-13T18:15:17ZAutomatic deployment to a load balanced environment<div><p>Hi all,</p>
<p>I've got to configure an automatic deployment process for a load balanced web application and I'd like to validate my solution before actually implementing it. I have 3 servers and this is what I have to do for each one:</p>
<ul>
<li>Disconnect the server from the load balancer (before-deploy script)</li>
<li>Make the deployment</li>
<li>Check the deployment with a Selenium test (after-deploy script)</li>
<li>Connect the server to the load balancer again</li>
<li>Trigger a deployment to the next server</li>
</ul>
<p>My questions with this workflow are:</p>
<ul>
<li>How can I make a decision based on the results of a Selenium test?</li>
<li>How can I trigger the next deployment if everything was ok? I was thinking about using AppVeyor's API.</li>
<li>How can I make a rollback if any of the deployments fail?</li>
</ul>
<p>Cheers!</p></div>camtag:help.appveyor.com,2012-11-13:Comment/421464262017-03-14T03:33:54Z2017-03-14T03:33:54ZAutomatic deployment to a load balanced environment<div><p>Hello,</p>
<ul>
<li>I believe that if Selenium tests command failed, exit code will be other than 0. So you can check if last command failed according to <a href="https://blogs.msdn.microsoft.com/powershell/2006/09/15/errorlevel-equivalent/">this</a> doc.</li>
<li>You can trigger deployment with API, <a href="https://gist.github.com/IlyaFinkelshteyn/a79eb4bd6eb9c59f63e63b23e2713218">here</a> is an example. Note that you will be needed to store API token as a <a href="https://www.appveyor.com/docs/build-configuration/#secure-variables">secure variable</a> and pass it to Environment deployment.</li>
<li>We have not rollback functionality, but you can just redeploy last successful build.</li>
</ul>
<p>However I think that scenario with Selenium tests on every server is a little fragile. Maybe better do Selenium test only on AppVeyor VM, after the build. Here is some <a href="https://www.appveyor.com/docs/how-to/selenium-testing/">notes</a>. And as part of deployment script do only lightweight testing with <code>invoke-webrequest</code> command.</p>
<p>Thanks!<br>
Ilya.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/421464262017-03-14T12:06:32Z2017-03-14T12:06:32ZAutomatic deployment to a load balanced environment<div><p>Hi Ilya,</p>
<p>Thank you for your response, I'll have everything clearer now.</p>
<p>Cheers.</p></div>camtag:help.appveyor.com,2012-11-13:Comment/421464262017-03-14T17:51:05Z2017-03-14T17:51:05ZAutomatic deployment to a load balanced environment<div><p>Sure, please feel free to ping with any questions when implementing it.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/421464262017-03-16T12:18:11Z2017-03-16T12:18:11ZAutomatic deployment to a load balanced environment<div><p>Hi,</p>
<p>We have been doing very similar with AppVeyor for a number of months. I am having an issue whereby machines that go through the deployment process command though are being re-deployed, so for example:</p>
<ul>
<li>Machine 1 starts up, initialises and runs the deployment script which sends the deployment message to AppVeyor, the machine gets deployed.</li>
<li>Second machine comes up, runs through the same process and runs the deployment. As machine 1 is in the same group, it deploys to both machines.</li>
</ul>
<p>Is there a way to deploy to just the one machine?</p>
<p>Andrew.</p></div>andrewtag:help.appveyor.com,2012-11-13:Comment/421464262017-03-16T23:53:51Z2017-03-16T23:53:51ZAutomatic deployment to a load balanced environment<div><p><strong>@Andrew</strong> could you please provide more details about your environment? Are all servers use the same Environment access key? Is your application have multiple tiers (main reason to have a groups)? Also please check <a href="http://help.appveyor.com/discussions/questions/1496-more-details-on-deployment-groups">this post</a> if you did not do it already, to get good example of groups usage.</p>
<p>Thanks!<br>
Ilya.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/421464262017-03-17T09:05:09Z2017-03-17T09:05:09ZAutomatic deployment to a load balanced environment<div><p>Hi,</p>
<p>We have a single environment called production and in that environment I have several servers in different groups. There are multiple servers per groups (i.e, multiple front-end machines, multiple back-end machines etc. From the URL you posted, I don't think there is any way to target a specific server for deployment, and I would say this would be a really good feature to have for auto-scaling environments, as with the current solution if a tier autoscales, it causes a re-deployment to all servers in that environment.</p>
<p>Thanks.<br>
Andrew.</p></div>andrewtag:help.appveyor.com,2012-11-13:Comment/421464262017-03-17T13:42:58Z2017-03-17T13:42:58ZAutomatic deployment to a load balanced environment<div><p>Hi All,</p>
<p>I've been able to configure my deployment flow.<br>
I'm using web deploy so I created 3 different environments in AppVeyor, one for each server, let's call them E1, E2 and E3. This is how the deploy works:</p>
<ul>
<li>I push to a git branch that triggers a deployment to E1</li>
<li>E1 disconnects itself from the load balancer through a before deployment command.</li>
<li>E1 gets deployed</li>
<li>E1 connects itself to the load balancer again and trigger the deployment to E2 through an after deployment command.</li>
<li>E2 disconnects itself from the load balancer through a before deployment command.</li>
<li>E2 gets deployed</li>
<li>E2 connects itself to the load balancer again and trigger the deployment to E3 through an after deployment command.</li>
<li>E3 gets deployed</li>
</ul>
<p>So far so good, this flow works perfectly.<br>
The missing part is the selenium test which I don't know how to configure.</p>
<p>I already have the test but I don't know how to make it work in AppVeyor, these are my questions:</p>
<ul>
<li>Which URL should I use for the test?</li>
<li>in which step of the pipeline does it get executed?</li>
</ul>
<p>I'd like to execute it after E1 gets deployed and before it connects itself to the load balancer.</p>
<p>Cheers,<br>
Cristhian.</p></div>camtag:help.appveyor.com,2012-11-13:Comment/421464262017-03-17T16:47:38Z2017-03-17T16:47:38ZAutomatic deployment to a load balanced environment<div><p><strong>@cam</strong></p>
<p>Please see my answers below:</p>
<ul>
<li>
<p>Which URL should I use for the test?</p>
<ul>
<li>You can use http://localhost, if your website does not user host headers. If it does, you can create record like <code>127.0.0.1 www.yoursite.com</code> in <code>hosts</code> file. Samples are <a href="http://stackoverflow.com/questions/2602460/powershell-to-manipulate-host-file">here</a>. It is good idea to restore hosts file after your test finished.</li>
</ul>
</li>
<li>
<p>in which step of the pipeline does it get executed?</p>
<ul>
<li>in after-deploy script, before server connects itself to load balancer back.</li>
</ul>
</li>
</ul></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/421464262017-03-17T16:53:51Z2017-03-17T16:53:51ZAutomatic deployment to a load balanced environment<div><p><strong>@Andrew</strong> I agree, we plan major improvements for deployment this year, will take this into account. For now I believe to avoid deployment duplication, you have to create separate environment for each server as <strong>@cam</strong> did.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/421464262017-03-17T18:11:29Z2017-03-17T18:11:29ZAutomatic deployment to a load balanced environment<div><p><a href="https://github.com/appveyor/ci/issues/1406">https://github.com/appveyor/ci/issues/1406</a></p></div>Ilya Finkelshteyn