Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .env
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For review purposes it's fine, but we should never push the changes with a .env file. The reason is that, this .env is environment specific. On our PC there might be a MySQL server running locally with a different username and password.
Similarly, Another team member may spin up a container and point to a MySQL server running on cloud.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=usersystem
MYSQL_PASSWORD=root

SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3307/usersystem?useSSL=false&serverTimezone=UTC&createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true
SPRING_DATASOURCE_USERNAME=root
SPRING_DATASOURCE_PASSWORD=root
SPRING_JPA_HIBERNATE_DDL_AUTO=update
SPRING_JPA_SHOW_SQL=true

9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM maven:3.8.1-openjdk-17 AS build
WORKDIR /app
COPY . .
RUN mvn clean package -DskipTests

FROM openjdk:17-jdk-alpine
WORKDIR /app
COPY --from=build /app/target/rihal-0.0.1-SNAPSHOT.jar app.jar
CMD ["java", "-jar", "rihal-0.0.1-SNAPSHOT.jar"]
39 changes: 39 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
services:
mysql:
image: mysql:8.0
container_name: my_sql_container
environment:
- MYSQL_ROOT_PASSWORD
- MYSQL_DATABASE
- MYSQL_PASSWORD
ports:
- "3307:3306"
volumes:
- mysql_data:/var/lib/mysql
networks:
- default
restart: always

app:
build: .
container_name: app_container
environment:
- SPRING_DATASOURCE_URL
- SPRING_DATASOURCE_USERNAME
- SPRING_DATASOURCE_PASSWORD
- SPRING_JPA_HIBERNATE_DDL_AUTO
- SPRING_JPA_SHOW_SQL
ports:
- "8080:8080"
depends_on:
- mysql
networks:
- default
restart: always

volumes:
mysql_data:

networks:
default:
driver: bridge
9 changes: 9 additions & 0 deletions target/classes/application.properties
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Target directory is also host specific and usually not pushed on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spring.application.name=rihal
spring.datasource.url=${SPRING_DATASOURCE_URL}
spring.datasource.username=${SPRING_DATASOURCE_USERNAME}
spring.datasource.password=${SPRING_DATASOURCE_PASSWORD}
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

17 changes: 17 additions & 0 deletions target/classes/templates/edit_user.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Edit User</title>
</head>
<body>
<h1>Edit User</h1>
<form action="#" th:action="@{/users/{id}(id=${user.id})}" th:object="${user}" method="post">
<label>Name: </label>
<input type="text" th:field="*{name}" /><br>
<label>Email: </label>
<input type="email" th:field="*{email}" /><br>
<button type="submit">Save</button>
</form>
</body>
</html>
32 changes: 32 additions & 0 deletions target/classes/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>User Management</title>
</head>
<body>
<h1>User Management</h1>
<a href="/users/new">Add New User</a>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr th:each="user : ${users}">
<td th:text="${user.id}"></td>
<td th:text="${user.name}"></td>
<td th:text="${user.email}"></td>
<td>
<a th:href="@{/users/edit/{id}(id=${user.id})}">Edit</a>
<a th:href="@{/users/delete/{id}(id=${user.id})}">Delete</a>
</td>
</tr>
</tbody>
</table>
</body>
</html>
17 changes: 17 additions & 0 deletions target/classes/templates/new_user.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Add New User</title>
</head>
<body>
<h1>Add New User</h1>
<form action="#" th:action="@{/users}" th:object="${user}" method="post">
<label>Name: </label>
<input type="text" th:field="*{name}" /><br>
<label>Email: </label>
<input type="email" th:field="*{email}" /><br>
<button type="submit">Save</button>
</form>
</body>
</html>
3 changes: 3 additions & 0 deletions target/maven-archiver/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifactId=rihal
groupId=com.docker
version=0.0.1-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
com/docker/rihal/controllers/UserController.class
com/docker/rihal/RihalApplication.class
com/docker/rihal/models/User.class
com/docker/rihal/repositories/UserRepository.class
com/docker/rihal/services/UserService.class
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/app/src/main/java/com/docker/rihal/RihalApplication.java
/app/src/main/java/com/docker/rihal/controllers/UserController.java
/app/src/main/java/com/docker/rihal/models/User.java
/app/src/main/java/com/docker/rihal/repositories/UserRepository.java
/app/src/main/java/com/docker/rihal/services/UserService.java
Binary file added target/rihal-0.0.1-SNAPSHOT.jar.original
Binary file not shown.