Skip to content

Commit 94f50c2

Browse files
committed
BAEL-1779 deploy springboot app to azure
1 parent 4c333ae commit 94f50c2

10 files changed

Lines changed: 311 additions & 0 deletions

File tree

azure/.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
.sts4-cache
12+
13+
### IntelliJ IDEA ###
14+
.idea
15+
*.iws
16+
*.iml
17+
*.ipr
18+
19+
### NetBeans ###
20+
/nbproject/private/
21+
/build/
22+
/nbbuild/
23+
/dist/
24+
/nbdist/
25+
/.nb-gradle/

azure/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Relevant Articles:
2+
3+
- [Deploy Spring Boot App to Azure]()

azure/docker/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM frolvlad/alpine-oraclejdk8:slim
2+
VOLUME /tmp
3+
ADD azure-0.1.jar app.jar
4+
RUN sh -c 'touch /app.jar'
5+
EXPOSE 8080
6+
ENTRYPOINT [ "sh", "-c", "java -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

azure/pom.xml

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.baeldung.springboot</groupId>
7+
<artifactId>azure</artifactId>
8+
<version>0.1</version>
9+
<packaging>war</packaging>
10+
<name>azure</name>
11+
<description>Demo project for Spring Boot on Azure</description>
12+
13+
<parent>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter-parent</artifactId>
16+
<version>2.0.2.RELEASE</version>
17+
<relativePath/> <!-- lookup parent from repository -->
18+
</parent>
19+
20+
<properties>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
23+
<java.version>1.8</java.version>
24+
25+
<azure.containerRegistry>aietdocker</azure.containerRegistry>
26+
<docker.image.prefix>${azure.containerRegistry}.azurecr.io</docker.image.prefix>
27+
</properties>
28+
29+
<dependencies>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-web</artifactId>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-tomcat</artifactId>
38+
<scope>provided</scope>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-data-jpa</artifactId>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>com.h2database</groupId>
48+
<artifactId>h2</artifactId>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>mysql</groupId>
53+
<artifactId>mysql-connector-java</artifactId>
54+
<version>5.1.6</version>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>org.springframework.boot</groupId>
59+
<artifactId>spring-boot-starter-test</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
</dependencies>
63+
64+
<build>
65+
<plugins>
66+
<plugin>
67+
<groupId>org.springframework.boot</groupId>
68+
<artifactId>spring-boot-maven-plugin</artifactId>
69+
</plugin>
70+
<plugin>
71+
<groupId>com.spotify</groupId>
72+
<artifactId>docker-maven-plugin</artifactId>
73+
<version>1.0.0</version>
74+
<configuration>
75+
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
76+
<registryUrl>https://${docker.image.prefix}</registryUrl>
77+
<serverId>${azure.containerRegistry}</serverId>
78+
<dockerDirectory>docker</dockerDirectory>
79+
<resources>
80+
<resource>
81+
<targetPath>/</targetPath>
82+
<directory>${project.build.directory}</directory>
83+
<include>${project.build.finalName}.jar</include>
84+
</resource>
85+
</resources>
86+
</configuration>
87+
</plugin>
88+
<plugin>
89+
<groupId>com.microsoft.azure</groupId>
90+
<artifactId>azure-webapp-maven-plugin</artifactId>
91+
<version>1.1.0</version>
92+
<configuration>
93+
<authentication>
94+
<serverId>azure-auth</serverId>
95+
</authentication>
96+
<resourceGroup>baeldung-group</resourceGroup>
97+
<appName>baeldung-webapp</appName>
98+
<appServicePlanName>baeldung-plan</appServicePlanName>
99+
<javaVersion>1.8</javaVersion>
100+
<!--<javaWebContainer>tomcat 8.5</javaWebContainer>-->
101+
<!--<region>japanwest</region>-->
102+
<!--<containerSettings>-->
103+
<!--<imageName>${docker.image.prefix}/${project.artifactId}</imageName>-->
104+
<!--<registryUrl>https://${docker.image.prefix}</registryUrl>-->
105+
<!--<serverId>${azure.containerRegistry}</serverId>-->
106+
<!--</containerSettings>-->
107+
<appSettings>
108+
<property>
109+
<name>spring.datasource.url</name>
110+
<value>jdbc:h2:file:~/test</value>
111+
<!--<value>jdbc:mysql://127.0.0.1:55738/localdb</value>-->
112+
</property>
113+
<property>
114+
<name>spring.datasource.username</name>
115+
<value>sa</value>
116+
<!--<value>azure</value>-->
117+
</property>
118+
<property>
119+
<name>spring.datasource.password</name>
120+
<value></value>
121+
<!--<value>replace-with-your-password</value>-->
122+
</property>
123+
</appSettings>
124+
<!--<deploymentType>ftp</deploymentType>-->
125+
<!--<resources>-->
126+
<!--<resource>-->
127+
<!--<directory>${project.basedir}/target</directory>-->
128+
<!--<targetPath>webapps</targetPath>-->
129+
<!--<includes>-->
130+
<!--<include>*.war</include>-->
131+
<!--</includes>-->
132+
<!--</resource>-->
133+
<!--</resources>-->
134+
</configuration>
135+
</plugin>
136+
</plugins>
137+
</build>
138+
139+
140+
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.springboot.azure;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.boot.builder.SpringApplicationBuilder;
6+
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
7+
8+
@SpringBootApplication
9+
public class AzureApplication extends SpringBootServletInitializer {
10+
11+
@Override
12+
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
13+
return application.sources(AzureApplication.class);
14+
}
15+
16+
public static void main(String[] args) {
17+
SpringApplication.run(AzureApplication.class, args);
18+
}
19+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.baeldung.springboot.azure;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.PostMapping;
6+
import org.springframework.web.bind.annotation.RequestParam;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
import static com.baeldung.springboot.azure.User.userNamed;
10+
11+
/**
12+
* @author aiet
13+
*/
14+
@RestController
15+
public class TestController {
16+
17+
@GetMapping("/hello")
18+
public String hello() {
19+
return "hello azure!";
20+
}
21+
22+
@Autowired private UserRepository userRepository;
23+
24+
@PostMapping("/user")
25+
public String register(@RequestParam String name) {
26+
userRepository.save(userNamed(name));
27+
return "registered";
28+
}
29+
30+
@GetMapping("/user")
31+
public Iterable<User> userlist() {
32+
return userRepository.findAll();
33+
}
34+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.baeldung.springboot.azure;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.GeneratedValue;
5+
import javax.persistence.GenerationType;
6+
import javax.persistence.Id;
7+
8+
/**
9+
* @author aiet
10+
*/
11+
@Entity
12+
public class User {
13+
14+
public User() {
15+
}
16+
17+
public static User userNamed(String name) {
18+
User u = new User();
19+
u.setName(name);
20+
return u;
21+
}
22+
23+
@Id
24+
@GeneratedValue(strategy = GenerationType.AUTO)
25+
private Integer id;
26+
private String name;
27+
28+
public Integer getId() {
29+
return id;
30+
}
31+
32+
public void setId(Integer id) {
33+
this.id = id;
34+
}
35+
36+
public String getName() {
37+
return name;
38+
}
39+
40+
public void setName(String name) {
41+
this.name = name;
42+
}
43+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.baeldung.springboot.azure;
2+
3+
import org.springframework.data.repository.CrudRepository;
4+
5+
/**
6+
* @author aiet
7+
*/
8+
public interface UserRepository extends CrudRepository<User, Long> {
9+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
server.port=8080
2+
server.address=0.0.0.0
3+
spring.jpa.hibernate.ddl-auto=create
4+
5+
logging.file=azure.log
6+
logging.level.root=info
7+
8+
spring.datasource.url=jdbc:h2:file:~/test
9+
spring.datasource.username=sa
10+
spring.datasource.password=
11+
12+
#spring.datasource.url=jdbc:mysql://localhost:3306/localdb
13+
#spring.datasource.username=your-db-username
14+
#spring.datasource.password=your-db-password
15+
16+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.baeldung.springboot.azure;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
import org.springframework.test.context.junit4.SpringRunner;
7+
8+
@RunWith(SpringRunner.class)
9+
@SpringBootTest
10+
public class AzureApplicationTests {
11+
12+
@Test
13+
public void contextLoads() {
14+
}
15+
16+
}

0 commit comments

Comments
 (0)