Skip to content

Installation Guide

Md Nazrul Islam edited this page Nov 24, 2026 · 5 revisions

Installation Guide

This page explains how to install and run the FHIR Validation Service (current release: 1.0.0). It matches the README. For the API itself, see API Documentation.

Requirements

  • One of:
    • Docker with Compose v2 (published container image, option A), or
    • Java 17 or later and your own PostgreSQL (option C), or
    • Java 17 and Maven, to build and develop
  • PostgreSQL 16 (provided by the Compose setup)
  • Up to 4 GB of memory per instance (the default container limit; the JVM takes 75% as heap, so 3 GB):
    • Warmed core validators for all four FHIR versions take about 0.9 GB of heap. Serving fewer versions (FV_ENABLED_FHIR_VERSIONS=R4, for example) saves memory and startup time.
    • Every included IG has its own validator context (the IG plus its dependencies), and building one holds about 6 times its expanded size. 4 GB fits contexts up to about 350 MB expanded (roughly a 30 MB archive).
    • An include that would not fit is refused with 413 package-too-large and nothing is changed. Watch fv_snapshot_package_size_bytes and fv_validator_contexts. The full formula is under FV_MEMORY_LIMIT in the configuration reference.

Installation

There are three ways to run the service:

Option Use when You provide
A. Docker Compose, published image you want a running service without the source code Docker
B. Docker Compose, source checkout you want the cluster, observability and pgAdmin profiles, or to build the image yourself Docker, git
C. Jar with your own PostgreSQL you already run PostgreSQL, or deploy without containers (VM, systemd) Java 17+, PostgreSQL

Whichever you choose, you need two API keys, each 32-128 characters of [A-Za-z0-9_-]. Generate each with

openssl rand -hex 32
  • FV_ADMIN_API_KEY is the administrator key (system administrator, role ADMIN). Without it, every administrative call is refused: IG upload and registration, including or excluding an IG with /{version}/validator, and sharing and ownership changes.
  • FV_VALIDATOR_API_KEY is a shared validation key (trial validator, role VALIDATE) that can use shareable content only. Every validation needs a key, so set this one or create keys per client with fv-admin (see Organisations and API keys). Don't give the administrator key to validation clients.

To try the service without keys, see public mode on Home. It is not for production.

Option A: Docker Compose with the published image

Images are published to ghcr.io/nazrulworld/fhir-validation-service for linux/amd64 and linux/arm64:

Tag Meaning
1.0.0 an exact release (recommended for production: pin it)
1.0 the newest patch release of 1.0
latest the newest release
sha-<commit> a build of main at that commit (unreleased; for testing)

Pin FV_TAG to an exact release in production, so a pull never upgrades without you.

1. Create a directory and an .env file

mkdir fhir-validation && cd fhir-validation

cat > .env <<EOF
FV_TAG=1.0.0
PG_PASSWORD=$(openssl rand -hex 24)
FV_ADMIN_API_KEY=$(openssl rand -hex 32)
FV_VALIDATOR_API_KEY=$(openssl rand -hex 32)
# Optional: serve fewer FHIR versions to save memory and startup time
# FV_ENABLED_FHIR_VERSIONS=R4
EOF
chmod 600 .env

Any other setting from .env.example can be added to .env; the validator receives the whole file.

2. Create compose.yaml

name: fhir

services:
  postgres:
    image: postgres:16.8-alpine
    environment:
      POSTGRES_DB: fhir_validator
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: ${PG_PASSWORD:?set PG_PASSWORD in .env}
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres -d fhir_validator"]
      interval: 5s
      timeout: 3s
      retries: 20
    restart: unless-stopped

  validator:
    image: ghcr.io/nazrulworld/fhir-validation-service:${FV_TAG:-latest}
    env_file: .env
    environment:
      FV_PG_HOST: postgres
      FV_PG_PORT: "5432"
      FV_PG_DATABASE: fhir_validator
      FV_PG_USER: postgres
      FV_PG_PASSWORD: ${PG_PASSWORD:?set PG_PASSWORD in .env}
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - "127.0.0.1:8880:8880"      # local only; see "Exposing the service" below
    mem_limit: 4g                  # the JVM uses 75% as heap
    stop_grace_period: 30s
    restart: unless-stopped

volumes:
  pgdata:

The image has its own health check (/health/readiness, 120 s start period), so --wait below waits until the validators are warmed.

Alternatively, download compose.yaml and default.env.example (rename it to .env, then fill in the passwords and keys) from the latest release. Its default services (PostgreSQL and one validator) work without a source checkout. It also defines the cluster, observability and admin profiles, but those need the configuration files under docker/ from a source checkout (option B).

