Tutorial: Deploy an application with CI/CD to a Service Fabric cluster
This tutorial is part four of a series and describes how to set up continuous integration and deployment for an Azure Service Fabric application using Azure Pipelines. An existing Service Fabric application is needed, the application created in Build a .NET application is used as an example.
In part three of the series, you learn how to:
- Add source control to your project
- Create a build pipeline in Azure Pipelines
- Create a release pipeline in Azure Pipelines
- Automatically deploy and upgrade an application
In these tutorials you learn how to:
Prerequisites
Before you begin this tutorial:
- If you don't have an Azure subscription, create a free account
- Install Visual Studio 2019 and install the Azure development and ASP.NET and web development workloads.
- Install the Service Fabric SDK
- Create a Windows Service Fabric cluster on Azure, for example by following this tutorial
- Create an Azure DevOps organization. An organization allows you to create a project in Azure DevOps and use Azure Pipelines.
Download the Voting sample application
If you didn't build the Voting sample application in part one of this series, you can download it. In a command window, run the following command to clone the sample app repository to your local machine.
git clone https://github.com/Azure-Samples/service-fabric-dotnet-quickstart
Prepare a publish profile
Now that you created an application and deployed the application to Azure, you're ready to set up continuous integration. First, prepare a publish profile within your application for use by the deployment process that executes within Azure Pipelines. The publish profile should be configured to target the cluster you previously created. Start Visual Studio and open an existing Service Fabric application project. In Solution Explorer, right-click the application and select Publish....
Choose a target profile within your application project to use for your continuous integration workflow, for example Cloud. Specify the cluster connection endpoint. Check the Upgrade the Application checkbox so that your application upgrades for each deployment in Azure DevOps. Select the Save hyperlink to save the settings to the publish profile and then choose Cancel to close the dialog box.
Share your Visual Studio solution to a new Azure DevOps Git repo
Share your application source files to a project in Azure DevOps so you can generate builds.
Create a new GitHub repo and Azure DevOps repo from Visual Studio 2022 IDE by selecting Git -> Create Git Repository from Git menu
Select your account in the drop-down and enter your repository name and select Create and Push button.
Publishing the repo creates a new project in your Azure DevOps Services account with the same name as the local repo.
View the newly created repository by navigating to https://dev.azure.com/\<organizationname>, hover mouse over the name of your project, and select the Repos icon.
Configure Continuous Delivery with Azure Pipelines
An Azure Pipelines build pipeline describes a workflow that is composed of a set of build steps that are executed sequentially. Create a build pipeline that produces a Service Fabric application package, and other artifacts, to deploy to a Service Fabric cluster. Learn more about Azure Pipelines build pipelines.
An Azure Pipelines release pipeline describes a workflow that deploys an application package to a cluster. When used together, the build pipeline and release pipeline execute the entire workflow starting with source files to ending with a running application in your cluster. Learn more about Azure Pipelines release pipelines.
Create a build pipeline
Open a web browser and navigate to your new project at: https://dev.azure.com/\<organizationname>/VotingSample
Select the Pipelines tab and select Create Pipeline.
Select Use the classic editor to create a pipeline without YAML.
Select Azure Repos Git as source, VotingSample Team project, VotingApplication Repository, and master Default branch for manual and scheduled builds. Then select Continue.
In Select a template, select the Azure Service Fabric application template and select Apply.
In Tasks, enter "Azure Pipelines" as the Agent pool and windows-2022 as Agent Specification.
Under Triggers, enable continuous integration by checking Enable continuous integration. Within Branch filters, the Branch specification defaults to master. Select Save and queue to manually start a build.
Builds also trigger upon push or check-in. To check your build progress, switch to the Builds tab. Once you verify that the build executes successfully, define a release pipeline that deploys your application to a cluster.
Create a release pipeline
Select the Pipelines tab, then Releases, then + New pipeline. In Select a template, select the Azure Service Fabric Deployment template from the list and then Apply.
Select Tasks and then +New to add a new cluster connection.
In the New Service Fabric Connection view select Certificate Based or Microsoft Entra credential authentication. Specify cluster endpoint of tcp://mysftestcluster.southcentralus.cloudapp.azure.com:19000" (or the endpoint of the cluster you're deploying to).
For certificate-based authentication, add the Server certificate thumbprint of the server certificate used to create the cluster. In Client certificate, add the base-64 encoding of the client certificate file. See the help pop-up on that field for info on how to get that base-64 encoded representation of the certificate. Also add the Password for the certificate. You can use the cluster or server certificate if you don't have a separate client certificate.
For Microsoft Entra credentials, add the Server certificate thumbprint of the server certificate used to create the cluster and the credentials you want to use to connect to the cluster in the Username and Password fields.
Select Save.
Next, add a build artifact to the pipeline so the release pipeline can find the output from the build. Select Pipeline and Artifacts->+Add. In Source (Build definition), select the build pipeline you created previously. Select Add to save the build artifact.
Enable a continuous deployment trigger so that a release is automatically created when the build completes. Select the lightning icon in the artifact, enable the trigger, and choose Save to save the release pipeline.
Select Create Release -> Create to manually create a release. You can monitor the release progress in the Releases tab.
Verify that the deployment succeeded and that the application is running in the cluster. Open a web browser and navigate to https://mysftestcluster.southcentralus.cloudapp.azure.com:19080/Explorer/. Note the application version. In this example, it's 1.0.0.20170616.3
.
Commit and push changes, trigger a release
To verify that the continuous integration pipeline is functioning by checking in some code changes to Azure DevOps.
As you write your code, Visual Studio keeps track of the file changes to your project in the Changes section of the Git Changes window.
On the Changes view, add a message describing your update and commit your changes.
In the Git Changes window, select Push button (the up arrow) to update code in Azure Pipelines.
Pushing the changes to Azure Pipelines automatically triggers a build. To check your build progress, switch to Pipelines tab in https://dev.azure.com/organizationname/VotingSample.
When the build completes, a release is automatically created and starts upgrading the application on the cluster.
Verify that the deployment succeeded and that the application is running in the cluster. Open a web browser and navigate to https://mysftestcluster.southcentralus.cloudapp.azure.com:19080/Explorer/
. Note the application version. In this example, it's 1.0.0.20170815.3
.
Update the application
Make code changes in the application. Save and commit the changes, following the previous steps.
Once the upgrade of the application begins, you can watch the upgrade progress in Service Fabric Explorer:
The application upgrade might take several minutes. When the upgrade is complete, the application will be running the next version. In this example 1.0.0.20170815.4
.
Next steps
In this tutorial, you learned how to:
- Add source control to your project
- Create a build pipeline
- Create a release pipeline
- Automatically deploy and upgrade an application
Advance to the next tutorial:
Feedback
https://aka.ms/ContentUserFeedback.
În curând: Pe parcursul anului 2024, vom elimina treptat Probleme legate de GitHub ca mecanism de feedback pentru conținut și îl vom înlocui cu un nou sistem de feedback. Pentru mai multe informații, consultați:Trimiteți și vizualizați feedback pentru