Skip to content

Instantly share code, notes, and snippets.

@dfuenzalida
Created February 21, 2021 06:05
Show Gist options
  • Save dfuenzalida/057993401095d92ec9172bbc8b8c827a to your computer and use it in GitHub Desktop.
Save dfuenzalida/057993401095d92ec9172bbc8b8c827a to your computer and use it in GitHub Desktop.
Quick guide to deploy a Clojure web app to Azure

Quick guide to deploy a Clojure web app to Azure

Prerequisites

Login to your Azure subscription

Start the login process from the terminal, log in using your web browser and let the subscription and user configuration to be saved locally:

$ az login

Create demo a Luminus app

Use Leiningen to create a new web app using the default Luminus framework template. I'm using lumidemo as the name:

$ lein new luminus lumidemo
Generating a Luminus project.

Use Leiningen to generate a Maven POM file

Leiningen can generate a pom.xml file from the project, which we'll use only for deployment to Azure:

$ lein pom
Wrote .../lumidemo/pom.xml

Change into the project folder with cd lumidemo (or whatever you named your project).

Microsoft provides a Maven plugin to make deployment of Java-based apps to Azure very simple.

Run the following command line: mvn com.microsoft.azure:azure-webapp-maven-plugin:1.12.0:config, the output should look like the following:

$ mvn com.microsoft.azure:azure-webapp-maven-plugin:1.12.0:config
[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------------< lumidemo:lumidemo >--------------------------
[INFO] Building lumidemo 0.1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- azure-webapp-maven-plugin:1.12.0:config (default-cli) @ lumidemo ---
[WARNING] The POM for com.microsoft.azure.applicationinsights.v2015_05_01:azure-mgmt-insights:jar:1.0.0-beta is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.microsoft.applicationinsights.core.dependencies.xstream.core.util.Fields (file:/home/denis/.m2/repository/com/microsoft/azure/applicationinsights-core/2.6.1/applicationinsights-core-2.6.1.jar) to field java.util.TreeMap.comparator
WARNING: Please consider reporting this to the maintainers of com.microsoft.applicationinsights.core.dependencies.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Auth Type : AZURE_CLI, Auth Files : [/home/denis/.azure/azureProfile.json, /home/denis/.azure/accessTokens.json]
[INFO] [Correlation ID: 49e28eb1-3df0-4087-b993-cbc96f038f01] Instance discovery was successful
[INFO] There is only one subscription 'Visual Studio Enterprise Subscription(860c696e-c799-4791-a073-9fda2ade2c98)' in your account, will use it automatically.
[WARNING] There are no Java Web Apps in current subscription, please follow the following steps to create a new one.
Define value for OS [Linux]:
* 1: Linux
  2: Docker
  3: Windows
Enter your choice: 
Define value for pricingTier [P1v2]:
   1: B1
   2: B2
   3: B3
   4: D1
   5: F1
*  6: P1v2
   7: P2v2
   8: P3v2
   9: S1
  10: S2
  11: S3
Enter your choice: 
Define value for javaVersion [Java 8]:
* 1: Java 8
  2: Java 11
Enter your choice: 2
Please confirm webapp properties
Subscription Id : 860c696e-c799-4791-a073-9fda2ade2c98
AppName : lumidemo-1613881972830
ResourceGroup : lumidemo-1613881972830-rg
Region : westeurope
PricingTier : PremiumV2_P1v2
OS : Linux
Java : Java 11
Web server stack: Java SE
Deploy to slot : false
Confirm (Y/N) [Y]: 
[INFO] Saving configuration to pom.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  31.264 s
[INFO] Finished at: 2021-02-20T20:33:15-08:00
[INFO] ------------------------------------------------------------------------

You will be asked for your OS, pricing tier and java version, I chose

  • Linux (the default)
  • P1v2 (the default)
  • Java 11 (I don't have Java 8 installed)

You will need to make minor changes to the pom.xml file. In the <deployment> element, change the following bits:

          <deployment>
            <resources>
              <resource>
                <directory>${project.basedir}/target/uberjar</directory> <!-- NOTE: uberjar path -->
                <includes>
                  <include>lumidemo.jar</include><!-- NOTE: single file -->
                </includes>
              </resource>
            </resources>
          </deployment>

Now you can build and package your app with lein uberjar:

$ lein uberjar
Compiling lumidemo.config
Compiling lumidemo.core
Compiling lumidemo.env
Compiling lumidemo.handler
Compiling lumidemo.layout
Compiling lumidemo.middleware
Compiling lumidemo.middleware.formats
Compiling lumidemo.nrepl
Compiling lumidemo.routes.home
Created /home/denis/Projects/azure/lumidemo/target/uberjar/lumidemo-0.1.0-SNAPSHOT.jar
Created /home/denis/Projects/azure/lumidemo/target/uberjar/lumidemo.jar

Finally, you can start deployment using the Maven plugin with mvn azure-webapp:deploy. The output will look like:

$ mvn azure-webapp:deploy
[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------------< lumidemo:lumidemo >--------------------------
[INFO] Building lumidemo 0.1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- azure-webapp-maven-plugin:1.12.0:deploy (default-cli) @ lumidemo ---
[WARNING] The POM for com.microsoft.azure.applicationinsights.v2015_05_01:azure-mgmt-insights:jar:1.0.0-beta is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.microsoft.applicationinsights.core.dependencies.xstream.core.util.Fields (file:/home/denis/.m2/repository/com/microsoft/azure/applicationinsights-core/2.6.1/applicationinsights-core-2.6.1.jar) to field java.util.TreeMap.comparator
WARNING: Please consider reporting this to the maintainers of com.microsoft.applicationinsights.core.dependencies.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Auth Type : AZURE_CLI, Auth Files : [/home/denis/.azure/azureProfile.json, /home/denis/.azure/accessTokens.json]
[INFO] [Correlation ID: 09505f09-fe96-4159-85c8-2c3c95d1898a] Instance discovery was successful
[INFO] Subscription : Visual Studio Enterprise Subscription(860c696e-c799-4791-a073-9fda2ade2c98)
[INFO] Target Web App doesn't exist. Creating a new one...
[INFO] Creating App Service Plan 'ServicePlan64f63ff5-71a9-4505'...
[INFO] Successfully created App Service Plan.
[INFO] Successfully created Web App.
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource to /home/denis/Projects/azure/lumidemo/target/azure-webapp/lumidemo-1613881972830-65812162-e63a-418c-81d9-8f0cd679739a
[INFO] Trying to deploy artifact to lumidemo-1613881972830...
[INFO] Renaming /home/denis/Projects/azure/lumidemo/target/azure-webapp/lumidemo-1613881972830-65812162-e63a-418c-81d9-8f0cd679739a/lumidemo.jar to app.jar
[INFO] Deploying the zip package lumidemo-1613881972830-65812162-e63a-418c-81d9-8f0cd679739a16911239699849543576.zip...
[INFO] Successfully deployed the artifact to https://lumidemo-1613881972830.azurewebsites.net
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:13 min
[INFO] Finished at: 2021-02-20T20:40:25-08:00
[INFO] ------------------------------------------------------------------------

In this example, the application was deployed to https://lumidemo-1613881972830.azurewebsites.net

Azure fronts the web application so that it can be accessed over HTTPs, or you can connect over plain HTTP too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment