Spaces:
Sleeping
Sleeping
Taki Eddine RAHAL
commited on
Commit
·
cc43ca5
1
Parent(s):
7f9bec3
Add project
Browse files- .gitignore +0 -1
- HELP.md +69 -0
- src/main/java/com/example/demo/DemoApplication.java +1 -22
- src/main/resources/application.properties +3 -3
.gitignore
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
HELP.md
|
2 |
target/
|
3 |
!.mvn/wrapper/maven-wrapper.jar
|
4 |
!**/src/main/**/target/
|
|
|
|
|
1 |
target/
|
2 |
!.mvn/wrapper/maven-wrapper.jar
|
3 |
!**/src/main/**/target/
|
HELP.md
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Deploy Sprint Boot And Postegres on Render with Web Services and Docker
|
2 |
+
|
3 |
+
## Creat Spring Boot Project
|
4 |
+
|
5 |
+
https://start.spring.io/
|
6 |
+
|
7 |
+
## Add Dependencies Web : spring-boot-starter-web
|
8 |
+
|
9 |
+
<dependency>
|
10 |
+
<groupId>org.springframework.boot</groupId>
|
11 |
+
<artifactId>spring-boot-starter-web</artifactId>
|
12 |
+
</dependency>
|
13 |
+
|
14 |
+
## Add Dependencies JPA
|
15 |
+
|
16 |
+
<dependency>
|
17 |
+
<groupId>org.springframework.boot</groupId>
|
18 |
+
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
19 |
+
</dependency>
|
20 |
+
|
21 |
+
## Add Dependencies PostegreSql : postgresql
|
22 |
+
|
23 |
+
<dependency>
|
24 |
+
<groupId>org.postgresql</groupId>
|
25 |
+
<artifactId>postgresql</artifactId>
|
26 |
+
<scope>runtime</scope>
|
27 |
+
</dependency>
|
28 |
+
|
29 |
+
|
30 |
+
### Create Dockerfile at the root folder
|
31 |
+
|
32 |
+
#
|
33 |
+
# Build stage
|
34 |
+
#
|
35 |
+
FROM maven:3.8.2-jdk-11 AS build
|
36 |
+
COPY . .
|
37 |
+
RUN mvn clean package -Pprod -DskipTests
|
38 |
+
|
39 |
+
#
|
40 |
+
# Package stage
|
41 |
+
#
|
42 |
+
FROM openjdk:11-jdk-slim
|
43 |
+
COPY --from=build /target/demo-0.0.1-SNAPSHOT.jar demo.jar
|
44 |
+
# ENV PORT=8080
|
45 |
+
EXPOSE 8080
|
46 |
+
ENTRYPOINT ["java","-jar","demo.jar"]
|
47 |
+
|
48 |
+
|
49 |
+
### Building a Dockerfile from the root folder
|
50 |
+
By default docker uses the Dockerfile of the current folder if you run a single command like
|
51 |
+
Run: docker build -t spring-boot-render .
|
52 |
+
|
53 |
+
### Run image with docker on localhost
|
54 |
+
Run docker run -p 8080:8080 spring-boot-render
|
55 |
+
|
56 |
+
|
57 |
+
## Create Postegres database from Render.com
|
58 |
+
https://dashboard.render.com/
|
59 |
+
|
60 |
+
|
61 |
+
### Modify connections params on application.properties
|
62 |
+
|
63 |
+
spring.datasource.url=jdbc:postgresql://dpg-{custom-url}.render.com:5432/{name_database}
|
64 |
+
spring.datasource.username=your_username
|
65 |
+
spring.datasource.password=your_passeword
|
66 |
+
spring.datasource.driver-class-name=org.postgresql.Driver
|
67 |
+
|
68 |
+
|
69 |
+
### Creat new Web Service app
|
src/main/java/com/example/demo/DemoApplication.java
CHANGED
@@ -10,33 +10,12 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|
10 |
import org.springframework.web.bind.annotation.RestController;
|
11 |
|
12 |
import java.util.List;
|
|
|
13 |
|
14 |
@SpringBootApplication
|
15 |
-
@RestController
|
16 |
public class DemoApplication {
|
17 |
|
18 |
-
@Autowired
|
19 |
-
UserRepository userRepository;
|
20 |
-
|
21 |
public static void main(String[] args) {
|
22 |
SpringApplication.run(DemoApplication.class, args);
|
23 |
}
|
24 |
-
|
25 |
-
// @Override
|
26 |
-
// public void run(String... args) throws Exception {
|
27 |
-
// User user = new User();
|
28 |
-
// user.setFirstName("Rahal");
|
29 |
-
// user.setLastName("Taki");
|
30 |
-
// userRepository.save(user);
|
31 |
-
// }
|
32 |
-
|
33 |
-
@GetMapping("test")
|
34 |
-
public String helloWorld(){
|
35 |
-
|
36 |
-
List<User> userList = userRepository.findAll();
|
37 |
-
userList.stream().forEach(user -> {
|
38 |
-
System.out.println("User "+user.getFirstName());
|
39 |
-
});
|
40 |
-
return "Hello Render";
|
41 |
-
}
|
42 |
}
|
|
|
10 |
import org.springframework.web.bind.annotation.RestController;
|
11 |
|
12 |
import java.util.List;
|
13 |
+
import java.util.Optional;
|
14 |
|
15 |
@SpringBootApplication
|
|
|
16 |
public class DemoApplication {
|
17 |
|
|
|
|
|
|
|
18 |
public static void main(String[] args) {
|
19 |
SpringApplication.run(DemoApplication.class, args);
|
20 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
}
|
src/main/resources/application.properties
CHANGED
@@ -5,7 +5,7 @@ spring.jpa.hibernate.ddl-auto=update
|
|
5 |
spring.jpa.hibernate.show-sql=true
|
6 |
|
7 |
# Local configuration DB
|
8 |
-
spring.datasource.url=jdbc:postgresql://
|
9 |
-
spring.datasource.username=
|
10 |
-
spring.datasource.password=
|
11 |
spring.datasource.driver-class-name=org.postgresql.Driver
|
|
|
5 |
spring.jpa.hibernate.show-sql=true
|
6 |
|
7 |
# Local configuration DB
|
8 |
+
spring.datasource.url=jdbc:postgresql://localhost:5432/spring-boot-render
|
9 |
+
spring.datasource.username=postgres
|
10 |
+
spring.datasource.password=azerty
|
11 |
spring.datasource.driver-class-name=org.postgresql.Driver
|