Skip to content

Commit 850d28a

Browse files
committed
feat(docker_launch_app): add dockerfile for start the app
1 parent 4c0bb39 commit 850d28a

3 files changed

Lines changed: 128 additions & 0 deletions

File tree

Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# ---- Stage 1: Build ----
2+
# Uses the full JDK image to compile the application with Maven
3+
FROM eclipse-temurin:25-jdk AS build
4+
WORKDIR /app
5+
6+
# Copy Maven wrapper and pom.xml first to leverage Docker layer caching
7+
# Dependencies are downloaded only when pom.xml changes
8+
COPY mvnw pom.xml ./
9+
COPY .mvn .mvn
10+
RUN chmod +x mvnw && ./mvnw dependency:go-offline -B
11+
12+
# Copy source code and build the JAR (tests are skipped as they run in CI)
13+
COPY src src
14+
RUN ./mvnw package -DskipTests -B
15+
16+
# ---- Stage 2: Run ----
17+
# Uses a lightweight JRE-only image for a smaller and more secure final image
18+
FROM eclipse-temurin:25-jre
19+
WORKDIR /app
20+
21+
# Create a non-root user and group for running the application securely
22+
RUN groupadd --system appgroup && useradd --system --gid appgroup appuser
23+
24+
# Copy the built JAR from the build stage (explicit name to avoid matching multiple artifacts)
25+
COPY --from=build /app/target/spring_boot_java_random_user-0.0.1-SNAPSHOT.jar app.jar
26+
27+
# Ensure the non-root user owns the application files
28+
RUN chown -R appuser:appgroup /app
29+
30+
# Switch to the non-root user
31+
USER appuser
32+
33+
# Document the port the application listens on
34+
EXPOSE 8080
35+
36+
# Start the Spring Boot application
37+
ENTRYPOINT ["java", "-jar", "app.jar"]

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,68 @@ docker-compose up -d
4747

4848
---
4949

50+
## 🐳 Docker
51+
52+
### Architecture
53+
54+
L'application peut être entièrement conteneurisée via un **Dockerfile multi-stage** et **Docker Compose**.
55+
56+
```
57+
┌─────────────────── xpeho_network (bridge) ───────────────────┐
58+
│ │
59+
│ ┌──────────┐ jdbc:postgresql:// ┌──────────┐ │
60+
│ │ app │ ──────── postgres:5432 ────────▶ │ postgres │ │
61+
│ │ :8080 │ (nom du service) │ :5432 │ │
62+
│ └──────────┘ └──────────┘ │
63+
│ │
64+
└───────────────────────────────────────────────────────────────┘
65+
```
66+
67+
| Service | Image / Build | Rôle | Port exposé |
68+
|------------|------------------------------|----------------------------|---------------------------|
69+
| `postgres` | `postgres:17-alpine` | Base de données PostgreSQL | `${POSTGRES_PORT}` → 5432 |
70+
| `app` | Build depuis `Dockerfile` | Application Spring Boot | 8080 → 8080 |
71+
72+
### Dockerfile — Build multi-stage
73+
74+
Le Dockerfile utilise deux étapes pour produire une image finale légère et sécurisée :
75+
76+
| Stage | Image | Rôle |
77+
|-------|-------|------|
78+
| **Build** | `eclipse-temurin:25-jdk` | Compile le JAR avec Maven (JDK complet) |
79+
| **Run** | `eclipse-temurin:25-jre` | Exécute l'application (JRE allégé, utilisateur non-root) |
80+
81+
> **Pourquoi Eclipse Temurin ?** Distribution OpenJDK de référence : gratuite, open-source, maintenue par la fondation Eclipse (Adoptium).
82+
83+
> **Sécurité :** L'image finale tourne avec un utilisateur non-root (`appuser`), sans code source ni outils de build.
84+
85+
### Compose Profiles
86+
87+
Le service `app` est derrière un **profil Compose** pour ne pas interférer avec le workflow dev/CI :
88+
89+
```bash
90+
# Démarrer uniquement PostgreSQL (dev, tests, CI)
91+
docker compose up -d
92+
93+
# Démarrer PostgreSQL + Application (déploiement complet)
94+
docker compose --profile app up -d --build
95+
```
96+
97+
### Commandes utiles
98+
99+
```bash
100+
# Voir les logs de l'application
101+
docker compose logs -f app
102+
103+
# Arrêter et supprimer les conteneurs
104+
docker compose down
105+
106+
# Arrêter et supprimer les conteneurs + volumes (reset DB)
107+
docker compose down -v
108+
```
109+
110+
---
111+
50112
## ⚙️ Configuration
51113

52114
### Environment Variables (.env)
@@ -56,6 +118,11 @@ POSTGRES_USER=your_user
56118
POSTGRES_PASSWORD=your_password
57119
POSTGRES_DB=your_database
58120
POSTGRES_PORT=5432
121+
122+
# Liquibase (optionnel, valeurs par défaut fournies)
123+
LB_CHANGELOG=db/changelog/db.changelog-master.yaml
124+
LB_SCHEMA=public
125+
SPRING_LIQUIBASE_ENABLED=true
59126
```
60127

61128
### External API Configuration

docker-compose.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,30 @@ services:
1818
networks:
1919
- xpeho_network
2020

21+
app:
22+
profiles:
23+
- app
24+
build:
25+
context: .
26+
dockerfile: Dockerfile
27+
container_name: xpeho_app
28+
environment:
29+
POSTGRES_USER: ${POSTGRES_USER}
30+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
31+
POSTGRES_DB: ${POSTGRES_DB}
32+
POSTGRES_PORT: 5432
33+
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/${POSTGRES_DB}
34+
SPRING_LIQUIBASE_ENABLED: ${SPRING_LIQUIBASE_ENABLED:-true}
35+
LB_CHANGELOG: ${LB_CHANGELOG:-db/changelog/db.changelog-master.yaml}
36+
LB_SCHEMA: ${LB_SCHEMA:-public}
37+
ports:
38+
- "8080:8080"
39+
depends_on:
40+
postgres:
41+
condition: service_healthy
42+
networks:
43+
- xpeho_network
44+
2145
volumes:
2246
postgres_data:
2347
driver: local

0 commit comments

Comments
 (0)