Oliver Watkins
Oliver Watkins

Reputation: 13519

Cannot deploy spring apps to Azure

I am trying to deploy my application.

In theory, it is incredibly simple what I want to do :

I basically already have a spring boot app running on Azure called shape-shop. Locally I have made some tiny change to shape-shop and I want to deploy this to Azure.

Now I simply want to replace the currently running in azure JAR file with the newly created JAR file.

I perform mvn clean package -DskipTests=true

I then want to deploy it, and run this command :

C:\dev\shape-shop-back-end>az spring app deploy --resource-group shapeShopResourceGroup --service shapeshop2 --name shape-shop-app --artifact-path target/shape-shop-backend-0.1.0.jar
This command usually takes minutes to run. Add '--verbose' parameter if needed.
[1/3] Requesting for upload URL.
[2/3] Uploading package to blob.
[3/3] Updating deployment in app "shape-shop-app" (this operation can take a while to complete)
Your application failed to start, please check the logs of your application.

But I get the "application failed to start" error.

resourcegroup, service, and name all seem to be correct.

enter image description here

I also notice in azure, that my spring boot app live production has died (which is terrible). Whatever issues I may have with my deployment, I do not want it to destroy my live production instance!

enter image description here

If I look further into the documentation (which is very poor) for deploying spring boot apps to azure, it seems to suggest using some kind of "Maven Plugin for Azure Spring Apps", which I am very uncomfortable about because what I want to do is very simple and I would assume that it would be some simple "az deploy" command that I would need to run. I do not want to have to install something else now.

But anyway, I go ahead and paste in this :

<pluginRepositories>
    <pluginRepository>
        <id>maven.snapshots</id>
        <name>Maven Central Snapshot Repository</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        <releases>
            <enabled>false</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

and then run this :

mvn com.microsoft.azure:azure-spring-apps-maven-plugin:1.10.0:config

and then after 10 minutes of things getting downloaded, I get this error :

enter image description here

Can anyone help here with the multiple issues I have with azure-spring-boot? Is it worth switching to something like AWS for spring boot apps, because deployment of spring boot apps in azure seem dangerously unreliable and bizarrely complex.

Upvotes: 0

Views: 330

Answers (1)

Pravallika KV
Pravallika KV

Reputation: 8541

When I tried to deploy my spring application to existing Azure Spring Apps with Standard consumption & dedicated (preview) plan, I was facing the issues.

enter image description here

I followed below steps to deploy the application successfully to Azure Spring Apps.

  • Created a demo spring application and ran the below commands:
mvn clean package
mvn spring-boot:run
  • Build the artifacts of your application and configure the deployment with the Azure spring apps maven dependency.
  • Deployed the application to a new spring app and new app created with Standard Pricing Plan using the command.
mvn com.microsoft.azure:azure-spring-apps-maven-plugin:1.19.0:config
  • could deploy to the app with Basic Plan as well.
C:\Users\usern\gs-spring-boot-for-azure\complete>mvn com.microsoft.azure:azure-spring-apps-maven-plugin:1.19.0:config
[INFO] Scanning for projects...
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building boot-for-azure 0.0.1-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] --- azure-spring-apps:1.19.0:config (default-cli) @ demo ---
[INFO] Auth type: AZURE_CLI
[INFO] Username: username.com
Available subscription:

// lists all the subscriptions

Select subscription [1-31] (8):
[INFO] Subscription: Azure CXP Community Internal Consumption(b83c1ed3-c5b6-44fb-b5ba-2b83a074c23f)
Use existing Azure Spring Apps in Azure (Y/n):n
Input the Azure Spring Apps name (cluster-demo):kpnewspringapp
Input the resource group name (rg-demo):<resource-group>
Skus:
 1. Basic*
 2. Standard
 3. Enterprise
Select sku for Azure Spring Apps: [1-3] (1): 2
Input the app name (demo):<application_name>//(existing/new)
[INFO] There is only one valid runtime (Java 17) for your project, will use it automatically.
Expose public access for this app (boot-for-azure)? (y/N):y
Summary of properties:
Subscription id   : b83c1ed3-c5b6-44fb-b5ba-2b83a074c23f
Resource group name : <resource_group_name>
Azure Spring Apps name : <your_springapp_name>
Runtime Java version : Java 17
Region            : eastus
Sku               : Standard
App name          : <app_name>
Public access     : true
Instance count/max replicas : 1
CPU count         : 1
Memory size(GB)   : 2
Confirm to save all the above configurations (Y/n):
[INFO] Configurations are saved to: C:\Users\usern\gs-spring-boot-for-azure\complete\pom.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  03:04 min
[INFO] Finished at: 2024-01-19T10:55:10+05:30
[INFO] ------------------------------------------------------------------------

This configuration for deployment will be added to pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.0</version>
        <relativePath/>
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>boot-for-azure</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-spring-apps-maven-plugin</artifactId>
                <version>1.19.0</version>
                <configuration>
                    <subscriptionId>b83c1ed3-c5b6-44fb-b5ba-2b83a074c23f</subscriptionId>
                    <resourceGroup>rgname</resourceGroup>
                    <clusterName>springappname</clusterName>
                    <region>eastus</region>
                    <sku>Standard</sku>
                    <appName>app_name</appName>
                    <isPublic>true</isPublic>
                    <deployment>
                        <cpu>1</cpu>
                        <memoryInGB>2</memoryInGB>
                        <instanceCount>1</instanceCount>
                        <runtimeVersion>Java 17</runtimeVersion>
                        <resources>
                            <resource>
                                <directory>${project.basedir}/target</directory>
                                <includes>
                                    <include>*.jar</include>
                                </includes>
                            </resource>
                        </resources>
                    </deployment>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
  • Deploy the application to Azure using the below command:
mvn azure-spring-apps:deploy

enter image description here

Portal:

enter image description here

Response:

enter image description here

Upvotes: 1

Related Questions