Merge pull request #4327 from aietcn/master

BAEL-1779 deploy springboot app to azure
This commit is contained in:
Loredana Crusoveanu 2018-05-23 20:25:06 +03:00 committed by GitHub
commit d49c6a2843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 311 additions and 0 deletions

25
azure/.gitignore vendored Normal file
View File

@ -0,0 +1,25 @@
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/build/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

3
azure/README.md Normal file
View File

@ -0,0 +1,3 @@
### Relevant Articles:
- [Deploy Spring Boot App to Azure]()

6
azure/docker/Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD azure-0.1.jar app.jar
RUN sh -c 'touch /app.jar'
EXPOSE 8080
ENTRYPOINT [ "sh", "-c", "java -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

140
azure/pom.xml Normal file
View File

@ -0,0 +1,140 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.springboot</groupId>
<artifactId>azure</artifactId>
<version>0.1</version>
<packaging>war</packaging>
<name>azure</name>
<description>Demo project for Spring Boot on Azure</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<azure.containerRegistry>aietdocker</azure.containerRegistry>
<docker.image.prefix>${azure.containerRegistry}.azurecr.io</docker.image.prefix>
</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-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<registryUrl>https://${docker.image.prefix}</registryUrl>
<serverId>${azure.containerRegistry}</serverId>
<dockerDirectory>docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>1.1.0</version>
<configuration>
<authentication>
<serverId>azure-auth</serverId>
</authentication>
<resourceGroup>baeldung-group</resourceGroup>
<appName>baeldung-webapp</appName>
<appServicePlanName>baeldung-plan</appServicePlanName>
<javaVersion>1.8</javaVersion>
<!--<javaWebContainer>tomcat 8.5</javaWebContainer>-->
<!--<region>japanwest</region>-->
<!--<containerSettings>-->
<!--<imageName>${docker.image.prefix}/${project.artifactId}</imageName>-->
<!--<registryUrl>https://${docker.image.prefix}</registryUrl>-->
<!--<serverId>${azure.containerRegistry}</serverId>-->
<!--</containerSettings>-->
<appSettings>
<property>
<name>spring.datasource.url</name>
<value>jdbc:h2:file:~/test</value>
<!--<value>jdbc:mysql://127.0.0.1:55738/localdb</value>-->
</property>
<property>
<name>spring.datasource.username</name>
<value>sa</value>
<!--<value>azure</value>-->
</property>
<property>
<name>spring.datasource.password</name>
<value></value>
<!--<value>replace-with-your-password</value>-->
</property>
</appSettings>
<!--<deploymentType>ftp</deploymentType>-->
<!--<resources>-->
<!--<resource>-->
<!--<directory>${project.basedir}/target</directory>-->
<!--<targetPath>webapps</targetPath>-->
<!--<includes>-->
<!--<include>*.war</include>-->
<!--</includes>-->
<!--</resource>-->
<!--</resources>-->
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,19 @@
package com.baeldung.springboot.azure;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class AzureApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(AzureApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(AzureApplication.class, args);
}
}

View File

@ -0,0 +1,34 @@
package com.baeldung.springboot.azure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import static com.baeldung.springboot.azure.User.userNamed;
/**
* @author aiet
*/
@RestController
public class TestController {
@GetMapping("/hello")
public String hello() {
return "hello azure!";
}
@Autowired private UserRepository userRepository;
@PostMapping("/user")
public String register(@RequestParam String name) {
userRepository.save(userNamed(name));
return "registered";
}
@GetMapping("/user")
public Iterable<User> userlist() {
return userRepository.findAll();
}
}

View File

@ -0,0 +1,43 @@
package com.baeldung.springboot.azure;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/**
* @author aiet
*/
@Entity
public class User {
public User() {
}
public static User userNamed(String name) {
User u = new User();
u.setName(name);
return u;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,9 @@
package com.baeldung.springboot.azure;
import org.springframework.data.repository.CrudRepository;
/**
* @author aiet
*/
public interface UserRepository extends CrudRepository<User, Long> {
}

View File

@ -0,0 +1,16 @@
server.port=8080
server.address=0.0.0.0
spring.jpa.hibernate.ddl-auto=create
logging.file=azure.log
logging.level.root=info
spring.datasource.url=jdbc:h2:file:~/test
spring.datasource.username=sa
spring.datasource.password=
#spring.datasource.url=jdbc:mysql://localhost:3306/localdb
#spring.datasource.username=your-db-username
#spring.datasource.password=your-db-password

View File

@ -0,0 +1,16 @@
package com.baeldung.springboot.azure;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class AzureApplicationTests {
@Test
public void contextLoads() {
}
}