diff --git a/.env b/.env new file mode 100644 index 0000000..f74a201 --- /dev/null +++ b/.env @@ -0,0 +1,8 @@ +SPRING_DATASOURCE_URL=jdbc:mysql://mysql-cont:3306/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 + +MYSQL_ROOT_PASSWORD=root +MYSQL_DATABASE=usersystem diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e648af4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# Use the Maven OpenJDK image as the base image +FROM maven:3.8.1-openjdk-17 AS build + +# Set the working directory +WORKDIR /app + +# Copy the pom.xml and the project source code +COPY pom.xml . +COPY src ./src +COPY .env . + +# Package the application +RUN mvn clean package -DskipTests + +# Use the official OpenJDK image to run the application +FROM openjdk:17-jdk-slim + +# Set the working directory +WORKDIR /app + +# Copy the packaged jar file from the build stage +COPY --from=build /app/target/rihal-0.0.1-SNAPSHOT.jar . +COPY --from=build /app/.env . + +# Expose the port the application runs on +EXPOSE 8080 + +# Run the application with .env variables +ENTRYPOINT ["sh", "-c", "java -jar rihal-0.0.1-SNAPSHOT.jar"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..51e068d --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,25 @@ +version: '3.8' + +services: + mysql: + image: mysql:8.0 + container_name: mysql-cont + env_file: + - .env + ports: + - "3307:3306" + volumes: + - db_data:/var/lib/mysql + + app: + build: . + container_name: userinfoapp + env_file: + - .env + ports: + - "8080:8080" + depends_on: + - mysql + +volumes: + db_data: diff --git a/pom.xml b/pom.xml index e74cc95..8d13919 100644 --- a/pom.xml +++ b/pom.xml @@ -42,21 +42,22 @@ org.springframework.boot spring-boot-starter-web - org.springframework.boot spring-boot-devtools runtime true - com.mysql mysql-connector-j runtime - - + + io.github.cdimascio + java-dotenv + 5.2.2 + @@ -67,5 +68,4 @@ - diff --git a/src/main/java/com/docker/rihal/RihalApplication.java b/src/main/java/com/docker/rihal/RihalApplication.java index 90af33a..eaa32f8 100644 --- a/src/main/java/com/docker/rihal/RihalApplication.java +++ b/src/main/java/com/docker/rihal/RihalApplication.java @@ -1,13 +1,21 @@ package com.docker.rihal; +import io.github.cdimascio.dotenv.Dotenv; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class RihalApplication { - public static void main(String[] args) { - SpringApplication.run(RihalApplication.class, args); - } + public static void main(String[] args) { + // Load environment variables from .env file + Dotenv dotenv = Dotenv.load(); + System.setProperty("SPRING_DATASOURCE_URL", dotenv.get("SPRING_DATASOURCE_URL")); + System.setProperty("SPRING_DATASOURCE_USERNAME", dotenv.get("SPRING_DATASOURCE_USERNAME")); + System.setProperty("SPRING_DATASOURCE_PASSWORD", dotenv.get("SPRING_DATASOURCE_PASSWORD")); + System.setProperty("SPRING_JPA_HIBERNATE_DDL_AUTO", dotenv.get("SPRING_JPA_HIBERNATE_DDL_AUTO")); + System.setProperty("SPRING_JPA_SHOW_SQL", dotenv.get("SPRING_JPA_SHOW_SQL")); + SpringApplication.run(RihalApplication.class, args); + } } diff --git a/target/classes/application.properties b/target/classes/application.properties new file mode 100644 index 0000000..9cc6243 --- /dev/null +++ b/target/classes/application.properties @@ -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 + diff --git a/target/classes/templates/edit_user.html b/target/classes/templates/edit_user.html new file mode 100644 index 0000000..8346537 --- /dev/null +++ b/target/classes/templates/edit_user.html @@ -0,0 +1,17 @@ + + + + + Edit User + + +

Edit User

+
+ +
+ +
+ +
+ + diff --git a/target/classes/templates/index.html b/target/classes/templates/index.html new file mode 100644 index 0000000..437d263 --- /dev/null +++ b/target/classes/templates/index.html @@ -0,0 +1,32 @@ + + + + + User Management + + +

User Management

+Add New User + + + + + + + + + + + + + + + + + +
IDNameEmailActions
+ Edit + Delete +
+ + diff --git a/target/classes/templates/new_user.html b/target/classes/templates/new_user.html new file mode 100644 index 0000000..14e04e3 --- /dev/null +++ b/target/classes/templates/new_user.html @@ -0,0 +1,17 @@ + + + + + Add New User + + +

Add New User

+
+ +
+ +
+ +
+ + diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 0000000..c66596b --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=rihal +groupId=com.docker +version=0.0.1-SNAPSHOT diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..6ea471a --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,5 @@ +com\docker\rihal\repositories\UserRepository.class +com\docker\rihal\services\UserService.class +com\docker\rihal\controllers\UserController.class +com\docker\rihal\RihalApplication.class +com\docker\rihal\models\User.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..330ecbb --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,5 @@ +C:\Users\EtharAlAasmi\TrainingChallenge\UserInfoStoreApp\src\main\java\com\docker\rihal\controllers\UserController.java +C:\Users\EtharAlAasmi\TrainingChallenge\UserInfoStoreApp\src\main\java\com\docker\rihal\models\User.java +C:\Users\EtharAlAasmi\TrainingChallenge\UserInfoStoreApp\src\main\java\com\docker\rihal\repositories\UserRepository.java +C:\Users\EtharAlAasmi\TrainingChallenge\UserInfoStoreApp\src\main\java\com\docker\rihal\RihalApplication.java +C:\Users\EtharAlAasmi\TrainingChallenge\UserInfoStoreApp\src\main\java\com\docker\rihal\services\UserService.java diff --git a/target/rihal-0.0.1-SNAPSHOT.jar.original b/target/rihal-0.0.1-SNAPSHOT.jar.original new file mode 100644 index 0000000..6d8cb45 Binary files /dev/null and b/target/rihal-0.0.1-SNAPSHOT.jar.original differ