|
| 1 | +# 🐳 Docker Compose Setup for mod-kb-ebsco-java |
| 2 | + |
| 3 | +Local development environment for mod-kb-ebsco-java using Docker Compose. |
| 4 | + |
| 5 | +## 📋 Prerequisites |
| 6 | + |
| 7 | +- Docker and Docker Compose V2+ |
| 8 | +- Java 21+ (for local development mode) |
| 9 | +- Maven 3.6+ (for building the module) |
| 10 | + |
| 11 | +## 🏗️ Architecture |
| 12 | + |
| 13 | +Two compose files provide flexible development workflows: |
| 14 | + |
| 15 | +- **`infra-docker-compose.yml`**: Infrastructure services only (PostgreSQL, WireMock, etc.) |
| 16 | +- **`app-docker-compose.yml`**: Full stack including the module (uses `include` to incorporate infra services) |
| 17 | + |
| 18 | +## ⚙️ Configuration |
| 19 | + |
| 20 | +Configuration is managed via the `.env` file in this directory. |
| 21 | + |
| 22 | +### Environment Variables |
| 23 | + |
| 24 | +| Variable | Default Value | Description | |
| 25 | +|----------------------------|---------------------------|-----------------------------------| |
| 26 | +| `COMPOSE_PROJECT_NAME` | `folio-mod-kb-ebsco-java` | Docker Compose project name | |
| 27 | +| **Module Configuration** | | | |
| 28 | +| `ENV` | `folio` | Environment name | |
| 29 | +| `MODULE_PORT` | `8081` | Module host port | |
| 30 | +| `MODULE_REPLICAS` | `1` | Number of module instances to run | |
| 31 | +| `DEBUG_PORT` | `5005` | Remote debugging port | |
| 32 | +| **Database Configuration** | | | |
| 33 | +| `DB_HOST` | `postgres` | PostgreSQL hostname | |
| 34 | +| `DB_PORT` | `5432` | PostgreSQL port | |
| 35 | +| `DB_DATABASE` | `modules` | Database name | |
| 36 | +| `DB_USERNAME` | `folio_admin` | Database username | |
| 37 | +| `DB_PASSWORD` | `folio_admin` | Database password | |
| 38 | +| **pgAdmin Configuration** | | | |
| 39 | +| `PGADMIN_DEFAULT_EMAIL` | `user@domain.com` | pgAdmin login email | |
| 40 | +| `PGADMIN_DEFAULT_PASSWORD` | `admin` | pgAdmin login password | |
| 41 | +| `PGADMIN_PORT` | `5050` | pgAdmin web interface port | |
| 42 | +| **WireMock Configuration** | | | |
| 43 | +| `OKAPI_URL` | `http://wiremock:8080` | Okapi URL for the module | |
| 44 | +| `WIREMOCK_PORT` | `9130` | WireMock (Okapi mock) port | |
| 45 | + |
| 46 | +## 🚀 Services |
| 47 | + |
| 48 | +### PostgreSQL |
| 49 | + |
| 50 | +- **Purpose**: Primary database for module data |
| 51 | +- **Version**: PostgreSQL 16 Alpine |
| 52 | +- **Access**: localhost:5432 (configurable via `DB_PORT`) |
| 53 | +- **Credentials**: See `DB_USERNAME` and `DB_PASSWORD` in `.env` |
| 54 | +- **Database**: See `DB_DATABASE` in `.env` |
| 55 | + |
| 56 | +### pgAdmin |
| 57 | + |
| 58 | +- **Purpose**: Database administration interface |
| 59 | +- **Access**: http://localhost:5050 (configurable via `PGADMIN_PORT`) |
| 60 | +- **Login**: Use `PGADMIN_DEFAULT_EMAIL` and `PGADMIN_DEFAULT_PASSWORD` from `.env` |
| 61 | + |
| 62 | +### WireMock |
| 63 | + |
| 64 | +- **Purpose**: Mock Okapi and other FOLIO modules for testing |
| 65 | +- **Access**: http://localhost:9130 (configurable via `WIREMOCK_PORT`) |
| 66 | +- **Mappings**: Located in `src/test/resources/mappings` |
| 67 | + |
| 68 | +## 📖 Usage |
| 69 | +### Starting the Environment |
| 70 | + |
| 71 | +```bash |
| 72 | +# Build the module first |
| 73 | +mvn clean package -DskipTests |
| 74 | +``` |
| 75 | +> **Note**: All further commands in this guide assume you are in the `docker/` directory. If you're at the project root, |
| 76 | +> run `cd docker` first. |
| 77 | +
|
| 78 | +```bash |
| 79 | +# Start all services (infrastructure + module) |
| 80 | +docker compose -f app-docker-compose.yml up -d |
| 81 | +``` |
| 82 | + |
| 83 | +```bash |
| 84 | +# Start only infrastructure services (for local development) |
| 85 | +docker compose -f infra-docker-compose.yml up -d |
| 86 | +``` |
| 87 | + |
| 88 | +```bash |
| 89 | +# Start with build (if module code changed) |
| 90 | +docker compose -f app-docker-compose.yml up -d --build |
| 91 | +``` |
| 92 | + |
| 93 | +```bash |
| 94 | +# Start specific service |
| 95 | +docker compose -f infra-docker-compose.yml up -d postgres |
| 96 | +``` |
| 97 | + |
| 98 | +### Stopping the Environment |
| 99 | + |
| 100 | +```bash |
| 101 | +# Stop all services |
| 102 | +docker compose -f app-docker-compose.yml down |
| 103 | +``` |
| 104 | + |
| 105 | +```bash |
| 106 | +# Stop infra services only |
| 107 | +docker compose -f infra-docker-compose.yml down |
| 108 | +``` |
| 109 | + |
| 110 | +```bash |
| 111 | +# Stop and remove volumes (clean slate) |
| 112 | +docker compose -f app-docker-compose.yml down -v |
| 113 | +``` |
| 114 | + |
| 115 | +### Viewing Logs |
| 116 | + |
| 117 | +```bash |
| 118 | +# All services |
| 119 | +docker compose -f app-docker-compose.yml logs |
| 120 | +``` |
| 121 | + |
| 122 | +```bash |
| 123 | +# Specific service |
| 124 | +docker compose -f app-docker-compose.yml logs mod-kb-ebsco-java |
| 125 | +``` |
| 126 | + |
| 127 | +```bash |
| 128 | +# Follow logs in real-time |
| 129 | +docker compose -f app-docker-compose.yml logs -f mod-kb-ebsco-java |
| 130 | +``` |
| 131 | + |
| 132 | +```bash |
| 133 | +# Last 100 lines |
| 134 | +docker compose -f app-docker-compose.yml logs --tail=100 mod-kb-ebsco-java |
| 135 | +``` |
| 136 | + |
| 137 | +### Scaling the Module |
| 138 | + |
| 139 | +The module is configured with resource limits and deployment policies for production-like scaling: |
| 140 | + |
| 141 | +- **CPU Limits**: 0.5 CPU (max), 0.25 CPU (reserved) |
| 142 | +- **Memory Limits**: 512M (max), 256M (reserved) |
| 143 | +- **Restart Policy**: Automatic restart on failure |
| 144 | + |
| 145 | +```bash |
| 146 | +# Scale to 3 instances |
| 147 | +docker compose -f app-docker-compose.yml up -d --scale mod-kb-ebsco-java=3 |
| 148 | +``` |
| 149 | + |
| 150 | +```bash |
| 151 | +# Or modify MODULE_REPLICAS in .env and restart |
| 152 | +echo "MODULE_REPLICAS=3" >> .env |
| 153 | +docker compose -f app-docker-compose.yml up -d |
| 154 | +``` |
| 155 | + |
| 156 | +### Cleanup and Reset |
| 157 | + |
| 158 | +```bash |
| 159 | +# Complete cleanup (stops containers, removes volumes) |
| 160 | +docker compose -f app-docker-compose.yml down -v |
| 161 | +``` |
| 162 | + |
| 163 | +```bash |
| 164 | +# Remove all Docker resources |
| 165 | +docker compose -f app-docker-compose.yml down -v |
| 166 | +docker volume prune -f |
| 167 | +docker network prune -f |
| 168 | +``` |
| 169 | + |
| 170 | +## 🛠️ Development |
| 171 | + |
| 172 | +### IntelliJ IDEA usage |
| 173 | + |
| 174 | +Run `docker compose -f infra-docker-compose.yml up -d` to start the infrastructure services. |
| 175 | +Customize the `dev` profile if needed, or use the default values. |
| 176 | +To activate this profile, set `application-dev.properties` in the `placeholderConfigurer` bean in the `ApplicationConfig` class. |
| 177 | + |
| 178 | +#### IntelliJ Application configuration using RestLauncher with the following settings: |
| 179 | +- Run → Edit Configurations → + → Application |
| 180 | +- Main class: `org.folio.rest.RestLauncher` |
| 181 | +- Program arguments: `org.folio.rest.RestVerticle` |
| 182 | +- Environment variables: |
| 183 | +```bash |
| 184 | +DB_HOST=localhost |
| 185 | +DB_PORT=5432 |
| 186 | +DB_DATABASE=modules |
| 187 | +DB_USERNAME=folio_admin |
| 188 | +DB_PASSWORD=folio_admin |
| 189 | +``` |
| 190 | +### Building the Module |
| 191 | + |
| 192 | +It's expected that the module is packaged to jar before building the Docker image. Use `mvn clean package` to build the |
| 193 | +jar. |
| 194 | + |
| 195 | +```bash |
| 196 | +# Build only the module image |
| 197 | +docker compose -f app-docker-compose.yml build mod-kb-ebsco-java |
| 198 | +``` |
| 199 | + |
| 200 | +```bash |
| 201 | +# Build with no cache |
| 202 | +docker compose -f app-docker-compose.yml build --no-cache mod-kb-ebsco-java |
| 203 | +``` |
| 204 | + |
| 205 | +### Connecting to Services |
| 206 | + |
| 207 | +```bash |
| 208 | +# Connect to PostgreSQL |
| 209 | +docker compose -f app-docker-compose.yml exec postgres psql -U folio_admin -d modules |
| 210 | +``` |
| 211 | + |
| 212 | +```bash |
| 213 | +# Check PostgreSQL health |
| 214 | +docker compose -f infra-docker-compose.yml exec postgres pg_isready -U folio_admin |
| 215 | +``` |
| 216 | + |
| 217 | +```bash |
| 218 | +# Connect to module container |
| 219 | +docker compose -f app-docker-compose.yml exec mod-kb-ebsco-java sh |
| 220 | +``` |
0 commit comments