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
48 changes: 40 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ Resource server introspection credentials (confidential client in Keycloak):
- `KEYCLOAK_RESOURCE_CLIENT_ID`
- `KEYCLOAK_RESOURCE_CLIENT_SECRET`

### 1. Start Keycloak (with automatic realm import)
### 1. Compose files layout

```bash
docker compose up -d
- `docker-compose.yaml` - shared stack (databases, Keycloak, observability, common `jwt-demo` settings)
- `docker-compose.dev.yaml` - dev override for `jwt-demo` (Maven container + source mount + watch)
- `docker-compose.prod.yaml` - prod override for `jwt-demo` (image build from `Dockerfile`)

### 2. Start in DEV mode (auto-restart on code changes)

```pwsh
docker compose -f docker-compose.yaml -f docker-compose.dev.yaml up --build --watch
```

Keycloak automatically imports:
Expand All @@ -85,18 +91,44 @@ Keycloak automatically imports:
- client `spring-app`
- protocol mappers (roles → access_token)

Keycloak UI:
### 3. Start in PROD mode

```
http://localhost:8080
```pwsh
docker compose -f docker-compose.yaml -f docker-compose.prod.yaml up -d --build
```

### 2. Start Spring Boot
### 4. Alternative local run (without app container)

```bash
```pwsh
docker compose up -d postgres postgres-app keycloak
```

```pwsh
mvn spring-boot:run
```

### 5. Stop and cleanup

DEV mode:

```pwsh
docker compose -f docker-compose.yaml -f docker-compose.dev.yaml down
docker compose -f docker-compose.yaml -f docker-compose.dev.yaml down -v
```

PROD mode:

```pwsh
docker compose -f docker-compose.yaml -f docker-compose.prod.yaml down
docker compose -f docker-compose.yaml -f docker-compose.prod.yaml down -v
```

Keycloak UI:

```
http://localhost:8080
```

Application runs at:

```
Expand Down
27 changes: 27 additions & 0 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3.9"

services:
jwt-demo:
image: maven:3.9-eclipse-temurin-25
container_name: jwt-demo-dev
working_dir: /workspace
command: mvn -DskipTests spring-boot:run
environment:
SPRING_PROFILES_ACTIVE: dev
OTEL_RESOURCE_ATTRIBUTES: service.name=jwt-demo,service.namespace=jwt-demo,deployment.environment=dev
volumes:
- ./:/workspace
- maven-cache:/root/.m2
develop:
watch:
- action: sync+restart
path: ./src
target: /workspace/src
- action: rebuild
path: ./pom.xml

volumes:
maven-cache:



14 changes: 14 additions & 0 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3.9"

services:
jwt-demo:
build:
context: .
dockerfile: Dockerfile
container_name: jwt-demo
restart: unless-stopped
environment:
SPRING_PROFILES_ACTIVE: prod
OTEL_RESOURCE_ATTRIBUTES: service.name=jwt-demo,service.namespace=jwt-demo,deployment.environment=prod


7 changes: 1 addition & 6 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,12 @@ services:
# JWT DEMO APPLICATION
# ------------------------------------------------------------
jwt-demo:
build:
context: .
dockerfile: Dockerfile
container_name: jwt-demo
ports:
- "8081:8081"
environment:
SPRING_PROFILES_ACTIVE: prod
SPRING_PROFILES_ACTIVE: local
KEYCLOAK_AUTH_SERVER_URL: http://keycloak:8080

# 👉 Добавляем параметры подключения к новой БД
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres-app:5432/appdb
SPRING_DATASOURCE_USERNAME: app
SPRING_DATASOURCE_PASSWORD: ${APP_DB_PASSWORD}
Expand Down
Loading