From 2d2bad10569ce6d3b0c1fcaa8b929025317084e4 Mon Sep 17 00:00:00 2001 From: Lhloworld Date: Sun, 12 Oct 2025 18:17:28 +0530 Subject: [PATCH 1/3] Configured Spring Boot for open access, updated Docker and Mysql setup --- .dockerignore | 11 ++++++ .vscode/settings.json | 3 ++ Docker-README.md | 32 +++++++++++++++ Dockerfile | 25 ++++++++++++ docker-compose.yml | 37 ++++++++++++++++++ src/main/resources/application.properties | 9 +---- target/classes/application.properties | 13 ++++++ .../com/inventory/im/ImApplication.class | Bin 0 -> 727 bytes .../inventory/im/config/SecurityConfig.class | Bin 0 -> 6111 bytes .../im/controller/AuthController.class | Bin 0 -> 3156 bytes .../im/controller/ProductController.class | Bin 0 -> 5483 bytes .../com/inventory/im/dto/AuthResponse.class | Bin 0 -> 637 bytes .../com/inventory/im/dto/ProductRequest.class | Bin 0 -> 1906 bytes .../im/dto/QuantityUpdateRequest.class | Bin 0 -> 621 bytes .../inventory/im/dto/UserLoginRequest.class | Bin 0 -> 804 bytes .../im/dto/UserRegisterRequest.class | Bin 0 -> 813 bytes .../com/inventory/im/model/Product.class | Bin 0 -> 2548 bytes .../classes/com/inventory/im/model/User.class | Bin 0 -> 1392 bytes .../im/repository/ProductRepository.class | Bin 0 -> 432 bytes .../im/repository/UserRepository.class | Bin 0 -> 532 bytes .../im/security/JwtAuthenticationFilter.class | Bin 0 -> 2872 bytes .../com/inventory/im/security/JwtUtil.class | Bin 0 -> 2735 bytes .../inventory/im/service/ProductService.class | Bin 0 -> 2293 bytes .../inventory/im/service/UserService.class | Bin 0 -> 2956 bytes .../com/inventory/im/ImApplicationTests.class | Bin 0 -> 525 bytes wait-for-it.sh | 20 ++++++++++ 26 files changed, 142 insertions(+), 8 deletions(-) create mode 100644 .dockerignore create mode 100644 .vscode/settings.json create mode 100644 Docker-README.md create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 target/classes/application.properties create mode 100644 target/classes/com/inventory/im/ImApplication.class create mode 100644 target/classes/com/inventory/im/config/SecurityConfig.class create mode 100644 target/classes/com/inventory/im/controller/AuthController.class create mode 100644 target/classes/com/inventory/im/controller/ProductController.class create mode 100644 target/classes/com/inventory/im/dto/AuthResponse.class create mode 100644 target/classes/com/inventory/im/dto/ProductRequest.class create mode 100644 target/classes/com/inventory/im/dto/QuantityUpdateRequest.class create mode 100644 target/classes/com/inventory/im/dto/UserLoginRequest.class create mode 100644 target/classes/com/inventory/im/dto/UserRegisterRequest.class create mode 100644 target/classes/com/inventory/im/model/Product.class create mode 100644 target/classes/com/inventory/im/model/User.class create mode 100644 target/classes/com/inventory/im/repository/ProductRepository.class create mode 100644 target/classes/com/inventory/im/repository/UserRepository.class create mode 100644 target/classes/com/inventory/im/security/JwtAuthenticationFilter.class create mode 100644 target/classes/com/inventory/im/security/JwtUtil.class create mode 100644 target/classes/com/inventory/im/service/ProductService.class create mode 100644 target/classes/com/inventory/im/service/UserService.class create mode 100644 target/test-classes/com/inventory/im/ImApplicationTests.class create mode 100644 wait-for-it.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0541f09 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +target/ +.mvn/ +.idea/ +*.iml +.classpath +.project +.settings/ +.git/ +node_modules/ +logs/ +*.log 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/Docker-README.md b/Docker-README.md new file mode 100644 index 0000000..7e10d6b --- /dev/null +++ b/Docker-README.md @@ -0,0 +1,32 @@ +# Docker: Build and run + +This project is a Spring Boot application. The repository includes a multi-stage `Dockerfile` that builds the app with Maven and produces a runtime image. A `docker-compose.yml` is provided as an example to run the service together with a MySQL database. + +Quick steps + +Build the image with Docker (from repository root): + +```bash +docker build -t im-app:latest . +``` + +Run the image: + +```bash +docker run --rm -p 8080:8080 \ + -e SPRING_DATASOURCE_URL='jdbc:mysql://:3306/imdb' \ + -e SPRING_DATASOURCE_USERNAME=root \ + -e SPRING_DATASOURCE_PASSWORD=example \ + im-app:latest +``` + +Use docker-compose for local development (builds image and starts MySQL): + +```bash +docker compose up --build +``` + +Notes +- The Dockerfile uses Maven to build and OpenJDK 21 runtime to run the jar. +- The `docker-compose.yml` exposes MySQL on 3306 for convenience. In production you should not expose DB ports publicly and use secure credentials. +- If you want Docker image layers to cache better during development, consider copying only `pom.xml` first and running `mvn dependency:go-offline` before copying source. diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e5ac5c2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# ---------- STAGE 1: Build ---------- +FROM maven:3.9.8-eclipse-temurin-21 AS builder +WORKDIR /app + +COPY pom.xml . +RUN mvn dependency:go-offline + +COPY src ./src +RUN mvn clean package -DskipTests + +# ---------- STAGE 2: Runtime ---------- +FROM eclipse-temurin:21-jdk +WORKDIR /app + +# Install netcat (for wait-for-it.sh) +RUN apt-get update && apt-get install -y netcat-openbsd && rm -rf /var/lib/apt/lists/* + +# Copy jar and wait script +COPY --from=builder /app/target/*.jar app.jar +COPY wait-for-it.sh . +RUN chmod +x wait-for-it.sh + +EXPOSE 8082 + +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3785487 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,37 @@ +version: "3.9" + +services: + db: + image: mysql:8.0 + container_name: mysql-db + environment: + MYSQL_ROOT_PASSWORD: Anjana@3176 + MYSQL_DATABASE: inventory_db + # MYSQL_USER: root + # MYSQL_PASSWORD: Anjana@3176 + #ports: + # - "3306:3306" + volumes: + - mysql_data:/var/lib/mysql + healthcheck: + test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-pAnjana@3176"] + interval: 5s + timeout: 10s + retries: 10 + + app: + build: . + container_name: inventory-app + depends_on: + db: + condition: service_healthy + environment: + SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/inventory_db?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC + SPRING_DATASOURCE_USERNAME: root + SPRING_DATASOURCE_PASSWORD: Anjana@3176 + ports: + - "8080:8082" + command: ["./wait-for-it.sh", "db", "3306", "--", "java", "-jar", "app.jar"] + +volumes: + mysql_data: diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index dc4e0b6..5034ded 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ # Database -spring.datasource.url=jdbc:mysql://localhost:3306/inventory_db?allowPublicKeyRetrieval=true&useSSL=false +spring.datasource.url=jdbc:mysql://db:3306/inventory_db?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC spring.datasource.username=root spring.datasource.password=Anjana@3176 @@ -11,10 +11,3 @@ spring.jpa.properties.hibernate.format_sql=true # Server server.port=8082 - - -# JWT -#abhay -# jwt.secret=your-secret-key -# jwt.expiration=86400000 # 24 hours in milliseconds -#lol diff --git a/target/classes/application.properties b/target/classes/application.properties new file mode 100644 index 0000000..d9bf846 --- /dev/null +++ b/target/classes/application.properties @@ -0,0 +1,13 @@ +# Database +spring.datasource.url=jdbc:mysql://db:3306/inventory_db?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC +spring.datasource.username=root +spring.datasource.password=Anjana@3176 + +# JPA/Hibernate +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect +spring.jpa.properties.hibernate.format_sql=true + +# Server +server.port=8082 diff --git a/target/classes/com/inventory/im/ImApplication.class b/target/classes/com/inventory/im/ImApplication.class new file mode 100644 index 0000000000000000000000000000000000000000..0a66fadd646adee7df06a80bb9ad94d3e4fa25d1 GIT binary patch literal 727 zcmaJ^sUs+*za5w{6ldvndB-J zP8r=qoniG_+zOrxo$*h}wM-qu;*rwI9WyL+_eTu%fw`0s7O>Pt1B(nRvC{Hm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UllPJDNBWpET6+ee;5|CN&#?BrW*2Hrvs-+E;O zdbw6Y`>=~*cXQr?J!R25`E@U!eYYWeyp8?*rzyDyI8j<2Q>#LBYUDQ@Jid;@e2%SS z@ZzB-=y`?{FYx|LoD+EZ43{|X8+(aV3!d^sYZ*=-+BiQz2nVV75aR6L3R=7(wF-^$ z@d>U|Z!iB(;06JH%3UP$58?u8&f5jIC>E2Lsy(OQM*jsYh`K%9^xBP8=z;t#dietJ*6lw_0pXW@u*6>Q_()Hu>jQ(Z^aMX+=3r# TG4T`EKl4!$ah}=wxTEVo)P;$g literal 0 HcmV?d00001 diff --git a/target/classes/com/inventory/im/controller/ProductController.class b/target/classes/com/inventory/im/controller/ProductController.class new file mode 100644 index 0000000000000000000000000000000000000000..985d3c0ba21d22e2fd48af81327a5233727e5f6c GIT binary patch literal 5483 zcmcgw2X_?L8NE+!q-7*z1#kow$P`-z7%(N+!q_0dC>BDNK#t=iFxnkSgJx%zDI&7t zRHygm^qx39v5B)Z$Fbv7$LYQI_9t?3-^}dpEIZ2|?S0>U_j^xI{rkdW z0QTZv3hD$lWu3fc+H;2OJMO$@=C!P2`>tbIhO3RbPAQu3{L6Da$xx*{XEMqP-I>5ICZu5ltD~fpG<6 z0@v3RKAnP8bl|AKzLY&wg)8pP8jIBe3P?0pg}4cP)6x#<-VC=z2FK9ajJwDQF;5;h zbFvI~t9TxsFVHAUnj-;KWqH^k=9b_%bOk2_S}S&GQ^h2*qXoP4+T!-CmH*^6OM!S@SJ0F{|Jtw^SM_hb(o7R5eca z4m=eW@-#j;c3|((1N#Lwq_W8+TCBQ*Qwj