Deploy spring boots application to AWS GAE Azure

Deploy spring boots application to AWS GAE Azure

七月 05, 2019

In this tutorial, we’ll show how to deploy an application from Spring Boot to Google App Engine, AWS Elastic Beanstalk and Microsoft Azure.

Deploy to Google App Engine

Documentation from google

  1. Create a Google Account

  2. Create a project

  3. Install google cloud sdk in local machine

  4. Login your google account in local terminal

    1
    gcloud auth Login
  5. Set your prject.

    1
    gcloud config set project <PROJECT_ID>
  6. Create a spring boots project

  7. Add maven plugin

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <plugin> 
    <groupId>com.google.cloud.tools</groupId>
    <artifactId>appengine-maven-plugin</artifactId>
    <version>2.0.0</version>
    <configuration>
    <deploy.projectId>dualshield-push-notification</deploy.projectId>
    <version>1</version>
    <port>8080</port>
    </configuration>
    </plugin>
  8. Add Appengine Engine Descrptor

src/main/webapp/WEB-INF/appengine-web.xml

1
2
3
4
5
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>{PROJECT_ID}</application>
<threadsafe>true</threadsafe>
<runtime>java8</runtime>
</appengine-web-app>
  1. Deploy
    1
    mvn clean package appengine:deploy

Deploy to AWS Elastic Beanstalk

Documentation from Amazon

  1. Install AWS CLI tools.https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html

  2. Create a spring boot project

  3. eb init //execute in your project

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    [steven@mysql deepnet-push-notification]$ eb init

    Select a default region
    1) us-east-1 : US East (N. Virginia)
    2) us-west-1 : US West (N. California)
    3) us-west-2 : US West (Oregon)
    4) eu-west-1 : EU (Ireland)
    5) eu-central-1 : EU (Frankfurt)
    6) ap-south-1 : Asia Pacific (Mumbai)
    7) ap-southeast-1 : Asia Pacific (Singapore)
    8) ap-southeast-2 : Asia Pacific (Sydney)
    9) ap-northeast-1 : Asia Pacific (Tokyo)
    10) ap-northeast-2 : Asia Pacific (Seoul)
    11) sa-east-1 : South America (Sao Paulo)
    12) cn-north-1 : China (Beijing)
    13) cn-northwest-1 : China (Ningxia)
    14) us-east-2 : US East (Ohio)
    15) ca-central-1 : Canada (Central)
    16) eu-west-2 : EU (London)
    17) eu-west-3 : EU (Paris)
    18) eu-north-1 : EU (Stockholm)
    19) ap-east-1 : Asia Pacific (Hong Kong)
    (default is 3): 16

    Select an application to use
    1) deepnet-push-notification
    2) [ Create new Application ]
    (default is 1): 1
    Do you wish to continue with CodeCommit? (y/N) (default is n): n
  4. Add a beanstalk-specifig maven profile to pom.xml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <profile>
    <id>beanstalk</id>
    <build>
    <finalName>${project.name}</finalName>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
    <excludes>
    <exclude>**/cloud/config/*.java</exclude>
    </excludes>
    </configuration>
    </plugin>
    </plugins>
    </build>
    </profile>
  5. specify the artifact into the Elastic Beanstalk configuration file .elasticbeanstalk/config.yml

    1
    2
    deploy:
    artifact: target/{PROJECT_NAME}.jar
  6. Specify the active Spring profile as environmental varialbe into Elastic Beanstalk

    1
    eb setenv SPRING_PROFILES_ACTIVE=beanstalk
  7. Specify default port 5000 expected by Beanstalk

    1
    eb setenv SERVER_PORT=5000
  8. Build

    1
    mvn clean package spring-boot:repackage
  9. Deploy

    1
    eb deploy
  10. check the status and determine the DNS name

    1
    eb status

Response

1
2
3
4
5
6
7
8
9
10
11
12
[steven@mysql deepnet-push-notification]$ eb status
Environment details for: DeepnetPushNotification-env
Application name: deepnet-push-notification
Region: eu-west-2
Deployed Version: app-9b78-190705_124756
Environment ID: e-jpkemgsuet
Platform: arn:aws:elasticbeanstalk:eu-west-2::platform/Java 8 running on 64bit Amazon Linux/2.8.6
Tier: WebServer-Standard-1.0
CNAME: DeepnetPushNotification-env.vwfe7yarai.eu-west-2.elasticbeanstalk.com
Updated: 2019-07-05 11:51:18.246000+00:00
Status: Ready
Health: Yellow

Deploy to Azure app service

Following this documentation

  1. Install Azure CLI

  2. Login Azure account in local.

    1
    az login

Azure login.

  1. Configure Maven Plugin for Azure App Service
    1
    2
    3
    4
    5
    <plugin>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-webapp-maven-plugin</artifactId>
    <version>1.6.0</version>
    </plugin>
1
2
3
OS: linux
javaVersion: jre8
runtimeStack: jre8
  1. Maven plugin will be updated automatically

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    <plugin>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-webapp-maven-plugin</artifactId>
    <version>1.6.0</version>
    <configuration>
    <schemaVersion>V2</schemaVersion>
    <resourceGroup>deepnet-push-notification-1562169090296-rg</resourceGroup>
    <appName>deepnet-push-notification-1562169090296</appName>
    <region>westeurope</region>
    <pricingTier>P1V2</pricingTier>
    <!-- Begin of App Settings -->
    <appSettings>
    <property>
    <name>JAVA_OPTS</name>
    <value>-Dserver.port=80</value>
    </property>
    </appSettings>
    <!-- End of App Settings -->
    <runtime>
    <os>linux</os>
    <javaVersion>jre8</javaVersion>
    <webContainer>TOMCAT 8.5</webContainer>
    </runtime>
    <deployment>
    <resources>
    <resource>
    <directory>${project.basedir}/target</directory>
    <includes>
    <include>*.war</include>
    </includes>
    </resource>
    </resources>
    </deployment>
    </configuration>
    </plugin>
  2. Build

    1
    mvn clean package
  3. Deploy

    1
    mvn azure-webapp:deploy
  4. Azure console: https://portal.azure.com/#blade/HubsExtension/BrowseResourceBlade/resourceType/Microsoft.Web%2Fsites