Deploying War Files On Windows App Services with GithubActions

3 minute read | By Keegan D'Souza

This blog will go over how to deploy your .war file to a Windows App Service using Github Actions.

How To

This blog will use a spring-boot application created using spring initializer.

Validate and test the application locally.

This section is optional if your team as an already existing project. If your team already has your application, you can skip to the deployment section.

  1. Navigate to spring initializer and generate your project. For this project we will use the following parameters.

    • Java Version: 17
    • Spring-Boot: 3.1.0
    • Project Management: Maven
    • Packing: WAR
    • Dependencies: Spring Web

    Spring Initializer

  2. Add a Hello World Controller to display a 200 response. This file will be created under demo\src\main\java\com\example\demo\HelloController.java

     package com.example.demo;
    
     import org.springframework.web.bind.annotation.GetMapping;
     import org.springframework.web.bind.annotation.RestController;
    
     @RestController
     public class HelloController {
    
         @GetMapping("/")
         public String index() {
             return "Greetings from Spring Boot!";
         }
    
     }
    

    Note this step is optional, however when testing you will receive a 404 response from spring boot if you do not add this.

    This hello world controller above is built from a reference of the below spring tutorial. Building an Application with Spring Boot

  3. Test your application runs successfully by running the below command and navigating to http://localhost:8080.

     mvn spring-boot:run
    

    Application running locally

    Additionally your team can download apache tomcat on your local machine and validate the application functions successfully running as a .war file. Below are some open source tutorials on how to accomplish this.

  4. Initialize and push the project to your Github Repo.

    GitHub Push

    This blog will not cover in depth on how to do this, but below is a tutorials on how to accomplish this from Github.

    Adding locally hosted code to GitHub

    Here is the link to my github repo I am using: kedsouza/java-appsvc-windows-github

Configure deployment from Github Actions.

  1. Configure your Windows App Service to use the desired Java and Tomcat Version. These settings can be found under Configuration -> General Settings

    Windows App Service Settings

  2. Set up your Deployment From Github Actions.

    Windows App Service Settings

    This will automatically create a workflow file for you.

  3. If you would like your tomcat application to listen on the ‘/’ endpoint of your app service. Your .war file will have to be named ROOT.war.

    By default the Github Actions pipeline will not do this. By default after deployment your application the file system as shown from the Kudu (Advanced Tools) Site will look similar to below.

    Windows Kudu (Advanced Tools) Settings

    And you will only be able to access your project with the following url scheme. https://{your-app-service-name}/{war name} Windows App Service Default Behavior

  4. Modify your github-actions.yml file to include the following command to rename the file. This will be under the Deploy Stage.

     deploy:
         runs-on: windows-latest
         needs: build
         environment:
             name: 'Production'
             url: $
            
         steps:
             - name: Download artifact from build job
                 uses: actions/download-artifact@v2
                 with:
                 name: java-app
    
             # ---- Added Task ---- #
             - name: Rename .War file
                 run: move *.war ROOT.war
    
             - name: Deploy to Azure Web 
                 id: deploy-to-webapp
                 uses: azure/webapps-deploy@v2
                 with:
                 app-name: 'kedsouza-tomcat'
                 slot-name: 'Production'
                 publish-profile: $
                 package: '*.war'
    

    This command will rename your .war file to ROOT.war.

  5. After you save your changes, and the github action redeploys you should now see your application responding on the ‘/’ endpoint.

    Windows App Service Root Behavior