Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ---- Stage 1: Build ----
# Uses the full JDK image to compile the application with Maven
FROM eclipse-temurin:25-jdk AS build
WORKDIR /app

# Copy Maven wrapper and pom.xml first to leverage Docker layer caching
# Dependencies are downloaded only when pom.xml changes
COPY mvnw pom.xml ./
COPY .mvn .mvn
RUN chmod +x mvnw && ./mvnw dependency:go-offline -B
Comment thread
MayuriXx marked this conversation as resolved.

# Copy source code and build the JAR (tests are skipped as they run in CI)
COPY src src
RUN ./mvnw package -DskipTests -B
Comment thread
MayuriXx marked this conversation as resolved.

# ---- Stage 2: Run ----
# Uses a lightweight JRE-only image for a smaller and more secure final image
FROM eclipse-temurin:25-jre
WORKDIR /app

# Create a non-root user and group for running the application securely
RUN groupadd --system appgroup && useradd --system --gid appgroup appuser

# Copy the built JAR from the build stage (explicit name to avoid matching multiple artifacts)
COPY --from=build /app/target/spring_boot_java_random_user-0.0.1-SNAPSHOT.jar app.jar
Comment thread
MayuriXx marked this conversation as resolved.
Outdated

# Ensure the non-root user owns the application files
RUN chown -R appuser:appgroup /app

# Switch to the non-root user
USER appuser

# Document the port the application listens on
EXPOSE 8080

# Start the Spring Boot application
ENTRYPOINT ["java", "-jar", "app.jar"]
Comment thread
MayuriXx marked this conversation as resolved.
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,68 @@ docker-compose up -d

---

## 🐳 Docker

### Architecture

L'application peut être entièrement conteneurisée via un **Dockerfile multi-stage** et **Docker Compose**.

Comment thread
MayuriXx marked this conversation as resolved.
Comment thread
MayuriXx marked this conversation as resolved.
```
┌─────────────────── xpeho_network (bridge) ───────────────────┐
│ │
│ ┌──────────┐ jdbc:postgresql:// ┌──────────┐ │
│ │ app │ ──────── postgres:5432 ────────▶ │ postgres │ │
│ │ :8080 │ (nom du service) │ :5432 │ │
│ └──────────┘ └──────────┘ │
│ │
└───────────────────────────────────────────────────────────────┘
```

| Service | Image / Build | Rôle | Port exposé |
|------------|------------------------------|----------------------------|---------------------------|
| `postgres` | `postgres:17-alpine` | Base de données PostgreSQL | `${POSTGRES_PORT}` → 5432 |
| `app` | Build depuis `Dockerfile` | Application Spring Boot | 8080 → 8080 |

### Dockerfile — Build multi-stage

Le Dockerfile utilise deux étapes pour produire une image finale légère et sécurisée :

| Stage | Image | Rôle |
|-------|-------|------|
| **Build** | `eclipse-temurin:25-jdk` | Compile le JAR avec Maven (JDK complet) |
| **Run** | `eclipse-temurin:25-jre` | Exécute l'application (JRE allégé, utilisateur non-root) |

> **Pourquoi Eclipse Temurin ?** Distribution OpenJDK de référence : gratuite, open-source, maintenue par la fondation Eclipse (Adoptium).

> **Sécurité :** L'image finale tourne avec un utilisateur non-root (`appuser`), sans code source ni outils de build.

### Compose Profiles

Le service `app` est derrière un **profil Compose** pour ne pas interférer avec le workflow dev/CI :

```bash
# Démarrer uniquement PostgreSQL (dev, tests, CI)
docker compose up -d

# Démarrer PostgreSQL + Application (déploiement complet)
docker compose --profile app up -d --build
```
Comment thread
MayuriXx marked this conversation as resolved.
Comment thread
MayuriXx marked this conversation as resolved.
Comment thread
MayuriXx marked this conversation as resolved.

### Commandes utiles

```bash
# Voir les logs de l'application
docker compose logs -f app

# Arrêter et supprimer les conteneurs
docker compose down

# Arrêter et supprimer les conteneurs + volumes (reset DB)
docker compose down -v
```

---

## ⚙️ Configuration

### Environment Variables (.env)
Expand All @@ -56,6 +118,11 @@ POSTGRES_USER=your_user
POSTGRES_PASSWORD=your_password
POSTGRES_DB=your_database
POSTGRES_PORT=5432

# Liquibase (optionnel, valeurs par défaut fournies)
LB_CHANGELOG=db/changelog/db.changelog-master.yaml
LB_SCHEMA=public
SPRING_LIQUIBASE_ENABLED=true
```

### External API Configuration
Expand Down
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ services:
networks:
- xpeho_network

app:
profiles:
- app
build:
context: .
dockerfile: Dockerfile
Comment thread
MayuriXx marked this conversation as resolved.
container_name: xpeho_app
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_PORT: 5432
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/${POSTGRES_DB}
SPRING_LIQUIBASE_ENABLED: ${SPRING_LIQUIBASE_ENABLED:-true}
LB_CHANGELOG: ${LB_CHANGELOG:-db/changelog/db.changelog-master.yaml}
LB_SCHEMA: ${LB_SCHEMA:-public}
ports:
- "8080:8080"
Comment thread
MayuriXx marked this conversation as resolved.
depends_on:
postgres:
condition: service_healthy
networks:
- xpeho_network

volumes:
postgres_data:
driver: local
Expand Down
Loading