Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
target/
.mvn/
.idea/
*.iml
.classpath
.project
.settings/
.git/
node_modules/
logs/
*.log
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.compile.nullAnalysis.mode": "automatic"
}
27 changes: 27 additions & 0 deletions Docker-README.md
Original file line number Diff line number Diff line change
@@ -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://<host>: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
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
9 changes: 1 addition & 8 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
13 changes: 13 additions & 0 deletions target/classes/application.properties
Original file line number Diff line number Diff line change
@@ -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
Binary file added target/classes/com/inventory/im/ImApplication.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added target/classes/com/inventory/im/model/User.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions wait-for-it.sh
Original file line number Diff line number Diff line change
@@ -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
Loading