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
- For source code management, we chose GitHub owing to the awareness factor
- Through GitHub Actions, demonstrated Azure DevOps pipelines kind of capabilities
- 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 -
- 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
- Pull request based code change merging
- Secrets and variable management - no checking in credentials in plain text to version control system
- Unit testing
- Eliminate bugs and vulnerabilities from start through SonarCloud - free for open source projects
- Overview of the Microsoft Azure functionality - quick bits about opening free/trial accounts with Microsoft Azure, AWS
- Swapping between staging and production slots
- 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 -
- External database in place of present in-memory database
- More data
- Custom domain mapping
- Secondary demo, perhaps using a containerized version of PetClinic
Comments
Post a Comment