spring-boot - 从 Azure Pipeline 将 Spring Boot Gradle 应用程序部署到 Azure 应用服务
问题描述
我无法从 YAML Azure Pipeline 将简单的 Spring Boot jar 应用程序部署到 Azure App Services。
这是我的 Deploy 阶段,在它上面我下载了以前构建的 jar 并设置 StartupCommand 以java -jar
针对下载的 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'
它失败了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
任务中有一些更新:
- 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'
有了这个,检查应用服务日志,它似乎正在部署应用程序:
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,我唯一能看到的是这个屏幕:
我在这里想念什么?
解决方案
问题是工件被命名为 {artifactId}-{version}.jar。
将其更改为 app.jar 后,应用程序部署成功。我app.jar
在文档的某些部分看到了这个名字,但找不到明确表示它必须这样命名的东西。
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 /)
推荐阅读
- java - gson : 将空字符串视为 null
- javascript - JS函数设置addEventListeners太多
- swift - 如何在 swift mac 应用程序中订阅全局触控板触摸事件?
- python - python中的变量扩展可以像变量的shell扩展一样工作吗
- django - 带有多个外键表单的页面
- excel - 我做了一个子函数但得到一个错误,怎么了?
- asp.net - 选中复选框时,ASP.Net onclick 未触发
- pyspark - 有没有办法在 PySpark 中使用 Impala 而不是 Hive?
- python - 在 python 中使用经度和纬度数据可视化 DBSCAN 集群和半径
- javascript - ZingChart X 轴标签的间距不均匀