Simplify using an interceptor with Docker
Now it is possible to mount a folder with extra classes that are loaded by HAPI. This makes it easy to load an interceptor JAR while using the standard Docker image. The README explains how to use it. Spring by default uses the WarLauncher. Now the ENTRYPOINT uses the PropertiesLauncher, configured in such a way that it is compatible with the WarLauncher, but adding the folder /app/extra-classes to the loader.path.
This commit is contained in:
committed by
Jens Kristian Villadsen
parent
43890a4b9d
commit
7e0fb80dac
@@ -46,4 +46,4 @@ WORKDIR /app
|
|||||||
COPY --chown=nonroot:nonroot --from=build-distroless /app /app
|
COPY --chown=nonroot:nonroot --from=build-distroless /app /app
|
||||||
COPY --chown=nonroot:nonroot --from=build-hapi /tmp/hapi-fhir-jpaserver-starter/opentelemetry-javaagent.jar /app
|
COPY --chown=nonroot:nonroot --from=build-hapi /tmp/hapi-fhir-jpaserver-starter/opentelemetry-javaagent.jar /app
|
||||||
|
|
||||||
CMD ["/app/main.war"]
|
ENTRYPOINT ["java", "--class-path", "/app/main.war", "-Dloader.path=main.war!/WEB-INF/classes/,main.war!/WEB-INF/,/app/extra-classes", "org.springframework.boot.loader.PropertiesLauncher", "app/main.war"]
|
||||||
|
|||||||
82
README.md
82
README.md
@@ -75,6 +75,7 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
|
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: postgres
|
image: postgres
|
||||||
restart: always
|
restart: always
|
||||||
@@ -105,6 +106,87 @@ spring:
|
|||||||
hibernate.search.enabled: false
|
hibernate.search.enabled: false
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Example running custom interceptor using docker-compose
|
||||||
|
|
||||||
|
This example is an extension of the above one, now adding a custom interceptor.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3.7'
|
||||||
|
|
||||||
|
services:
|
||||||
|
fhir:
|
||||||
|
container_name: fhir
|
||||||
|
image: "hapiproject/hapi:latest"
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
configs:
|
||||||
|
- source: hapi
|
||||||
|
target: /app/config/application.yaml
|
||||||
|
- source: hapi-extra-classes
|
||||||
|
target: /app/extra-classes
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: admin
|
||||||
|
POSTGRES_USER: admin
|
||||||
|
POSTGRES_DB: hapi
|
||||||
|
volumes:
|
||||||
|
- ./hapi.postgress.data:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
configs:
|
||||||
|
hapi:
|
||||||
|
file: ./hapi.application.yaml
|
||||||
|
hapi-extra-classes:
|
||||||
|
file: ./hapi-extra-classes
|
||||||
|
```
|
||||||
|
|
||||||
|
Provide the following content in ``./hapi.aplication.yaml``:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
url: 'jdbc:postgresql://db:5432/hapi'
|
||||||
|
username: admin
|
||||||
|
password: admin
|
||||||
|
driverClassName: org.postgresql.Driver
|
||||||
|
jpa:
|
||||||
|
properties:
|
||||||
|
hibernate.dialect: ca.uhn.fhir.jpa.model.dialect.HapiFhirPostgres94Dialect
|
||||||
|
hibernate.search.enabled: false
|
||||||
|
hapi:
|
||||||
|
fhir:
|
||||||
|
custom-bean-packages: the.package.containing.your.interceptor
|
||||||
|
custom-interceptor-classes: the.package.containing.your.interceptor.YourInterceptor
|
||||||
|
```
|
||||||
|
|
||||||
|
The basic interceptor structure would be like this:
|
||||||
|
|
||||||
|
```java
|
||||||
|
package the.package.containing.your.interceptor;
|
||||||
|
|
||||||
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.interceptor.api.Hook;
|
||||||
|
import ca.uhn.fhir.interceptor.api.Interceptor;
|
||||||
|
import ca.uhn.fhir.interceptor.api.Pointcut;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Interceptor
|
||||||
|
public class YourInterceptor
|
||||||
|
{
|
||||||
|
@Hook(Pointcut.STORAGE_PRECOMMIT_RESOURCE_CREATED)
|
||||||
|
public void resourceCreated(IBaseResource newResource)
|
||||||
|
{
|
||||||
|
System.out.println("YourInterceptor.resourceCreated");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Running locally
|
## Running locally
|
||||||
|
|
||||||
The easiest way to run this server entirely depends on your environment requirements. At least, the following 4 ways are supported:
|
The easiest way to run this server entirely depends on your environment requirements. At least, the following 4 ways are supported:
|
||||||
|
|||||||
Reference in New Issue
Block a user