Azure / spring-apps-deploy

GitHub Actions to deploy to Azure Spring Cloud
MIT License
12 stars 9 forks source link

Support for Java 17 and Spring Boot 3 #22

Closed felipmiguel closed 1 year ago

felipmiguel commented 1 year ago

I have a Java 17/Spring Boot 3 application that I'm able to deploy to Azure Spring Apps using Azure cli.

I prepared a deployment using Actions and I can specify Java_17 as runtime.

- name: Deploy api-gateway
      uses: azure/spring-apps-deploy@v1
      with:
        azure-subscription: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
        action: deploy
        service-name: ${{ secrets.SPRING_APPS_SERVICE_NAME }}
        app-name: ${{ env.API_GATEWAY }}
        use-staging-deployment: false
        package: ${{ github.workspace }}/${{ env.API_GATEWAY_JAR }}
        jvm-options: -Xms2048m -Xmx2048m
        runtime-version: Java_17
        environment-variables: -SPRING_PROFILES_ACTIVE passwordless

There is no validation issues on the action, but the deployment fails. Here the logs on the application side:

Build in Environment Variables
BUILD_IN_EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=https://fmiguel-spring-petclinic.svc.azuremicroservices.io/eureka/eureka
BUILD_IN_SPRING_CLOUD_CONFIG_URI=https://fmiguel-spring-petclinic.svc.azuremicroservices.io/config
BUILD_IN_SPRING_CLOUD_CONFIG_FAILFAST=true
[Azure Spring Cloud] The following environment variables are loaded: SPRING_PROFILES_ACTIVE
Picked up JAVA_TOOL_OPTIONS:  -Xms2048m -Xmx2048m
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2023-01-16 10:28:25.157Z INFO  c.m.applicationinsights.agent - Application Insights Java Agent 3.4.4 started successfully (PID 1, JVM running for 9.397 s)
2023-01-16 10:28:25.232Z INFO  c.m.applicationinsights.agent - Java version: 17.0.5, vendor: Microsoft, home: /usr/lib/jvm/msopenjdk-17
10:28:36.658 [main] DEBUG org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - Application failed to start due to an exception
java.lang.NoSuchMethodError: 'org.springframework.http.HttpStatus org.springframework.http.ResponseEntity.getStatusCode()'
        at com.microsoft.azure.telemetry.TelemetrySender.sendTelemetryData(TelemetrySender.java:58)
        at com.microsoft.azure.telemetry.TelemetrySender.send(TelemetrySender.java:74)
        at com.microsoft.azure.keyvault.spring.KeyVaultEnvironmentPostProcessorHelper.sendTelemetry(KeyVaultEnvironmentPostProcessorHelper.java:219)
        at com.microsoft.azure.keyvault.spring.KeyVaultEnvironmentPostProcessorHelper.<init>(KeyVaultEnvironmentPostProcessorHelper.java:56)
        at com.microsoft.azure.keyvault.spring.KeyVaultEnvironmentPostProcessor.postProcessEnvironment(KeyVaultEnvironmentPostProcessor.java:40)
        at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:109)
        at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:94)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
        at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
        at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
        at java.base/java.lang.Iterable.forEach(Iterable.java:75)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
        at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:352)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1291)
        at org.springframework.samples.petclinic.api.ApiGatewayApplication.main(ApiGatewayApplication.java:50)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:95)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
10:28:36.733 [main] ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter -

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    com.microsoft.azure.telemetry.TelemetrySender.sendTelemetryData(TelemetrySender.java:58)

The following method did not exist:

    'org.springframework.http.HttpStatus org.springframework.http.ResponseEntity.getStatusCode()'

The calling method's class, com.microsoft.azure.telemetry.TelemetrySender, was loaded from the following location:

    jar:file:/tmp/668c2a7f-89a0-4710-af05-68fdde4720c9!/BOOT-INF/lib/azure-spring-boot-2.3.0.jar!/com/microsoft/azure/telemetry/TelemetrySender.class

The called method's class, org.springframework.http.ResponseEntity, is available from the following locations:

    jar:file:/tmp/668c2a7f-89a0-4710-af05-68fdde4720c9!/BOOT-INF/lib/spring-web-6.0.3.jar!/org/springframework/http/ResponseEntity.class

The called method's class hierarchy was loaded from the following locations:

    org.springframework.http.ResponseEntity: jar:file:/tmp/668c2a7f-89a0-4710-af05-68fdde4720c9!/BOOT-INF/lib/spring-web-6.0.3.jar!/
    org.springframework.http.HttpEntity: jar:file:/tmp/668c2a7f-89a0-4710-af05-68fdde4720c9!/BOOT-INF/lib/spring-web-6.0.3.jar!/

Action:

Correct the classpath of your application so that it contains compatible versions of the classes com.microsoft.azure.telemetry.TelemetrySender and org.springframework.http.ResponseEntity

Deploying the same application using Azure cli (2.44.0) works.

az spring app deploy  \
  --resource-group ${RESOURCE_GROUP} \
  --service ${SPRING_CLOUD_SERVICE} \
  --name ${API_GATEWAY} \
  --artifact-path ${API_GATEWAY_JAR} \
  --jvm-options='-Xms2048m -Xmx2048m' \
  --runtime-version Java_17 \
  --env SPRING_PROFILES_ACTIVE=passwordless

Is there any library on the Github Action side that needs to be upgraded?

seanli1988 commented 1 year ago

@felipmiguel , please create an issue in azure spring apps https://github.com/Azure/Azure-Spring-Apps/issues

felipmiguel commented 1 year ago

After reviewing the solution I realized that the version deployed with azure cli and the version deployed with github actions are not exactly the same. The failing version included an old version for one of the dependencies. Removing that dependency fixed the issue.