Събитие
Създаване на AI приложения и агенти
17.03, 21 ч. - 21.03, 10 ч.
Присъединете се към поредицата срещи, за да изградите мащабируеми AI решения, базирани на реални случаи на употреба с колеги разработчици и експерти.
Регистрирайте се сегаТози браузър вече не се поддържа.
Надстройте до Microsoft Edge, за да се възползвате от най-новите функции, актуализации на защитата и техническа поддръжка.
Бележка
Azure Spring Apps is the new name for the Azure Spring Cloud service. Although the service has a new name, you'll see the old name in some places for a while as we work to update assets such as screenshots, videos, and diagrams.
Azure Spring Apps is a fully managed microservice development with built-in service discovery and configuration management. The service makes it easy to deploy Spring Boot-based microservice applications to Azure. This tutorial demonstrates how you can use Azure CLI in Jenkins to automate continuous integration and delivery (CI/CD) for Azure Spring Apps.
In this tutorial, you'll complete these tasks:
We use Piggy Metrics as the sample Microsoft service application and follow the same steps in Quickstart: Launch a Java Spring application using the Azure CLI to provision the service instance and set up the applications. If you've already gone through the same process, you can skip to the next section. Otherwise, included in the following are the Azure CLI commands. Refer to Quickstart: Launch a Java Spring application using the Azure CLI to get more information.
Your local machine needs to meet the same prerequisite as the Jenkins build server. Make sure the following are installed to build and deploy the microservice applications:
Install the Azure Spring Apps extension:
az extension add --name spring
Create a resource group to contain your Azure Spring Apps service:
az group create --location eastus --name <resource group name>
Provision an instance of Azure Spring Apps:
az spring create -n <service name> -g <resource group name>
Fork the Piggy Metrics repo to your own GitHub account. In your local machine, clone your repo in a directory called source-code
:
mkdir source-code
git clone https://github.com/<your GitHub id>/piggymetrics
Set up your configuration server. Make sure you replace <your GitHub id> with the correct value.
az spring config-server git set -n <your-service-name> --uri https://github.com/<your GitHub id>/piggymetrics --label config
Build the project:
cd piggymetrics
mvn clean package -D skipTests
Create the three microservices: gateway, auth-service, and account-service:
az spring app create --n gateway -s <service name> -g <resource group name>
az spring app create --n auth-service -s <service name> -g <resource group name>
az spring app create --n account-service -s <service name> -g <resource group name>
Deploy the applications:
az spring app deploy -n gateway -s <service name> -g <resource group name> --jar-path ./gateway/target/gateway.jar
az spring app deploy -n account-service -s <service name> -g <resource group name> --jar-path ./account-service/target/account-service.jar
az spring app deploy -n auth-service -s <service name> -g <resource group name> --jar-path ./auth-service/target/auth-service.jar
Assign public endpoint to gateway:
az spring app update -n gateway -s <service name> -g <resource group name> --is-public true
Query the gateway application to get the url so that you can verify that the application is running.
az spring app show --name gateway | grep url
Navigate to the URL provided by the previous command to run the PiggyMetrics application.
In this section, you prepare the Jenkins server to run a build, which is fine for testing. However, because of security implication, you should use an Azure VM agent or Azure Container agent to spin up an agent in Azure to run your builds.
Log in to your Jenkins server.
Select Manage Jenkins.
Select Manage Plugins.
On the Available tab, select the following plug-ins:
If these plug-ins don't appear in the list, check the Installed tab to see if they're already installed.
To install the plug-ins, select Download now and install after restart.
Restart your Jenkins server to complete the installation.
You need an Azure Service Principal to deploy to Azure. For more information, see the Create service principal section in the Deploy to Azure App Service tutorial. The output from az ad sp create-for-rbac
looks something like this:
{
"appId": "xxxxxx-xxx-xxxx-xxx-xxxxxxxxxxxx",
"displayName": "xxxxxxxjenkinssp",
"name": "http://xxxxxxxjenkinssp",
"password": "xxxxxx-xxx-xxxx-xxx-xxxxxxxxxxxx",
"tenant": "xxxxxx--xxx-xxxx-xxx-xxxxxxxxxxxx"
}
On the Jenkins dashboard, select Credentials > System. Then, select Global credentials(unrestricted).
Select Add Credentials.
Select Microsoft Azure Service Principal as kind.
Supply values for the following fields:
azure_service_principal
. We use this ID in a later step in this articleThe sample pipeline uses Maven to build and Azure CLI to deploy to the service instance. When Jenkins is installed, it creates an admin account named jenkins. Ensure that the user jenkins has permission to run the spring extension.
Connect to the Jenkins controller via SSH.
Install Maven.
sudo apt-get install maven
Verify that the Azure CLI is installed by entering az version
. If the Azure CLI isn't installed, see Installing the Azure CLI.
Switch to the jenkins
user:
sudo su jenkins
Install the spring extension:
az extension add --name spring
In your own repo - https://github.com/your_github_id/piggymetrics
- create a Jenkinsfile in the root.
Update the file as follows. Make sure you replace the values of <resource group name> and <service name>. Replace azure_service_principal with the right ID if you use a different value when you added the credential in Jenkins.
node {
stage('init') {
checkout scm
}
stage('build') {
sh 'mvn clean package'
}
stage('deploy') {
withCredentials([azureServicePrincipal('azure_service_principal')]) {
// Log in to Azure
sh '''
az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET -t $AZURE_TENANT_ID
az account set -s $AZURE_SUBSCRIPTION_ID
'''
// Set default resource group name and service name. Replace <resource group name> and <service name> with the right values
sh 'az config set defaults.group=<resource group name>'
sh 'az config set defaults.spring=<service name>'
// Deploy applications
sh 'az spring app deploy -n gateway --jar-path ./gateway/target/gateway.jar'
sh 'az spring app deploy -n account-service --jar-path ./account-service/target/account-service.jar'
sh 'az spring app deploy -n auth-service --jar-path ./auth-service/target/auth-service.jar'
sh 'az logout'
}
}
}
Save and commit the change.
On the Jenkins dashboard, select New Item.
Provide a name, Deploy-PiggyMetrics for the job and select Pipeline. Click OK.
Select the Pipeline tab.
For Definition, select Pipeline script from SCM.
For SCM, select Git.
Enter the GitHub URL for your forked repo: https://github.com/<your GitHub id>/piggymetrics.git
.
For Branch Specifier (black for 'any'), select /Azure.
For Script path, select Jenkinsfile.
Select Save
Before running the job, edit the text in the login input box to enter login ID.
In your repo, open index.html
in /gateway/src/main/resources/static/
.
Search for enter your login
and update that text to enter login ID
.
<input class="frontforms" id="frontloginform" name="username" placeholder="enter login ID" type="text" autocomplete="off"/>
Save and commit the change.
Run the job in Jenkins manually. On the Jenkins dashboard, select the job Deploy-PiggyMetrics
and then select Build Now.
After the job is complete, navigate to the public IP of the gateway
application and verify that your application has been updated.
When no longer needed, delete the resources created in this article:
az group delete -y --no-wait -n <resource group name>
Събитие
Създаване на AI приложения и агенти
17.03, 21 ч. - 21.03, 10 ч.
Присъединете се към поредицата срещи, за да изградите мащабируеми AI решения, базирани на реални случаи на употреба с колеги разработчици и експерти.
Регистрирайте се сегаОбучение
Модул
Deploy Spring microservices to Azure - Training
Learn how to deploy Spring Boot microservices to Azure Spring Apps (ASA).
Сертифициране
Microsoft Certified: Azure Developer Associate - Certifications
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.