-
Notifications
You must be signed in to change notification settings - Fork 16
containerized-app-and-db #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "java.compile.nullAnalysis.mode": "automatic" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Build the application using Maven and OpenJDK 17 & setting the working diroctory | ||
| FROM maven:3.8.1-openjdk-17 AS build | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # using the provided files (e.g. pom.xml) | ||
| COPY pom.xml . | ||
|
|
||
| COPY src ./src | ||
|
|
||
| # -DskipTests to skip tests | ||
| RUN mvn clean package -DskipTests | ||
|
|
||
| # contents of the target | ||
| RUN ls -l target/ | ||
|
|
||
| # Create image | ||
| FROM openjdk:17-jdk-slim | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY --from=build /app/target/rihal-0.0.1-SNAPSHOT.jar app.jar | ||
|
|
||
| # Expose | ||
| EXPOSE 8080 | ||
|
|
||
| # Define the entry point | ||
| ENTRYPOINT ["java", "-jar", "app.jar"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| version: '3.8' | ||
|
|
||
| services: | ||
| mysql: | ||
| image: mysql | ||
| container_name: mysql | ||
| environment: # Set environment variables for MySQL | ||
| MYSQL_ROOT_PASSWORD: root | ||
| MYSQL_DATABASE: usersystem | ||
| MYSQL_PASSWORD: root | ||
| MYSQL_TCP_PORT: 3307 | ||
| ports: | ||
| - "3307:3307" # port 3307 on the host to port 3307 on the container | ||
| volumes: | ||
| - mysql_data:/var/lib/mysql | ||
| networks: | ||
| - demo-network | ||
|
|
||
| springboot: | ||
| build: . # Build the Spring Boot application | ||
| container_name: springboot | ||
| environment: # Set environment variables for the Spring Boot application | ||
| SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3307/usersystem?useSSL=false&serverTimezone=UTC&createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true # JDBC URL for the MySQL database | ||
| SPRING_DATASOURCE_USERNAME: root | ||
| SPRING_DATASOURCE_PASSWORD: root | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should never push the password on GitHub. |
||
| SPRING_JPA_HIBERNATE_DDL_AUTO: update | ||
| SPRING_JPA_SHOW_SQL: "true" | ||
| ports: | ||
| - "8080:8080" # port 8080 on the host to port 8080 on the container | ||
| depends_on: | ||
| - mysql | ||
| networks: | ||
| - demo-network | ||
| restart: on-failure # Restart the container if it fails | ||
|
|
||
| networks: | ||
| demo-network: | ||
|
|
||
| volumes: | ||
| mysql_data: | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Target directory is machine specific and should not be pushed with the project |
| 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 | ||
|
|
| 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> |
| 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> |
| 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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is an IDE related config file, It should not be pushed because every user might have their own config file, and if they pull the changes, this file will conflict with theirs.