Skip to main content

DevOps Demo: GitHub Actions for Azure WebApp Deployment

On a daily basis, I automate builds and deployments with Azure DevOps Pipelines. I was excited to come across the news of the launch of CI/CD capabilities on GitHub Actions and was looking for an opportunity to try things out. The opportunity came when I got to be one of the trainers for DevOps track in the NASSCOM GCC Skills development session for select Engineering college faculties hosted by Hexagon.


The objective was to give insights into software development practices followed by large IT organizations. In addition to an in-depth presentation, we demonstrated source code management, explained good coding practices and tools involved from a DevOps perspective. 

The Choices: GitHub and Microsoft Azure

  1. For source code management, we chose GitHub owing to the awareness factor
  2. Through GitHub Actions, demonstrated Azure DevOps pipelines kind of capabilities
  3. For the demo, we felt a web application would be a good choice as it would enable us to showcase cloud platform usage

The PetClinic Project

To avoid building everything from scratch, I started looking for a nice looking free web application. This led us to the PetClinic project approved by the Spring Team. I got started by forking it and managed to set up a GitHub Actions workflow to build and deploy the application. While the Java part, until "Build with Maven" was simple, it took quite some effort to get the Azure WebApps Deployment part to work.

name: Build & Deploy Pet Clinic

on: push

jobs:
  build-and-deploy:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    
    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8
    
    - name: Unit Tests
      run: mvn test
      
    - name: Build with Maven
      run: mvn -B package --file pom.xml
      
    - name: SonarCloud scan
      run: mvn verify sonar:sonar
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        SONAR_TOKEN: ${{ secrets.sonarToken }}
      if: github.ref == 'refs/heads/master'
        
    - name: Azure WebApp Deployment
      uses: Azure/webapps-deploy@v1
      with:
        publish-profile: ${{ secrets.stagingPublishProfile }}
        app-name: thepetclinic
        package: '${{ github.workspace }}/target/*.war'
        slot-name: thepetclinic-staging
        
    - name: Azure Login
      uses: Azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDS }}
    
    - run: |
        az storage blob upload -c petclinic -f '${{ github.workspace }}/target/petclinic.war' -n 'petclinic_${{ github.sha }}.war' \
        --account-name warfiles \
        --account-key ${{ secrets.azureStorage }}

In addition to the process involved in building the Actions workflow, we explained the following best practices -

  1. Version control for source code management - this is something which students rarely do today and end up with code scattered between computers during their project work
  2. Pull request based code change merging
  3. Secrets and variable management - no checking in credentials in plain text to version control system
  4. Unit testing
  5. Eliminate bugs and vulnerabilities from start through SonarCloud - free for open source projects
  6. Overview of the Microsoft Azure functionality - quick bits about opening free/trial accounts with Microsoft Azure, AWS
  7. Swapping between staging and production slots
  8. Artifact management - here the generated .war files were uploaded to Azure Storage account

What Next?

The next time, I get to demonstrate on the topic, I am planning following improvements - 
  1. External database in place of present in-memory database
  2. More data
  3. Custom domain mapping
  4. Secondary demo, perhaps using a containerized version of PetClinic 

Comments

Popular posts from this blog

Resolving INS-20802: Oracle Net Configuration Assistant failed error on Windows 10

I was all excited about the migration to Windows 10 until I had to install Oracle client 12.1.0.2 on it. The Oracle client installation used to fail miserably at the last stage with this error named INS-20802.


SSL VPN: Configuring and Using Forticlient on Ubuntu, creating a Launcher

Is your primary OS at home Linux and do you use Windows only to connect to your work PC over VPN or to attend meetings? Do you often wish to connect to your work VPN from a Linux PC?  If your answer is 'Yes' to the above questions, I have an answer if your workplace uses Fortinet SSL VPN. Note that it's possible to connect to Fortinet and other VPNs like Cisco VPN from Linux through the inbuilt network manager by installing additional tools but this post would focus on using the standard Forticlient for accessing the resources on your work network.
Obtaining Forticlient The most important thing to note w.r.t. using Forticlient for Ubuntu (or any Linux distro) is to note that the client is not publicly available for download from the official website. You will have to ask your IT department to download the client for you, in case they haven't provided it.

Nginx - Solution for 10060: A connection attempt failed because the connected party did not properly respond

I was in the process of setting up Nginx to serve as the reverse proxy for Nexus Repository Manager OSS. However, the Nexus repository started loading really slowly post this and used to repeatedly display disconnected and reconnected messages. The Nginx log file used to log the below error -

<timestamp> [error] 3240#3632: *1 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: <ip address="">, server: <fqdn>, request: "GET /nexus HTTP/1.1", upstream: "http://[::1]:8081/nexus", host: "<fqdn>"