From c04b872afd7adad0521953e9b6f1003ee6c495fd Mon Sep 17 00:00:00 2001 From: Hamdan Al Shaaili Date: Tue, 30 Jul 2024 00:34:18 +0400 Subject: [PATCH 1/2] Added dockerfile and docker-compose --- .vscode/settings.json | 3 ++ Dockerfile | 21 +++++++++++++ docker-compose.yml | 39 +++++++++++++++++++++++++ target/classes/application.properties | 9 ++++++ target/classes/templates/edit_user.html | 17 +++++++++++ target/classes/templates/index.html | 32 ++++++++++++++++++++ target/classes/templates/new_user.html | 17 +++++++++++ 7 files changed, 138 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 target/classes/application.properties create mode 100644 target/classes/templates/edit_user.html create mode 100644 target/classes/templates/index.html create mode 100644 target/classes/templates/new_user.html diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..7b016a8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.compile.nullAnalysis.mode": "automatic" +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a7672ef --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM maven:3.8.1-openjdk-17 AS build + +WORKDIR /app + +COPY pom.xml . +COPY src ./src + +RUN mvn clean package -DskipTests + +RUN ls -l target/ + +FROM openjdk:17-jdk-slim + +WORKDIR /app + +COPY --from=build /app/target/rihal-0.0.1-SNAPSHOT.jar app.jar + +EXPOSE 8080 + +ENTRYPOINT ["java", "-jar", "app.jar"] + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..40ce27a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,39 @@ +version: '3.8' + +services: + mysql: + image: mysql + container_name: mysql + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: usersystem + MYSQL_PASSWORD: root + MYSQL_TCP_PORT: 3307 + ports: + - "3307:3307" + volumes: + - mysql_data:/var/lib/mysql + networks: + - demo-network + + springboot: + build: . + container_name: springboot + environment: + 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" + ports: + - "8080:8080" + depends_on: + - mysql + networks: + - demo-network + restart: on-failure +networks: + demo-network: + +volumes: + mysql_data: \ No newline at end of file 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

+
+ +
+ +
+ +
+ + From e4f9030f844bd313cfc9286af87bcf5c338d46f5 Mon Sep 17 00:00:00 2001 From: Hamdan Al Shaaili Date: Wed, 31 Jul 2024 01:01:45 +0400 Subject: [PATCH 2/2] Added dockerfile and docker-compose --- Dockerfile | 11 +++++++++-- docker-compose.yml | 17 +++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index a7672ef..9efccbc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +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 -ENTRYPOINT ["java", "-jar", "app.jar"] - +# Define the entry point +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 40ce27a..b628778 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,34 +4,35 @@ services: mysql: image: mysql container_name: mysql - environment: + environment: # Set environment variables for MySQL MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: usersystem MYSQL_PASSWORD: root MYSQL_TCP_PORT: 3307 ports: - - "3307:3307" + - "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: . # Build the Spring Boot application container_name: springboot - environment: - SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3307/usersystem?useSSL=false&serverTimezone=UTC&createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true + 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 SPRING_JPA_HIBERNATE_DDL_AUTO: update SPRING_JPA_SHOW_SQL: "true" ports: - - "8080:8080" + - "8080:8080" # port 8080 on the host to port 8080 on the container depends_on: - mysql networks: - - demo-network - restart: on-failure + - demo-network + restart: on-failure # Restart the container if it fails + networks: demo-network: