Custom deployment on azure sites

I recently started using Gulp.js to pack all my CSS and JavaScript into separate files, which I then include in my web application. My web application is written in Python (using Flask ).

I obviously don't want to track the output CSS and JS Gulp files with git (since they create the output files).

I am deploying my site to Azure Websites using push to deploy. That is, I just run git push azure master , and Azure automatically detects that I am using Python, configure virtualenv , install pip dependencies, and so on. This article describes how to install this .

This process works fine, but now that I have started using Gulp, I want to make sure that the related JavaScript and CSS files are also created on the server side every time the website is deployed.

In addition, in the future, I would like Azure to run all tests during deployment and only successfully deploy if they all pass.

Unfortunately, I have yet to find a satisfactory solution for this workflow, as I cannot add custom steps for Azure's automatic deployment.

I tried writing a custom deployment script using Kudu (as suggested by this blog post ), but it turns off all the automatic steps that Azure usually performs; running azure site deploymentscript --python only creates a very simple Kudu deployment file that does not handle reading in the web.config , configuring virtualenv or installing dependencies. I did not find documentation on how to do this myself; I use the standard Azure automatic deployment script (which gets the generated server side when I click on the code, so I cannot access it myself), because otherwise virtualenv and pip dependencies will not be processed.

Is there any workaround available so that I can configure my script deployment (e.g. run Gulp) when Flask is deployed correctly?

+6
source share
1 answer

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

  • Access the Kudu Services website at: yourwebsite.scm.azurewebsites.net .
  • Click Tools> Download Deployment Script and get the Script Azure deployment generated for your code (this is not limited to Flask applications).
  • (optional) Script - Windows script package. I ported it to Bash because I am familiar with it and it is also supported by Azure websites.
  • Add special materials to your liking: create the material using Gulp / Grunt, run the tests and fail (failing with a non-zero error code) if there is any failure, etc. You should also remember to check how things like Gulp / Grunt are installed using npm and the corresponding package.json file.
    • note that you must mark the deployment as invalid before KuduSync will be able to copy your new files from the repository, because otherwise they will fall into your root folder on the Internet, although, for example, your tests failed.

Here's a snippet of my Gulp.js code processing, for anyone interested. Take a look at the Script generated by azure site deploymentscript --node for examples of how to choose the correct versions of Node and npm:

 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." 

Remember to add the 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!

PS: Please note that this whole process is a bit hacked, and that the absolutely correct way to do this is to use the continuous integration agent.

+7
source

Source: https://habr.com/ru/post/982094/


All Articles