none
[Node.js][Web Apps] Continuous Deployment of Node.js App RRS feed

  • Question

  • Hello,

    I have a Node.js app. This app is a basic website. I can run it locally by running "node dist/server.js". However, the contents of the "dist" directory do not get populated until I run "gulp package". I have setup up continuous integration from the Azure portal, however, from what I can tell a) "gulp package" does  not get ran and b) I'm not sure that Azure knows to use "dist/server.js". My directory structure looks like this:

    node_modules/ src/ server.js views/ index.html

    .deployment gulpfile.js package.json web.config

    My web.config file has the following:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.webServer>
        <staticContent>
          <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
        </staticContent>
        <modules runAllManagedModulesForAllRequests="false" />
    
        <iisnode watchedFiles="web.config;*.js;dist\routes\*.js;dist\views\*.html"/>
    
        <handlers>
          <add name="iisnode" path="/dist/server.js" verb="*" modules="iisnode" />
        </handlers>
    
        <security>
          <requestFiltering>
            <hiddenSegments>
              <remove segment="bin" />
            </hiddenSegments>
          </requestFiltering>
        </security>
    
        <rewrite>
          <rules>
            <clear />
            <rule name="app" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
              <match url="iisnode.+" negate="true" />
              <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
              <action type="Rewrite" url="dist\server.js" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>

    My .deployment file has the following:

    [config]
    project = dist

    I'm not sure what else I need to do to get the "dist" version of my app visible from Azure. Thanks!




    Thursday, February 18, 2016 2:02 PM

Answers

  • Hi Chad,

    Get the Azure-Cli NPM package.

    Then, run "azure site deploymentscript node" (on the project folder).

    This will generate the ".deployment" and "deploy.cmd" files you need for a NodeJS deploy to Azure.

    Commit these files and they should do the trick.

    Thursday, February 18, 2016 4:08 PM
  • You can try the following steps:

    • Install the Azure CLI
    • In your application's root directory, run command: 
      • azure config mode asm
      • azure site deploymentscript --node
    • the command will create 2 files name ".deployment" and "deploy.cmd", add the gulp command in the deploy.cmd, e.g.

    My test gulpfile has a simple content:

    var gulp = require('gulp');
    gulp.task('default', function() {
        return gulp.src('src/*.js')
            .pipe(gulp.dest('dist'));
    });

    Then found the similar command in deploy.cmd file:

    call :ExecuteCmd !NPM_CMD! install --production //(line 103 in my test)

    under this line, add the gulp command with local gulp module:

    call :ExecuteCmd node_modules/.bin/gulp

    Then when you delpoy your application to Azure Web apps, after the npm finished installing modules, you can find the similar message in remote console:

    remote: [05:20:34] Using gulpfile D:\home\site\wwwroot\gulpfile.js
    remote: [05:20:34] Starting 'default'...
    remote: [05:20:34] Finished 'default' after 47 ms

    Friday, February 19, 2016 5:32 AM
    Moderator

All replies

  • Hi Chad,

    Get the Azure-Cli NPM package.

    Then, run "azure site deploymentscript node" (on the project folder).

    This will generate the ".deployment" and "deploy.cmd" files you need for a NodeJS deploy to Azure.

    Commit these files and they should do the trick.

    Thursday, February 18, 2016 4:08 PM
  • You can try the following steps:

    • Install the Azure CLI
    • In your application's root directory, run command: 
      • azure config mode asm
      • azure site deploymentscript --node
    • the command will create 2 files name ".deployment" and "deploy.cmd", add the gulp command in the deploy.cmd, e.g.

    My test gulpfile has a simple content:

    var gulp = require('gulp');
    gulp.task('default', function() {
        return gulp.src('src/*.js')
            .pipe(gulp.dest('dist'));
    });

    Then found the similar command in deploy.cmd file:

    call :ExecuteCmd !NPM_CMD! install --production //(line 103 in my test)

    under this line, add the gulp command with local gulp module:

    call :ExecuteCmd node_modules/.bin/gulp

    Then when you delpoy your application to Azure Web apps, after the npm finished installing modules, you can find the similar message in remote console:

    remote: [05:20:34] Using gulpfile D:\home\site\wwwroot\gulpfile.js
    remote: [05:20:34] Starting 'default'...
    remote: [05:20:34] Finished 'default' after 47 ms

    Friday, February 19, 2016 5:32 AM
    Moderator
  • Thank you for your response. I attempted what you mentioned. However, that did not solve my issue. I am getting an error in the activity logs that says:

    deploy.sh: line 125: ./node_modules/.bin/gulp: No such file or directory
    An error has occurred during web site deployment.
    gulp failed

    First, I opened the deploy.sh file that was generated by the "azure site deploymentscript node" command. Inside of the deploy.sh file, I added lines 18-25 from this gist. My package.json file has:

      "engines" : { "node" : "~5.3.0" },  
      "devDependencies": {
        "bower": "^1.5.2",
        "gulp": "github:gulpjs/gulp#4.0",
      },

    To my surprise, when I look in the ./node_modules directory via Kudo, I do not see gulp installed though. Its like it doesn't install the devDependencies which is what gulp is. So, I tried moving the gulp package description to the "dependencies" section. At that point, I got a separate error detailing that gulp could not be installed.

    Friday, February 19, 2016 12:16 PM
  • Hi Chad,

    One question, why are you trying to run Gulp on the deploy process?

    Most default scenarios use Gulp to process things on the Dev Environtment (that's why it's on the devDependencies by default). That way, if you are, for example, using it to minify files, you just commit the minified files, you don't minify them on the deploy process.

    Friday, February 19, 2016 1:03 PM
  • I am trying to run Gulp on the deploy process.
    Friday, February 19, 2016 2:02 PM
  • As Azure Web Apps is a production env for applications, you can login the Kudu console site of your site to check whether the deployment task has installed the dependencies in your package.json file. 

    the URL should be "https://<your_site_name>.scm.azurewebsites.net".

    And you can try to move the dependencies to "dependencies" section.

    This is my package.json file:

    {
      "dependencies": {
        "gulp": "^3.9.1"
      }
    }

    Monday, February 22, 2016 1:18 AM
    Moderator