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..1db1f34 --- /dev/null +++ b/Docker-README.md @@ -0,0 +1,27 @@ +# Inventory Management Tool - Docker Setup + +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 to run the service together with a MySQL database. + +--- + +## Quick Commands + +```bash +# Build Docker image +docker build -t im-app:latest . + +# Run the Docker image +docker run --rm -p 8082:8082 \ + -e SPRING_DATASOURCE_URL='jdbc:mysql://:3306/inventory_db?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC' \ + -e SPRING_DATASOURCE_USERNAME=root \ + -e SPRING_DATASOURCE_PASSWORD=Anjana@3176 \ + im-app:latest + +# Start using Docker Compose +docker compose up --build + +# Stop Docker Compose +docker compose down + +# View logs +docker compose logs -f 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/README.md b/README.md index f741cab..820f9f2 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,12 @@ spring.datasource.username=your_username spring.datasource.password=your_password +🌏 Docker Hub Image + +You can directly pull and run the pre-built image from Docker Hub: + +docker pull atulsingh17/opcode-inventorymanagement:1.0 +docker run -p 8080:8082 atulsingh17/opcode-inventorymanagement:1.0 3. **Build and run** ```bash 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 0000000..0a66fad Binary files /dev/null and b/target/classes/com/inventory/im/ImApplication.class differ diff --git a/target/classes/com/inventory/im/config/SecurityConfig.class b/target/classes/com/inventory/im/config/SecurityConfig.class new file mode 100644 index 0000000..8bf0169 Binary files /dev/null and b/target/classes/com/inventory/im/config/SecurityConfig.class differ diff --git a/target/classes/com/inventory/im/controller/AuthController.class b/target/classes/com/inventory/im/controller/AuthController.class new file mode 100644 index 0000000..230b0fd Binary files /dev/null and b/target/classes/com/inventory/im/controller/AuthController.class differ 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 0000000..985d3c0 Binary files /dev/null and b/target/classes/com/inventory/im/controller/ProductController.class differ diff --git a/target/classes/com/inventory/im/dto/AuthResponse.class b/target/classes/com/inventory/im/dto/AuthResponse.class new file mode 100644 index 0000000..f6b7302 Binary files /dev/null and b/target/classes/com/inventory/im/dto/AuthResponse.class differ diff --git a/target/classes/com/inventory/im/dto/ProductRequest.class b/target/classes/com/inventory/im/dto/ProductRequest.class new file mode 100644 index 0000000..73eea65 Binary files /dev/null and b/target/classes/com/inventory/im/dto/ProductRequest.class differ diff --git a/target/classes/com/inventory/im/dto/QuantityUpdateRequest.class b/target/classes/com/inventory/im/dto/QuantityUpdateRequest.class new file mode 100644 index 0000000..4648e32 Binary files /dev/null and b/target/classes/com/inventory/im/dto/QuantityUpdateRequest.class differ diff --git a/target/classes/com/inventory/im/dto/UserLoginRequest.class b/target/classes/com/inventory/im/dto/UserLoginRequest.class new file mode 100644 index 0000000..96a5411 Binary files /dev/null and b/target/classes/com/inventory/im/dto/UserLoginRequest.class differ diff --git a/target/classes/com/inventory/im/dto/UserRegisterRequest.class b/target/classes/com/inventory/im/dto/UserRegisterRequest.class new file mode 100644 index 0000000..8db9c0f Binary files /dev/null and b/target/classes/com/inventory/im/dto/UserRegisterRequest.class differ diff --git a/target/classes/com/inventory/im/model/Product.class b/target/classes/com/inventory/im/model/Product.class new file mode 100644 index 0000000..dee7dbc Binary files /dev/null and b/target/classes/com/inventory/im/model/Product.class differ diff --git a/target/classes/com/inventory/im/model/User.class b/target/classes/com/inventory/im/model/User.class new file mode 100644 index 0000000..b9e9775 Binary files /dev/null and b/target/classes/com/inventory/im/model/User.class differ diff --git a/target/classes/com/inventory/im/repository/ProductRepository.class b/target/classes/com/inventory/im/repository/ProductRepository.class new file mode 100644 index 0000000..0356f2c Binary files /dev/null and b/target/classes/com/inventory/im/repository/ProductRepository.class differ diff --git a/target/classes/com/inventory/im/repository/UserRepository.class b/target/classes/com/inventory/im/repository/UserRepository.class new file mode 100644 index 0000000..41fa8c0 Binary files /dev/null and b/target/classes/com/inventory/im/repository/UserRepository.class differ diff --git a/target/classes/com/inventory/im/security/JwtAuthenticationFilter.class b/target/classes/com/inventory/im/security/JwtAuthenticationFilter.class new file mode 100644 index 0000000..5fa11eb Binary files /dev/null and b/target/classes/com/inventory/im/security/JwtAuthenticationFilter.class differ diff --git a/target/classes/com/inventory/im/security/JwtUtil.class b/target/classes/com/inventory/im/security/JwtUtil.class new file mode 100644 index 0000000..d8cd1ce Binary files /dev/null and b/target/classes/com/inventory/im/security/JwtUtil.class differ diff --git a/target/classes/com/inventory/im/service/ProductService.class b/target/classes/com/inventory/im/service/ProductService.class new file mode 100644 index 0000000..815c134 Binary files /dev/null and b/target/classes/com/inventory/im/service/ProductService.class differ diff --git a/target/classes/com/inventory/im/service/UserService.class b/target/classes/com/inventory/im/service/UserService.class new file mode 100644 index 0000000..866c071 Binary files /dev/null and b/target/classes/com/inventory/im/service/UserService.class differ diff --git a/target/test-classes/com/inventory/im/ImApplicationTests.class b/target/test-classes/com/inventory/im/ImApplicationTests.class new file mode 100644 index 0000000..b373cb5 Binary files /dev/null and b/target/test-classes/com/inventory/im/ImApplicationTests.class differ diff --git a/wait-for-it.sh b/wait-for-it.sh new file mode 100644 index 0000000..012eb0b --- /dev/null +++ b/wait-for-it.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# wait-for-it.sh +# Use this script to test if a given TCP host/port are available + +set -e + +HOST="$1" +PORT="$2" +shift 2 +CMD="$@" + +echo "⏳ Waiting for $HOST:$PORT to be available..." + +while ! nc -z "$HOST" "$PORT"; do + echo "MySQL at $HOST:$PORT not yet available..." + sleep 3 +done + +echo "✅ $HOST:$PORT is available — starting application..." +exec $CMD