Part 1: Kick-start containerized microservice CI/CD with Azure DevOps

June 14, 2018 by rdagumampan

This is part of a five-part series in my exploration of Azure microservices facilities.

  1. Kick-start containerized microservice CI/CD with Azure DevOps
  2. Build containerized microservices with Docker and .NET Core 2.1
  3. Build containerized web dashboard with ASP.NET Core
  4. Email service health report with Azure serverless
  5. Scale out services with Managed Kubernetes

Background

I have always been fascinated with container technology and over years I have watched the technology mature. As cloud adaption grows, the community interests on microservices and distributed computing is also unwavering. Undoubtedly, there has never been a better time to be a developer and there just so many exciting things to learn!

But if we want to explore a new technology, it would be nice to build something that is far more than a HelloWorld. Something that would make a difference to what we normally do. So I thought of building a simple service health dashboard that our team could checkout in the morning on their way to work thru notebook or mobile.

The Achitecture Vision

My goal is simple. To build a scalable service that can receive heartbeats from on-premise systems and create near-real time dashboard accessible anywhere and anytime. If should fast to develop and cheap to operate.

Architecture vision

The Technology Stack

  • Azure Container Services (AKS)
  • Azure DevOps
  • Azure SQL Database
  • Application Insights
  • .NET Core 2.1
  • Docker for Windows

The Solution

Jumpstart CI/CD with Azure DevOps

Azure DevOps is a magic wand. It boils and cooks everything for you so you can immedially deliver value. When you choose to create a .NET Core project, Azure DevOps will:

  1. Setup your Azure infrastructure

    • Resource Group. For cost management.
    • Container Registry. For hosting your docker images
    • Linux-based Hosting Plan. For exposing the service to public
    • Application Insights. For your application logs and diagnostics
    • AppService. Dor running your container instance and expose via public URL.
  2. Setup your CI/CD pipeline in VSTS

    • Creates a Git-based project in your VSTS account
    • Creates CI builds
    • Creates CD to your Azure AppService

Build with VSCode

To start developing container-based services, you’re gonna need Windows 10 Pro. Yeah, ditch those Windows 8 machines or create a new Windows 10 VM in Azure. That’s what I did, fast, simple.

  1. Create VM in Azure

    • Standard D4s v3 (4 vcpus, 16 GB memory)
    • Windows 10 Pro
  2. Install Chocolatey / @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

  3. Install Docker for Windows / choco install docker ..and don’t forget to enable Hyper-V.

  4. Install VS Code with these plugins / choco install vscode

  5. Install Git For Windows / choco install git

  6. Install .NET Core 2.1 SDK / choco install dotnetcore-sdk

Run your .NET Core App

Copy your git repo link from your VSTS project page.

/ git clone https://rdagumampanvsts.visualstudio.com/ServiceHealthWebApp/_git/ServiceHealthWebApp
/ dotnet restore
/ dotnet build
/ dotnet run

Build and run your first container

  1. Dockerize it. Open Dockerfile and refactor.

    FROM microsoft/aspnetcore-build:1.1 AS build-env
    WORKDIR /app
    
    # Copy csproj and restore as distinct layers
    COPY *.csproj ./
    RUN dotnet restore
    
    # Copy everything else and build
    COPY . ./
    RUN dotnet publish -c Release -o out
    
    # Build runtime image
    FROM microsoft/aspnetcore:1.1
    WORKDIR /app
    COPY --from=build-env /app/out .
    ENTRYPOINT ["dotnet", "aspnet-core-dotnet-core.dll"]
    
  2. Build it

    / dotnet publish --configuration=Release -o pub
    / docker build . -t servicehealthweb
    / docker images
    

  3. Test it

    / docker run -d -p 8080:80 --name servicehealthweb servicehealthweb
    

    / docker ps
    

    / docker ps
    / docker stop <containerid>
    
  4. Cleanup your ship, remove all containers and images.

    Containers and images takes enormouse amount of space especially your picking a large distribution. These commands cleanup all your running containers and existing images. WARNING: THIS DELETES ALL CONTAINERS AND IMAGES IN YOUR MACHINE!

    / docker ps
    / docker stop $(docker ps -a -q)
    / docker rm $(docker ps -a -q)
    
    / docker images
    / docker rmi $(docker images -a -q)
    

Summary

Azue DevOps is great way to get started and greatly reduced the challenges of making entire CI/CD work. Docker made it so easy to create portable aplications that can be deployed across environments and cloud platforms;

Its important to note that I just made this for fun and learning. The solution altenatives are.

  1. Use enterprise APM solutions. APM solutions like HP’s Microfocus APM and Cisco’s AppDynamics delivers comprehensive service monitoring tools. No doubt its the best tool money can buy but tools like these would have to go through official budget commitment and an enterprise agreement.

  2. Use open source ELK stack. We can leverage on existing ElasticSearch logs to derive service states. This is promising alternative though our ELK server is not exposed to the internet.

References


https://azure.microsoft.com/en-us/features/devops-projects/
https://chocolatey.org/install
https://code.visualstudio.com/
https://www.docker.com/docker-windows
https://git-scm.com/download/win
https://www.microsoft.com/net/download/dotnet-core/sdk-2.1.300

© 2017 | About | Contact | Follow me on Twitter | Powerered by Hucore & Hugo