tag:help.appveyor.com,2012-11-13:/discussions/problems/6167-post-deploy-npm-installAppVeyor: Discussion 2018-08-25T02:15:23Ztag:help.appveyor.com,2012-11-13:Comment/420489832017-02-28T17:30:49Z2017-02-28T17:30:49ZPost-deploy npm install?<div><p>Hi Brian,</p>
<p>Do you think <a href="http://stackoverflow.com/questions/30509490/azure-web-apps-service-auto-install-npm-modules-from-package-json">
this SO discussion</a> can help?</p>
<p>Ilya.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/420489832017-02-28T18:58:56Z2017-02-28T18:59:55ZPost-deploy npm install?<div><p>No, the issue is that there doesn't seem to be a way to build
from AppVeyor, push to Azure and then have Azure install the NPM
packages.</p>
<p>The discussion on SO centered around using Azures Kudu build
environment, which would take the place of AppVeyor. I'd just
rather use AppVeyor if possible since I have some additional steps,
such as TypeScript compilation.</p></div>Brian Vallelungatag:help.appveyor.com,2012-11-13:Comment/420489832017-02-28T19:53:46Z2017-02-28T19:53:46ZPost-deploy npm install?<div><p>Ah I see. Actually if you follow <a href="https://www.appveyor.com/docs/deployment/web-deploy/#using-web-deploy-with-a-nodejs-website">
this guide</a> all packages should be published to Azure website.
Please let me know if I misunderstood something again :)</p>
<p>Ilya.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/420489832017-03-02T14:35:07Z2017-03-02T14:35:08ZPost-deploy npm install?<div><p>I have followed that guide. The issue is that zipping and
synchronizing the node_modules folder takes about 20 minutes
because it has 30,000 files in it. I'd like to send just my
application files and then run npm install on Azure itself.</p></div>Brian Vallelungatag:help.appveyor.com,2012-11-13:Comment/420489832017-03-02T19:29:05Z2017-03-02T19:29:05ZPost-deploy npm install?<div><p>Now I see! You can call it with <a href="https://github.com/projectkudu/kudu/wiki/REST-API#command">Kudu
API</a><br>
<a href="https://gist.github.com/IlyaFinkelshteyn/41caf156dd5b41927c9e010f266b9090">
Here</a> is working sample.</p>
<p>This YAML worked for me (assuming <code>package.json</code> is
in site root, maybe <code>site\\wwwroot</code> is better
folder)</p>
<pre>
<code>version: 1.22.{build}
environment:
AzureDeploymentUsername:
secure: FDubtx3elTZYT8zd+dduVg==
AzureDeploymentPassword:
secure: dNPsSiN7aAwAe2K7Aw+IVw==
AzureWebsiteName: ilyaf3
build_script:
- ps: "$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes((\"{0}:{1}\" -f $env:AzureDeploymentUsername,$env:AzureDeploymentPassword)))\n$apiUrl = \"https://$env:AzureWebsiteName.scm.azurewebsites.net/api/command\"\n\n$body = @{ \n command=\"npm install\"\n dir=\"site\"\n}\n\n$headers = @{\n \"Authorization\" = (\"Basic {0}\" -f $base64AuthInfo)\n \"ContentType\" = \"application/json\" \n}\n\nInvoke-RestMethod -Uri $apiUrl -Headers @{Authorization=(\"Basic {0}\" -f $base64AuthInfo)} -Method POST -ContentType \"application/json\" -Body (ConvertTo-Json $body) | fl"</code>
</pre>
<p>YAML is auto-generated, you can make is look nicer using
<a href="https://www.appveyor.com/docs/build-configuration/#script-blocks-in-build-configuration">
script blocs doc</a> or using separate <code>.ps1</code> file.</p>
<p>Please let me know if it works e2e with your site. I did not
that it with true node site, but simple put
<code>package.json</code> into default ASP.NET site folder.</p>
<p>Ilya.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/420489832017-03-03T15:10:39Z2017-03-03T15:10:39ZPost-deploy npm install?<div><p>This almost works for me, but I'd like to avoid putting the
username and password directly in my script file for obvious
reasons.</p>
<p>Since my deployment environment already has these values for
WebDeploy configured is there a way I can access them?</p></div>Brian Vallelungatag:help.appveyor.com,2012-11-13:Comment/420489832017-03-03T17:47:07Z2017-03-03T17:47:07ZPost-deploy npm install?<div><p>As you see in my sample, I use <a href="https://www.appveyor.com/docs/build-configuration/#secure-variables">
secure variables</a> for my deployment credentials.</p>
<p>If you call this deployment as part of build process, you can
add this script as <code>after_deploy</code> script which happens
<a href="https://www.appveyor.com/docs/build-configuration/#build-pipeline">
right after deployment</a>.</p>
<p>If you need to start your environment deployment asynchronously,
separately from build process, we have no way to call this script
as part of environment deployment. What you can do in this case is
create script which will start environment deployment <a href="https://www.appveyor.com/docs/api/environments-deployments/#start-deployment">
with API</a> and then call script to run <code>npm install</code>
on Azure website. In this case you have to dela with all secrets on
computer you are calling this script from. We can provide more help
with scripting if this is your case.</p>
<p>Also, if you need to start your environment deployment
asynchronously, you can create separate <a href="https://www.appveyor.com/blog/page/2/">deployment project</a>
which will artifacts from another build deploy everything and run
<code>npm install</code> script. Thus you will be able to run this
script securely and start deployment with UI any time.</p>
<p>Ilya.</p></div>Ilya Finkelshteyn