Reshuffle Open Source on Azure

This tutorial describes how to use the Azure command line interface to deploy a Node.js application.

Prerequisites

  • An Azure subscription
  • Git
  • Node.js and npm 6.x or higher
  • Azure CLI

Steps to Deploy

  1. Login to your Azure account

    $ az login

  2. Create the Azure App Service to host your app code

    a. Create a resource group in a data center

    $ az group create --name [RESOURCE_GROUP] --location [DATA_CENTRE_LOCATION]

    The locations list can be found by running

    $ az account list-locationse.g.westus

    e.g. westus

    b. Set the default resource group and region for subsequent commands

    $ az configure --defaults group=[RESOURCE_GROUP] location=[DATA_CENTRE_LOCATION]

    c. Create an app service plan that defines the underlying virtual machine used by the App Service

    $ az appservice plan create --name [PLAN_NAME] --sku F1

    The command above specifies a free hosting plan,--sku F1, which uses a shared virtual machine, and names the plan [PLAN_NAME]

    Additional values for --sku can be found by typing

    $ az appservice list-locations --help

    d. Create the App Service

    $ az webapp create --name [APP_NAME] --plan [PLAN_NAME] --runtime "[NODE_VERSION]"

    [PLAN_NAME]should be a unique name that eventually will be part of the app URL. Choose [NODE_VERSION] from the list when running az webapp list-runtimes e.g. node|12-lts

  3. Deploy the App In this step, you deploy your Node.js app code to Azure App Service using a basic process of pushing your local Git repository to Azure. Please note that in order to pass the PORT to reshuffle, send it when starting the app

    ```
    const app = new Reshuffle()
    ...
    app.start(process.env.PORT)
    ```
    a. Initialize a local Git repository and make an initial commit
    ```
    $ git init 
    $ git add -A 
    $ git commit -m "Initial Commit"
    ```
    b. Set up deployment credentials in Azure, replacing `[USERNAME]` and `[PASSWORD]` with your credentials
    
    `$ az webapp deployment user set --user-name [USERNAME] --password [PASSWORD]`
    
    c. Retrieve the Git endpoint to which we want to push the app code
    
    `$ az webapp deployment source config-local-git --name [APP_NAME]`
    
    The output from the command is similar to the following:
    ```
    {
       "url": "https://username@msdocs-node-cli.scm.azurewebsites.net/msdocs-node-cli.git"
    }
    ```
    d. Set a new remote in Git named azure, using the URL from the previous step omitting the username. 
    
    `$ git remote add azure https://msdocs-node-cli.scm.azurewebsites.net/msdocs-node-cli.git`
    
    e. Deploy the app code from the Git repository to the App Service.
    
    `$ git push azure master`
    
  4. View the App

    $ az webapp browse --name [APP_NAME]

  5. View logs

    Enable and start logging

    $ az webapp log tail --name [APP_NAME]

    In order to view more detailed logs you can run

    $ az webapp log config --name [APP_NAME] --resource-group [RESOURCE_GROUP] --detailed-error-messages true --level verbose

  6. Changes and redeploy Commit your code changes to the local Git repository, and then redeploy by pushing to Azure.

    $ git commit -a -m "Commit message"
    $ git push azure master
    
  7. Cleanup Clean up the resources by running

    $ az group delete --name [RESOURCE_GROUP]

More details can be found in the following