从Azure管道将Spring Boot Gradle应用程序部署到Azure App Service [英] Deploy a Spring Boot Gradle application to Azure App Service from an Azure Pipeline

本文介绍了从Azure管道将Spring Boot Gradle应用程序部署到Azure App Service的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从YAML Azure管道将简单的Spring Boot jar应用程序部署到Azure App Services.

I'm having trouble deploying a simple Spring Boot jar application to Azure App Services from a YAML Azure Pipeline.

这是我的Deploy阶段,在该阶段上,我下载先前构建的jar并设置StartupCommand以对下载的jar运行 java -jar :

Here's my Deploy stage, on it I download the previously built jar and set up the StartupCommand to run java -jar against the downloaded jar:

  - stage: Deploy_Staging
    pool:
      vmImage: ubuntu-latest
    jobs:
      - job: deploy
        steps:
        - script: find ./
        - task: DownloadBuildArtifacts@0
          inputs:
            buildType: 'current'
            downloadType: 'single'
            artifactName: 'drop'
            downloadPath: '$(System.ArtifactsDirectory)'
        - script: 'find $(System.ArtifactsDirectory)'
        - task: AzureRmWebAppDeployment@4
          inputs:
            ConnectionType: 'AzureRM'
            azureSubscription: 'Free Trial(xxx)'
            appType: 'webAppLinux'
            WebAppName: 'sleuth-kafka-streams'
            packageForLinux: '$(System.ArtifactsDirectory)/**/*.jar'
            RuntimeStack: 'JAVA|11-java11'
            StartupCommand: 'java - jar $(System.ArtifactsDirectory)/drop/build/libs/sleuth-kafka-streams-0.0.1-SNAPSHOT.jar'
        

它失败并显示以下代码:运行启动命令'java-jar/home/vsts/work/1/a/drop/build/libs/sleuth-kafka-streams-0.0.1-SNAPSHOT.jar'完成.以退出代码1退出.

It fails with Finished running startup command 'java - jar /home/vsts/work/1/a/drop/build/libs/sleuth-kafka-streams-0.0.1-SNAPSHOT.jar'. Exiting with exit code 1.

这是完整的启动日志:

2021-02-15T09:26:01  Welcome, you are now connected to log-streaming service.
Starting Log Tail -n 10 of existing logs ----
/home/LogFiles/__lastCheckTime.txt  (https://sleuth-kafka-streams.scm.azurewebsites.net/api/vfs/LogFiles/__lastCheckTime.txt)02/15/2021 09:25:47
/home/LogFiles/kudu/trace/00f323152028-d712e8d7-342f-4138-bece-0abcf8da5026.txt  (https://sleuth-kafka-streams.scm.azurewebsites.net/api/vfs/LogFiles/kudu/trace/00f323152028-d712e8d7-342f-4138-bece-0abcf8da5026.txt)
2021-02-15T08:41:30  Startup Request, url: /api/vfs/site/wwwroot/?_=1613378228250, method: GET, type: request, pid: 178,1,5, ScmType: None
/home/LogFiles/kudu/trace/664006eb122a-bf88ab71-7fdc-4025-b8a4-912c118c3c6d.txt  (https://sleuth-kafka-streams.scm.azurewebsites.net/api/vfs/LogFiles/kudu/trace/664006eb122a-bf88ab71-7fdc-4025-b8a4-912c118c3c6d.txt)
2021-02-15T08:53:24  Startup Request, url: /api/deployments/d34ef8aaeda34816930a48ebf3e1e8bc/log, method: GET, type: request, pid: 130,1,5, ScmType: VSTSRM
/home/LogFiles/kudu/trace/7fa2def72fc8-40194c95-7fa0-4afe-9be4-bdf9b1787208.txt  (https://sleuth-kafka-streams.scm.azurewebsites.net/api/vfs/LogFiles/kudu/trace/7fa2def72fc8-40194c95-7fa0-4afe-9be4-bdf9b1787208.txt)
2021-02-15T08:58:37  Startup Request, url: /api/logstream/, method: GET, type: request, pid: 133,1,4, ScmType: VSTSRM
/home/LogFiles/2021_02_15_lw1sdlwk000012_default_docker.log  (https://sleuth-kafka-streams.scm.azurewebsites.net/api/vfs/LogFiles/2021_02_15_lw1sdlwk000012_default_docker.log)
2021-02-15T09:25:56.424172424Z STARTUP_FILE=
2021-02-15T09:25:56.424846518Z STARTUP_COMMAND=java - jar /home/vsts/work/1/a/drop/build/libs/sleuth-kafka-streams-0.0.1-SNAPSHOT.jar
2021-02-15T09:25:56.431061668Z No STARTUP_FILE available.
2021-02-15T09:25:56.440223495Z Running STARTUP_COMMAND: java - jar /home/vsts/work/1/a/drop/build/libs/sleuth-kafka-streams-0.0.1-SNAPSHOT.jar
2021-02-15T09:25:57.700920721Z Picked up JAVA_TOOL_OPTIONS: -Djava.net.preferIPv4Stack=true
2021-02-15T09:25:57.701975512Z Unrecognized option: -
2021-02-15T09:25:57.702641307Z Error: Could not create the Java Virtual Machine.
2021-02-15T09:25:57.702657307Z Error: A fatal exception has occurred. Program will exit.
2021-02-15T09:25:57.719490372Z Finished running startup command 'java - jar /home/vsts/work/1/a/drop/build/libs/sleuth-kafka-streams-0.0.1-SNAPSHOT.jar'. Exiting with exit code 1.
/home/LogFiles/2021_02_15_lw1sdlwk000012_docker.log  (https://sleuth-kafka-streams.scm.azurewebsites.net/api/vfs/LogFiles/2021_02_15_lw1sdlwk000012_docker.log)
2021-02-15T09:25:47.846Z INFO  -  Digest: sha256:f7afa8c056821cbd51789f0f78b28f7ef412ce4c70c382a4fbabcedcbce7f4e5
2021-02-15T09:25:47.846Z INFO  -  Status: Image is up to date for mcr.microsoft.com/azure-app-service/java:11-java11_200319054033
2021-02-15T09:25:47.849Z INFO  - Pull Image successful, Time taken: 0 Minutes and 0 Seconds
2021-02-15T09:25:47.891Z INFO  - Starting container for site
2021-02-15T09:25:47.891Z INFO  - docker run -d -p 10046:80 --name sleuth-kafka-streams_0_bee3ce4f -e WEBSITE_SITE_NAME=sleuth-kafka-streams -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=sleuth-kafka-streams.azurewebsites.net -e WEBSITE_INSTANCE_ID=b08b793703ed90c29d190499db3bc194822d9b232329810c8844678e66822c18 -e HTTP_LOGGING_ENABLED=1 mcr.microsoft.com/azure-app-service/java:11-java11_200319054033 java - jar /home/vsts/work/1/a/drop/build/libs/sleuth-kafka-streams-0.0.1-SNAPSHOT.jar
2021-02-15T09:25:51.212Z INFO  - Initiating warmup request to container sleuth-kafka-streams_0_bee3ce4f for site sleuth-kafka-streams
2021-02-15T09:25:58.936Z ERROR - Container sleuth-kafka-streams_0_bee3ce4f for site sleuth-kafka-streams has exited, failing site start
2021-02-15T09:25:58.944Z ERROR - Container sleuth-kafka-streams_0_bee3ce4f didn't respond to HTTP pings on port: 80, failing site start. See container logs for debugging.
2021-02-15T09:25:58.966Z INFO  - Stopping site sleuth-kafka-streams because it failed during startup.
/home/LogFiles/webssh/pm2.log  (https://sleuth-kafka-streams.scm.azurewebsites.net/api/vfs/LogFiles/webssh/pm2.log)
Ending Log Tail of existing logs ---
Starting Live Log Stream ---

更新:

我进步了一点,在 AzureRmWebAppDeployment 任务中进行了一些更新:

I progressed a bit, with some updates in the AzureRmWebAppDeployment task:

            - task: AzureRmWebAppDeployment@4
                inputs:
                  ConnectionType: 'AzureRM'
                  azureSubscription: 'Free Trial(xxx)'
                  appType: 'webAppLinux'
                  WebAppName: 'sb-hello-azure'
                  packageForLinux: '$(System.DefaultWorkingDirectory)/drop/**/*.jar'
                  RuntimeStack: 'JAVA|11-java11'
                  WebConfigParameters: '-JAR_PATH D:\home\site\wwwroot\*.jar -ADDITIONAL_DEPLOYMENT_OPTIONS ''-Dserver.port=%HTTP_PLATFORM_PORT%'' -appType Java_SpringBoot'           

使用此方法,检查App Service日志似乎正在部署该应用程序:

With this, checking the App Service logs it seems to be deploying the application:

2021-02-15T20:59:39.713Z INFO  - Initiating warmup request to container sb-hello-azure_2_914de81c for site sb-hello-azure
2021-02-15T20:59:41.635Z INFO  - Pulling image from Docker hub: mcr.microsoft.com/azure-app-service/java:11-java11_200319054033
2021-02-15T20:59:41.700Z INFO  - 11-java11_200319054033 Pulling from azure-app-service/java
2021-02-15T20:59:41.700Z INFO  -  Digest: sha256:f7afa8c056821cbd51789f0f78b28f7ef412ce4c70c382a4fbabcedcbce7f4e5
2021-02-15T20:59:41.701Z INFO  -  Status: Image is up to date for mcr.microsoft.com/azure-app-service/java:11-java11_200319054033
2021-02-15T20:59:41.703Z INFO  - Pull Image successful, Time taken: 0 Minutes and 0 Seconds
2021-02-15T20:59:41.737Z INFO  - Starting container for site
2021-02-15T20:59:41.743Z INFO  - docker run -d -p 2669:80 --name sb-hello-azure_1_f78e773e -e WEBSITE_SITE_NAME=sb-hello-azure -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=sb-hello-azure.azurewebsites.net -e WEBSITE_INSTANCE_ID=e1e87e7fa56e45aab977a8209864dccda91aa35bff07c18a350bd334691fb981 -e HTTP_LOGGING_ENABLED=1 mcr.microsoft.com/azure-app-service/java:11-java11_200319054033
2021-02-15T20:59:45.772Z INFO  - Container sb-hello-azure_2_914de81c for site sb-hello-azure initialized successfully and is ready to serve requests.

调用服务URL,唯一可以看到的是此屏幕:

Calling the service URL, the only thing I can see is this screen:

我在这里想念什么?

推荐答案

问题是工件被命名为{artifactId}-{version} .jar.

The problem was that the artifact was named {artifactId}-{version}.jar.

将其更改为app.jar后,应用程序将成功部署.我在文档的某些部分看到了这个 app.jar 名称的提示,但是找不到明确表示必须如此命名的名称.

After changing it to be app.jar the application deploys successfully. I got a hint seeing this app.jar name in some parts of the documentation, but couldn't find something that explicitly said it had to be named like that though.

tasks.bootJar {
    archiveFileName.set("app.jar")
}

2021-02-16T08:08:39.961599574Z Picked up JAVA_TOOL_OPTIONS: -Djava.net.preferIPv4Stack=true
2021-02-16T08:08:53.965933557Z
2021-02-16T08:08:53.967247109Z   .   ____          _            __ _ _
2021-02-16T08:08:53.968059841Z  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
2021-02-16T08:08:53.968470257Z ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2021-02-16T08:08:53.970914553Z  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
2021-02-16T08:08:53.970942254Z   '  |____| .__|_| |_|_| |_\__, | / / / /
2021-02-16T08:08:53.971029758Z  =========|_|==============|___/=/_/_/_/
2021-02-16T08:08:53.975294826Z  :: Spring Boot ::                (v2.4.2)
2021-02-16T08:08:53.978922169Z
2021-02-16T08:08:54.785119742Z 2021-02-16 08:08:54.751  INFO 124 --- [           main] c.c.helloazure.HelloAzureApplicationKt   : Starting HelloAzureApplicationKt using Java 11.0.6 on f4473caaa0f3 with PID 124 (/local/site/wwwroot/app.jar started by root in /)

这篇关于从Azure管道将Spring Boot Gradle应用程序部署到Azure App Service的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