From b24bcb95342d1b40a06b5880056cc39917b70c46 Mon Sep 17 00:00:00 2001 From: Muhammad Asad Date: Thu, 1 Aug 2024 00:24:12 +0400 Subject: [PATCH 1/3] Added dockerfile and docker-compose --- .env | 9 +++++++++ Dockerfile | 35 +++++++++++++++++++++++++++++++++++ docker-compose.yml | 30 ++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 .env create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.env b/.env new file mode 100644 index 0000000..37b3b96 --- /dev/null +++ b/.env @@ -0,0 +1,9 @@ +MYSQL_ROOT_PASSWORD=root +MYSQL_DATABASE=usersystem +MYSQL_USER=root +MYSQL_PASSWORD=root +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 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3009b90 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +# Use Maven to build the application +FROM maven:3.8.1-openjdk-17 AS build + +# Set the working directory +WORKDIR /app + +# Copy the pom.xml and install dependencies +COPY pom.xml ./ +RUN mvn dependency:go-offline + +# Copy the source code and build the application +COPY src ./src +RUN mvn clean package -DskipTests + +# Use OpenJDK for running the application +FROM openjdk:17-jdk-slim + +# Set the working directory +WORKDIR /app + +# Copy the built JAR file from the Maven build stage +COPY --from=build /app/target/rihal-0.0.1-SNAPSHOT.jar /app/rihal-0.0.1-SNAPSHOT.jar + +# Expose the application port +EXPOSE 8080 + +# Set environment variables +ENV 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 + +# Define the command to run the application +CMD ["java", "-jar", "rihal-0.0.1-SNAPSHOT.jar"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..378bd2e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,30 @@ +version: '3.8' + +services: + database: + image: mysql:8.0.32 + container_name: userinfostoreapp-mysql + ports: + - "3308:3306" + environment: + - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} + - MYSQL_DATABASE=${MYSQL_DATABASE} + - MYSQL_USER=${MYSQL_USER} + - MYSQL_PASSWORD=${MYSQL_PASSWORD} + volumes: + - mysql_data:/var/lib/mysql + + application: + build: . + container_name: userinfostoreapp-app + ports: + - "8081:8080" + env_file: + - .env + depends_on: + - database + volumes: + - ./logs:/app/logs + +volumes: + mysql_data: From 46cd5c0f0849f432b2a9984557dca9be047d9692 Mon Sep 17 00:00:00 2001 From: Muhammad Asad Date: Thu, 1 Aug 2024 00:54:10 +0400 Subject: [PATCH 2/3] dockerfile and docker-compose version 2 --- Dockerfile | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3009b90..974453e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,35 +1,32 @@ -# Use Maven to build the application + FROM maven:3.8.1-openjdk-17 AS build -# Set the working directory WORKDIR /app -# Copy the pom.xml and install dependencies -COPY pom.xml ./ -RUN mvn dependency:go-offline -# Copy the source code and build the application +COPY pom.xml . COPY src ./src + RUN mvn clean package -DskipTests -# Use OpenJDK for running the application + FROM openjdk:17-jdk-slim -# Set the working directory + WORKDIR /app -# Copy the built JAR file from the Maven build stage + COPY --from=build /app/target/rihal-0.0.1-SNAPSHOT.jar /app/rihal-0.0.1-SNAPSHOT.jar -# Expose the application port + EXPOSE 8080 -# Set environment variables + ENV 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 -# Define the command to run the application + CMD ["java", "-jar", "rihal-0.0.1-SNAPSHOT.jar"] From 10056dc5484b5f44148ae6dd846e6d82ec8d555f Mon Sep 17 00:00:00 2001 From: Sheikho8 Date: Thu, 1 Aug 2024 01:12:03 +0400 Subject: [PATCH 3/3] Delete Dockerfile --- Dockerfile | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 974453e..0000000 --- a/Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ - -FROM maven:3.8.1-openjdk-17 AS build - -WORKDIR /app - - -COPY pom.xml . -COPY src ./src - -RUN mvn clean package -DskipTests - - -FROM openjdk:17-jdk-slim - - -WORKDIR /app - - -COPY --from=build /app/target/rihal-0.0.1-SNAPSHOT.jar /app/rihal-0.0.1-SNAPSHOT.jar - - -EXPOSE 8080 - - -ENV 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 - - -CMD ["java", "-jar", "rihal-0.0.1-SNAPSHOT.jar"]