3. Start and check

docker compose pull
docker compose up -d --wait        # first start takes 1-2 minutes while the validators warm up
curl -fsS http://127.0.0.1:8880/health/readiness

Then validate a resource, as shown in API Documentation.

Exposing the service

The service speaks plain HTTP, and API keys travel in the Authorization header. Don't publish port 8880 on a public interface. Put a reverse proxy that terminates TLS in front of it instead, set FV_AUTH_TRUSTED_PROXIES to the proxy's address so client addresses are recorded correctly, and consider limiting administrative calls to your own networks with FV_AUTH_ADMIN_CIDRS.

Day-to-day

Task Command
Logs docker compose logs -f validator
Stop (keep data) docker compose down
Upgrade read the CHANGELOG first (database migrations run automatically on start and are not undone by a downgrade), back up, set the new FV_TAG in .env, then docker compose pull && docker compose up -d --wait
Back up docker compose exec -T postgres pg_dump -U postgres -Fc fhir_validator > fhir_validator.dump
Restore docker compose stop validator, then docker compose exec -T postgres pg_restore -U postgres -d fhir_validator --clean --if-exists < fhir_validator.dump, then docker compose start validator
Delete everything, data included docker compose down -v

Option B: Docker Compose from a source checkout

git clone https://github.com/nazrulworld/fhir-validation-service.git
cd fhir-validation-service
cp .env.example .env      # set PG_PASSWORD (= FV_PG_PASSWORD), FV_ADMIN_API_KEY and FV_VALIDATOR_API_KEY
make up                   # = docker compose up -d --wait : PostgreSQL + one validator on 127.0.0.1:8880
curl -fsS http://127.0.0.1:8880/health/readiness

make up uses the published image named by FV_TAG when it is available; docker compose build builds it from the checkout instead.

Command Starts Endpoint
make up PostgreSQL, one validator http://127.0.0.1:8880
make up-cluster + a second validator behind nginx (shared database) http://127.0.0.1:8881
make up-obs + Prometheus and a PostgreSQL exporter http://127.0.0.1:9090
make up-admin + pgAdmin (credentials from .env) http://127.0.0.1:5050
make rolling-restart restarts the cluster's validators one at a time under load
make down / make clean stop (keep / delete volumes)
make smoke build, start, validate, graceful stop

The cluster profile runs two validators, so the host needs room for two memory limits. All ports bind to 127.0.0.1. PostgreSQL is not published; to reach it from the host, add a git-ignored compose.override.yaml with services: {postgres: {ports: ["127.0.0.1:54329:5432"]}}.

Option C: Jar with your own PostgreSQL

The release jar is self-contained (all dependencies included). The service creates and migrates its own schema (fhir_validator_schema, with Flyway) on startup; you only provide an empty database and a user.

1. Install Java 17 or later

java -version             # must report 17 or later, e.g. Eclipse Temurin 17/21

2. Prepare PostgreSQL (16 recommended)

As a PostgreSQL superuser (for example sudo -u postgres psql):

CREATE ROLE fhir_validator LOGIN PASSWORD 'choose-a-strong-password';
CREATE DATABASE fhir_validator OWNER fhir_validator;

The user must be able to create a schema in the database (owning it, as above, is enough). If you prefer a user that does not own the database, create the schema for it instead:

\c fhir_validator
CREATE SCHEMA fhir_validator_schema AUTHORIZATION fhir_validator;

If PostgreSQL runs on another host, allow the connection in pg_hba.conf and set FV_PG_SSL_MODE to require or verify-full.

3. Download the jar

VERSION=1.0.0
curl -fLO "https://github.com/nazrulworld/fhir-validation-service/releases/download/v${VERSION}/fhir-validation-service-${VERSION}.jar"

(Or build it: ./mvnw -B package -DskipTests produces target/fhir-validation-service-<version>.jar.)

4. Configure and run

Settings are read from environment variables only (the service does not read .env files itself):

export FV_PG_HOST=localhost
export FV_PG_PORT=5432
export FV_PG_DATABASE=fhir_validator
export FV_PG_USER=fhir_validator
export FV_PG_PASSWORD='choose-a-strong-password'
export FV_ADMIN_API_KEY='<output of openssl rand -hex 32>'
export FV_VALIDATOR_API_KEY='<another output of openssl rand -hex 32>'
export FV_HTTP_PORT=8880

java -XX:+ExitOnOutOfMemoryError -Xms512m -Xmx3g -jar "fhir-validation-service-${VERSION}.jar"

