Custom Deployment to Azure Websites

只谈情不闲聊 提交于 2019-12-05 06:04:19

Since Kudu is open source and available on GitHub, I have brought up this problem in its issue tracker (link, for anyone interested). The code owner vas very helpful and pointed me towards a solution.

  1. Access the site's Kudu Services at: yourwebsite.scm.azurewebsites.net.
  2. Click Tools > Download Deployment Script and get the deployment script Azure generated for your code (this isn't limited to Flask apps).
  3. (Optional) The script is a Windows batch script. I ported it to Bash, because I'm more familiar with it and Azure Websites supports it as well.
  4. Add custom stuff to your liking: build stuff using Gulp/Grunt, run tests and fail the deployment (exiting with nonzero error code) if any fail, etc. You should also remember to first check whether stuff like Gulp/Grunt is installed using npm and the appropriate package.json file.
    • note that you should only mark the deployment as failed before KuduSync has a chance to copy your new files from the repository, since otherwise they'll end up in your web root folder even though e.g. your tests have failed.

Here's the fragment of my code handling Gulp.js, for anyone who's interested. Look at the script generated by azure site deploymentscript --node for examples on how to select the correct Node and npm versions:

selectNodeVersion
echo "Invoking \"$NPM_CMD install\"..."
eval $NPM_CMD install
exitWithMessageOnError "Could not run 'npm install'.  Do you have the necessary privileges?"
echo "Finished npm install."

# The path doesn't seem to get set OK.  Use this hack to run gulp.
GULP="node_modules/gulp/bin/gulp.js"

echo "Running gulp..."
"$GULP" production
exitWithMessageOnError "Could not run 'gulp'.  Did 'npm install' run OK?"
echo "Finished gulp."

Don't forget to actually add a package.json file containing all the necessary Gulp dependencies to your project. Azure provides Node.js (and npm) but not Gulp.js. Hope this helps!

P.S.: Do note that this whole process is a bit hacky and that the completely correct way to do this is by using a continuous integration agent.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!