In Focus

MicroServices Using Service Fabric And .NET Core With CI/CD

In this article, we will be creating a sample MicroService project using Visual Studio and Service Fabric. Then, we will publish that on Azure by applying continuous integration and continuous deployment to this sample project using Azure Pipelines.

In this article, we will be creating a sample MicroService project using Visual Studio and Service Fabric. Then, we will publish that on Azure by applying continuous integration and continuous deployment to this sample project using Azure Pipelines.

 
"Azure Service Fabric is a distributed systems platform that makes it easy to package, deploy, and manage scalable and reliable microservices and containers. Service Fabric also addresses the significant challenges in developing and managing cloud-native applications. Developers and administrators can avoid complex infrastructure problems and focus on implementing mission-critical, demanding workloads that are scalable, reliable, and manageable. Service Fabric represents the next-generation platform for building and managing these enterprise-class, tier-1, cloud-scale applications running in containers." Read more here >>
 

Creating a sample project

 
Setting up the environment
MicroServices using Service Fabric and .Net Core with CI - CD 

MicroServices using Service Fabric and .Net Core with CI - CD

Create the project of type Service Fabric named ServiceFabricSample.

MicroServices using Service Fabric and .Net Core with CI - CD 
 
Create the service of type .NET Core Stateless Service named StatelessServiceSample.
 
 MicroServices using Service Fabric and .Net Core with CI - CD
 
Choose the API template.
 
MicroServices using Service Fabric and .Net Core with CI - CD
 
The result of your newly-created MicroService project.
 
MicroServices using Service Fabric and .Net Core with CI - CD
 
Push F5 and see the result of your service.
 
MicroServices using Service Fabric and .Net Core with CI - CD
Check your cluster status.
  • Open your local cluster, right-click on your Service Fabric icon in the Icons Task Bar.
MicroServices using Service Fabric and .Net Core with CI - CD
  • Navigate through your apps and settings.
MicroServices using Service Fabric and .Net Core with CI - CD
 
MicroServices using Service Fabric and .Net Core with CI - CD
 
MicroServices using Service Fabric and .Net Core with CI - CD
 
Update the default controller to change the returning message.
  1. namespace StatelessServiceSample.Controllers  
  2. {  
  3.     [Route("api/[controller]")]  
  4.     [ApiController]  
  5.     public class ValuesController : ControllerBase  
  6.     {  
  7.         // GET api/values  
  8.         [HttpGet]  
  9.         public ActionResult<string> Get()  
  10.         {  
  11.             return "This is version 1.";  
  12.         }  
  13.   
  14.         // GET api/values/5  
  15.         [HttpGet("{id}")]  
  16.         public ActionResult<string> Get(int id)  
  17.         {  
  18.             return "value";  
  19.         }  
  20.   
  21.         // POST api/values  
  22.         [HttpPost]  
  23.         public void Post([FromBody] string value)  
  24.         {  
  25.         }  
  26.   
  27.         // PUT api/values/5  
  28.         [HttpPut("{id}")]  
  29.         public void Put(int id, [FromBody] string value)  
  30.         {  
  31.         }  
  32.   
  33.         // DELETE api/values/5  
  34.         [HttpDelete("{id}")]  
  35.         public void Delete(int id)  
  36.         {  
  37.         }  
  38.     }  
  39. }  

MicroServices using Service Fabric and .Net Core with CI - CD

 

Publishing your MicroService to Azure using Party Clusters

 
Read more about party clusters here.
 
Register and get your cluster information.
 
MicroServices using Service Fabric and .Net Core with CI - CD
 
Configure your Visual Studio with Party Cluster info
 
Read more about connecting to party cluster here.
 
MicroServices using Service Fabric and .Net Core with CI - CD
 
Validate the published result
 
MicroServices using Service Fabric and .Net Core with CI - CD

Publishing your MicroService to Azure using Azure Service Fabric Clusters

A pre-created Service Fabric Cluster will be used here.
 
MicroServices using Service Fabric and .Net Core with CI - CD 
 
Set the publish profile in Visual Studio.
 
 MicroServices using Service Fabric and .Net Core with CI - CD
 
Check the published result.
 
MicroServices using Service Fabric and .Net Core with CI - CD
MicroServices using Service Fabric and .Net Core with CI - CD

Implementing CI to our sample project

 
Read more about implementing CI here.
 
Create a new Build Pipeline.
MicroServices using Service Fabric and .Net Core with CI - CD
Point it to your repository.
MicroServices using Service Fabric and .Net Core with CI - CD
 
Select Service Fabric template.
MicroServices using Service Fabric and .Net Core with CI - CD
 
Your tasks will be generated according to the selected template, usually, we do not need to change anything here. Now, let's queue our build.
 
MicroServices using Service Fabric and .Net Core with CI - CD
 
Validate your build result.
 
MicroServices using Service Fabric and .Net Core with CI - CD

Implementing CD to our sample project

 
Read more about implementing CD here.
 
Create a new release pipeline.
MicroServices using Service Fabric and .Net Core with CI - CD
Select the Service Fabric template.
MicroServices using Service Fabric and .Net Core with CI - CD
 
Configure your release pipeline.
 
MicroServices using Service Fabric and .Net Core with CI - CD 
 
Set up your cluster endpoint.
 
MicroServices using Service Fabric and .Net Core with CI - CD
 
Turn on the trigger.
 
MicroServices using Service Fabric and .Net Core with CI - CD

Testing the whole process

 
Update the ValuesController.
  1. namespace StatelessServiceSample.Controllers  
  2. {  
  3.     [Route( "api/[controller]" )]  
  4.     [ApiController]  
  5.     public class ValuesController : ControllerBase  
  6.     {  
  7.         // GET api/values  
  8.         [HttpGet]  
  9.         public ActionResult<string> Get()  
  10.         {  
  11.             return "This is version 2.";  
  12.         }  
  13.   
  14.         // GET api/values/5  
  15.         [HttpGet( "{id}" )]  
  16.         public ActionResult<string> Get( int id )  
  17.         {  
  18.             return "value";  
  19.         }  
  20.   
  21.         // POST api/values  
  22.         [HttpPost]  
  23.         public void Post( [FromBody] string value )  
  24.         {  
  25.         }  
  26.   
  27.         // PUT api/values/5  
  28.         [HttpPut( "{id}" )]  
  29.         public void Put( int id, [FromBody] string value )  
  30.         {  
  31.         }  
  32.   
  33.         // DELETE api/values/5  
  34.         [HttpDelete( "{id}" )]  
  35.         public void Delete( int id )  
  36.         {  
  37.         }  
  38.     }  
  39. }  

Commit your changes.
 

MicroServices using Service Fabric and .Net Core with CI - CD
 
Check your build pipeline, you must have a new build.
 
MicroServices using Service Fabric and .Net Core with CI - CD 
 
Check your release pipeline, you must have a new deployment.
 
MicroServices using Service Fabric and .Net Core with CI - CD
 
Check your Cluster Manager to see the diferent version.
 
 MicroServices using Service Fabric and .Net Core with CI - CD
 
MicroServices using Service Fabric and .Net Core with CI - CD 
 
Congratulations, you have successfully created your Service Fabric MicroService and deployed it.
  • Project on Azure Repos here.
References
 
https://azure.microsoft.com/en-us/services/service-fabric/