从 Azure 管道将 Spring Boot Gradle 应用程序部署到 Azure 应用服务

时间:2021-02-15 09:30:13

标签: spring-boot azure-devops azure-web-app-service azure-pipelines azure-pipelines-yaml

我无法从 YAML Azure Pipeline 将简单的 Spring Boot jar 应用程序部署到 Azure 应用服务。

这是我的 Deploy 阶段,我在上面下载了之前构建的 jar 并设置了 StartupCommand 以针对下载的 jar 运行 java -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,我唯一能看到的就是这个屏幕:

enter image description here

我在这里遗漏了什么?

2 个答案:

答案 0 :(得分:0)

查看此官方博客:https://azuredevopslabs.com/labs/vstsextend/dockerjava/,似乎您需要将war包的名称附加到URL中的Web应用程序上下文路径才能到达应用程序主页。例如,如果我们构建此应用程序,然后发布此工件:helloworld.war。部署成功后,app的url应该是http://{your web app name}.azurewebsites.net/helloworld。也可以到http://{your web app name}.scm.azurewebsites.net查看代码是否部署成功。

此外,您还可以在 Azure 门户中使用 DevOps Starter 服务,该服务可帮助您在 Azure 门户中只需几个快速步骤即可在您选择的 Azure 服务上启动您喜爱的应用。

DevOps Starter 设置了开发、部署和监控应用程序所需的一切。请参阅此文档:Set up a CI/CD pipeline for a Java app with Azure DevOps Starter 以获得指导。

答案 1 :(得分:0)

问题是工件被命名为 {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 /)