-Xmx3g matches the 3 GB heap of the default 4 GB container. Size it with the formula under Requirements.

curl -fsS http://127.0.0.1:8880/health/readiness   # 200 once every FHIR version is warmed (1-2 minutes)

The jar listens on all interfaces at FV_HTTP_PORT and speaks plain HTTP. Put it behind a reverse proxy that terminates TLS, or a firewall, rather than exposing it directly (see Exposing the service).

5. Run it as a service (systemd example)

/etc/fhir-validator/env (mode 0600, owner root), one NAME=value per line, no export, and no spaces, quotes or $ in a value (the fv-admin wrapper in step 6 reads this file too):

FV_PG_HOST=localhost
FV_PG_DATABASE=fhir_validator
FV_PG_USER=fhir_validator
FV_PG_PASSWORD=choose-a-strong-password
FV_ADMIN_API_KEY=replace-with-the-generated-key
FV_VALIDATOR_API_KEY=replace-with-another-generated-key
FV_LOG_FORMAT=json

/etc/systemd/system/fhir-validator.service:

[Unit]
Description=FHIR Validation Service
After=network-online.target postgresql.service
Wants=network-online.target

[Service]
User=fhir
Group=fhir
EnvironmentFile=/etc/fhir-validator/env
ExecStart=/usr/bin/java -XX:+ExitOnOutOfMemoryError -Xmx3g -jar /opt/fhir-validator/fhir-validation-service.jar
# SIGTERM drains in-flight requests: FV_SHUTDOWN_PRE_DRAIN_MS (5 s) + FV_SHUTDOWN_GRACE_MS (20 s) by default.
# Keep this above their sum if you raise them.
TimeoutStopSec=30
Restart=on-failure
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target
sudo useradd --system --no-create-home --shell /usr/sbin/nologin fhir
sudo install -D -m 0444 "fhir-validation-service-${VERSION}.jar" /opt/fhir-validator/fhir-validation-service.jar
sudo systemctl daemon-reload && sudo systemctl enable --now fhir-validator
journalctl -u fhir-validator -f

6. Set up the fv-admin command line

The jar is also the administrative command line: when the first argument is a command group (org, key, package, snapshot, usage), it runs that one command and exits instead of starting the server. It connects straight to the database with the same FV_PG_* settings (no HTTP call, no API key, and the service does not need to be running) and applies pending migrations first.

A small wrapper gives the same fv-admin command the container image has, reading the service's environment file. /usr/local/bin/fv-admin:

#!/bin/sh
# fv-admin: the administrative command line, with the service's database settings.
set -a                        # export every variable the file defines
. /etc/fhir-validator/env
set +a
exec /usr/bin/java -Xmx512m -jar /opt/fhir-validator/fhir-validation-service.jar "$@"
sudo install -m 0750 -o root -g root fv-admin /usr/local/bin/fv-admin
  • The environment file is 0600 root, so run fv-admin with sudo. If your sudo secure_path does not include /usr/local/bin (RHEL and derivatives), call it as sudo /usr/local/bin/fv-admin.
  • -Xmx512m keeps it from competing with a running service on the same host.
  • It can run on any host that reaches the database (with the same FV_PG_SSL_MODE).

Running more instances and upgrading

To run more instances, start more processes (any host) against the same database, with the same configuration, and put a load balancer in front that health-checks /health/readiness.

To upgrade, read the CHANGELOG and back up the database first: migrations run on start and are not undone by a downgrade. Then replace the jar and restart the instances one at a time, waiting for /health/readiness to answer 200 before restarting the next.

Organisations and API keys

Every API key, IG package and included IG belongs to an organisation. The key from FV_ADMIN_API_KEY belongs to the built-in system organisation, and the key from FV_VALIDATOR_API_KEY to the built-in trial organisation. Give each client its own organisation and VALIDATE key:

APP="docker compose run --rm validator fv-admin"     # option C: APP="sudo fv-admin"
$APP org create --name-short acme --name-long "Acme Health ApS" --type COMMERCIAL --country DK
$APP key create --org acme --name acme-ci --role VALIDATE   # prints the key once; only its hash is stored
$APP key list --org acme                                    # never shows keys; shows expiresAt and lastUsedIp
$APP key revoke --name acme-ci

Commands print one JSON document on stdout (pipe it to jq) and write errors to stderr. The seeded keys are rotated by changing FV_ADMIN_API_KEY / FV_VALIDATOR_API_KEY on every instance and restarting. The full command reference is specs/005-organisation-ownership/contracts/cli.md; key rotation, revocation and sharing are explained in the README.

Next steps