mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 13:26:51 +00:00
feature/OBP API – Docker & Docker Compose Setup
This commit is contained in:
parent
06faaebbdb
commit
9ab4aa90f6
18
docker/Dockerfile
Normal file
18
docker/Dockerfile
Normal file
@ -0,0 +1,18 @@
|
||||
FROM maven:3.9.6-eclipse-temurin-17
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy all project files into container
|
||||
COPY . .
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
# Build the project, skip tests to speed up
|
||||
RUN mvn install -pl .,obp-commons -am -DskipTests
|
||||
|
||||
# Copy entrypoint script that runs mvn with needed JVM flags
|
||||
COPY docker/entrypoint.sh /app/entrypoint.sh
|
||||
RUN chmod +x /app/entrypoint.sh
|
||||
|
||||
# Use script as entrypoint
|
||||
CMD ["/app/entrypoint.sh"]
|
||||
96
docker/README.md
Normal file
96
docker/README.md
Normal file
@ -0,0 +1,96 @@
|
||||
## OBP API – Docker & Docker Compose Setup
|
||||
|
||||
This project uses Docker and Docker Compose to run the **OBP API** service with Maven and Jetty.
|
||||
|
||||
- Java 17 with reflection workaround
|
||||
- Connects to your local Postgres using `host.docker.internal`
|
||||
- Supports separate dev & prod setups
|
||||
|
||||
---
|
||||
|
||||
## How to use
|
||||
|
||||
> **Make sure you have Docker and Docker Compose installed.**
|
||||
|
||||
### Set up the database connection
|
||||
|
||||
Edit your `default.properties` (or similar config file):
|
||||
|
||||
```properties
|
||||
db.url=jdbc:postgresql://host.docker.internal:5432/YOUR_DB_NAME?user=YOUR_DB_USER&password=YOUR_DB_PASSWORD
|
||||
````
|
||||
|
||||
> Use `host.docker.internal` so the container can reach your local database.
|
||||
|
||||
---
|
||||
|
||||
### Build & run (production mode)
|
||||
|
||||
Build the Docker image and run the container:
|
||||
|
||||
```bash
|
||||
docker-compose up --build
|
||||
```
|
||||
|
||||
The service will be available at [http://localhost:8080](http://localhost:8080).
|
||||
|
||||
---
|
||||
|
||||
## Development tips
|
||||
|
||||
For live code updates without rebuilding:
|
||||
|
||||
* Use the provided `docker-compose.override.yml` which mounts only:
|
||||
|
||||
```yaml
|
||||
volumes:
|
||||
- ../obp-api:/app/obp-api
|
||||
- ../obp-commons:/app/obp-commons
|
||||
```
|
||||
* This keeps other built files (like `entrypoint.sh`) intact.
|
||||
* Avoid mounting the full `../:/app` because it overwrites the built image.
|
||||
|
||||
---
|
||||
|
||||
## Useful commands
|
||||
|
||||
Rebuild the image and restart:
|
||||
|
||||
```bash
|
||||
docker-compose up --build
|
||||
```
|
||||
|
||||
Stop the container:
|
||||
|
||||
```bash
|
||||
docker-compose down
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Before first run
|
||||
|
||||
Make sure your entrypoint script is executable:
|
||||
|
||||
```bash
|
||||
chmod +x docker/entrypoint.sh
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Notes
|
||||
|
||||
* The container uses `MAVEN_OPTS` to pass JVM `--add-opens` flags needed by Lift.
|
||||
* In production, avoid volume mounts for better performance and consistency.
|
||||
|
||||
---
|
||||
|
||||
That’s it — now you can run:
|
||||
|
||||
```bash
|
||||
docker-compose up --build
|
||||
```
|
||||
|
||||
and start coding!
|
||||
|
||||
```
|
||||
7
docker/docker-compose.override.yml
Normal file
7
docker/docker-compose.override.yml
Normal file
@ -0,0 +1,7 @@
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
obp-api:
|
||||
volumes:
|
||||
- ../obp-api:/app/obp-api
|
||||
- ../obp-commons:/app/obp-commons
|
||||
14
docker/docker-compose.yml
Normal file
14
docker/docker-compose.yml
Normal file
@ -0,0 +1,14 @@
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
obp-api:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: docker/Dockerfile
|
||||
ports:
|
||||
- "8080:8080"
|
||||
extra_hosts:
|
||||
# Connect to local Postgres on the host
|
||||
# In your config file:
|
||||
# db.url=jdbc:postgresql://host.docker.internal:5432/YOUR_DB?user=YOUR_DB_USER&password=YOUR_DB_PASSWORD
|
||||
- "host.docker.internal:host-gateway"
|
||||
9
docker/entrypoint.sh
Normal file
9
docker/entrypoint.sh
Normal file
@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
export MAVEN_OPTS="-Xss128m \
|
||||
--add-opens=java.base/java.util.jar=ALL-UNNAMED \
|
||||
--add-opens=java.base/java.lang=ALL-UNNAMED \
|
||||
--add-opens=java.base/java.lang.reflect=ALL-UNNAMED"
|
||||
|
||||
exec mvn jetty:run -pl obp-api
|
||||
Loading…
Reference in New Issue
Block a user