0
votes

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

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'
        

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.

Here's the full startup log:

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 ---

UPDATE:

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'           

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.

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

enter image description here

What am I missing here?

2

2 Answers

0
votes

Reviewing this official blog: https://azuredevopslabs.com/labs/vstsextend/dockerjava/, it seems that you need to append the name of war package to the web application context path in the URL to get to the app home page. For example, if we build this application and then publish this artifact: helloworld.war. After deploying it successfully, the url of app should be http://{your web app name}.azurewebsites.net/helloworld. Also you could go to http://{your web app name}.scm.azurewebsites.net to check whether code is deployed successfully or not.

In addition, you could also use DevOps Starter service in Azure portal, which helps you launch your favorite app on the Azure service of your choice in just a few quick steps from the Azure portal.

DevOps Starter sets up everything you need for developing, deploying, and monitoring your application. See this doc: Set up a CI/CD pipeline for a Java app with Azure DevOps Starter for guidance.

0
votes

The problem was that the artifact was named {artifactId}-{version}.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 /)