Skip to main content

Docker Compose

The easiest way to run the ORT Server for testing is to use Docker Compose. For a proper deployment to Kubernetes, the project will later provide a Helm chart.

warning

Do not use the Docker Compose setup in production as it uses multiple insecure defaults, like providing Keycloak without TLS.

To use Docker Compose, you need to have Docker and Docker Compose installed. Also, you have to clone the ORT Server repository:

git clone https://github.com/eclipse-apoapsis/ort-server.git

Run with Published Images​

To start the ORT Server with the required third-party services, run:

docker compose up

This will use the ORT Server images published on GitHub. By default, the main tag is used. Those images are built from the main branch of the repository. To use a different tag, you can set the ORT_SERVER_IMAGE_TAG environment variable, for example:

ORT_SERVER_IMAGE_TAG=0.1.0-RC1 docker compose up

By default, the ORT Server API is exposed on port 8080. If this port is already in use, it can be changed using the ORT_SERVER_CORE_PORT environment variable:

ORT_SERVER_CORE_PORT=8090 docker compose up

When using a different port, please make sure that it is not used by another service.

Update the Images​

Docker Compose will not automatically update the images for a specific tag like main once they have been pulled. To update the images to the latest version, run:

docker compose pull

Run with Local Images​

First, ensure to have Docker BuildKit enabled by either using Docker version 23.0 or newer, running export DOCKER_BUILDKIT=1, or configuring /etc/docker/daemon.json with:

{
"features": {
"buildkit": true
}
}

Then you can build the images with the following command:

./gradlew buildAllImages

This will build the images with the latest tag. Then you can start Docker Compose using the local images by setting the image prefix to an empty string and the tag to latest:

ORT_SERVER_IMAGE_PREFIX= ORT_SERVER_IMAGE_TAG=latest docker compose up

Build specific images​

There are also Gradle tasks to only build specific images. For example, to build only the analyzer worker image, run:

./gradlew buildAnalyzerWorkerImage

To list all available tasks, run:

./gradlew tasks --group=docker

Access the Services​

The following services are exposed by Docker Compose:

ServiceURLCredentials
ORT Server APIhttp://localhost:8080/swagger-ui/index.htmlCredentials: Same as Keycloak
Client: ort-server
Client Secret: <none>
ORT Server UIhttp://localhost:8082Same as Keycloak
Keycloakhttp://localhost:8081Administrator: admin:admin
User: ort-admin:password
PostgreSQLhttp://localhost:5433postgres:postgres
RabbitMQhttp://localhost:15672admin:admin
Graphitehttp://localhost:8888root:root
Grafanahttp://localhost:3200admin:1234

Run Maintenance Tasks​

The ORT Server provides maintenance tasks, for example to synchronize users with Keycloak or to delete data that no ORT run refers to anymore. In Kubernetes, the Helm chart runs them on a schedule. In Docker Compose, the tasks service runs them on demand; docker compose up does not start it.

To run a task, set its name in the TASKS environment variable, for example:

TASKS=delete-orphaned-entities docker compose run --rm tasks

To run several tasks, separate their names with commas and no spaces, for example TASKS=delete-old-ort-runs,delete-orphaned-entities. The tasks service has no default task, so every run has to name the tasks to run.

The tasks sync-keycloak-users, delete-old-ort-runs, delete-orphaned-entities and delete-unused-projections work in Docker Compose. The tasks whose names start with kubernetes- require Kubernetes and fail in Docker Compose.

If a task fails, the other tasks of the run still run, and docker compose run ends with exit code 1. The last line of its output names each failed task and the reason.

When using local images, set the image prefix and tag in the same way as for docker compose up:

TASKS=sync-keycloak-users ORT_SERVER_IMAGE_PREFIX= ORT_SERVER_IMAGE_TAG=latest docker compose run --rm tasks
TASKS=delete-orphaned-entities ORT_SERVER_IMAGE_PREFIX= ORT_SERVER_IMAGE_TAG=latest docker compose run --rm tasks

Synchronize users with Keycloak​

To synchronize the users with Keycloak, run:

TASKS=sync-keycloak-users docker compose run --rm tasks

The user synchronization stops without changes if a single run would remove more users than its limit allows. The limit is the larger of two numbers, which can be set with environment variables:

Environment variableDefaultMeaning
USER_SYNC_MAX_DELETED_USERS5The number of users that a single run may remove in any case.
USER_SYNC_MAX_DELETED_SHARE0.1The share of all stored users that a single run may remove, as a number between 0 and 1. 0.1 means 10 %.

With the defaults and 30 stored users, a run may remove 5 users; with 200 stored users, it may remove 20. For details, see Safety checks.

To make a bigger cleanup, raise a limit for a single run. For example, to allow a run to remove up to 50 users:

TASKS=sync-keycloak-users docker compose run --rm -e USER_SYNC_MAX_DELETED_USERS=50 tasks

To allow a run to remove any number of users, set the share to 1, which means 100 %:

TASKS=sync-keycloak-users docker compose run --rm -e USER_SYNC_MAX_DELETED_SHARE=1 tasks

Development​

HTTP request collections​

When using IntelliJ IDEA Ultimate, you can use the integrated HTTP client to execute requests against the ORT Server. The requests can be found in scripts/requests.

Debugging​

To debug the ORT Server in IntelliJ, you can use a composition with only some selected services:

docker compose up rabbitmq keycloak

Please note that postgres does not have to be explicitly passed: since it is a dependency of Keycloak, it will be started automatically.

Then execute the ORT Server in IntelliJ with the run configuration "Run ORT Server".

Updating Keycloak configuration​

The Keycloak configuration is managed declaratively with keycloak-config-cli. A dedicated keycloak-config service applies the realm configuration from a minimal config file to the running Keycloak instance. This file contains the minimal configuration to apply the recommended configuration and can be used as a template to configure your own Keycloak instance.

To change the configuration, edit scripts/docker/keycloak/ort-server-realm.yaml and re-apply it:

docker compose up keycloak-config

The keycloak-config service is idempotent: it runs once, reconciles the ort-server realm with the config file, and then exits. Keycloak does not need to be restarted for the changes to take effect.

When adding new entities, it can be helpful to first configure them in the admin UI (http://localhost:8081/admin, username admin, password admin) and then copy the relevant, non-default parts into the config file. See the keycloak-config-cli documentation for the list of supported features and the file format.

Troubleshooting​

Flyway migration errors​

When starting the ORT Server, you can run into the following error:

Exception in thread "main" org.flywaydb.core.api.exception.FlywayValidateException: Validate failed: Migrations have failed validation

This usually happens when you previously started the ORT Server with a different version of the database schema than the one you are currently using. To solve this issue, you need to investigate which migrations failed and then manually fix the database schema. During testing, this is often not worth the effort, so you can also clean the database and start from scratch. One way to clean the database is to shut down Docker Compose and delete all volumes:

docker compose down -v

Major version upgrades of PostgreSQL​

PostgreSQL does not support reading the data directory of a previous major version. When upgrading the PostgreSQL version in the Docker Compose setup, the database data directory must be manually migrated by following these steps:

  1. Stop the Docker Compose setup:

    docker compose stop
  2. Start only the PostgreSQL service:

    docker compose up -d postgres

    The backups must be made with the old PostgreSQL version. If docker-compose.yml already refers to the new version, for example after pulling the latest changes, the PostgreSQL service fails to start. In that case, change the version in docker-compose.yml back to the old one and run the command again. Before the next step, check with docker compose ps postgres that the service is healthy.

  3. Make backups of the ORT Server and Keycloak databases:

    docker compose exec -T postgres pg_dump -Fc -U postgres -d ort_server -n public > keycloak.dump
    docker compose exec -T postgres pg_dump -Fc -U postgres -d ort_server -n ort_server --large-objects > ort-server.dump

    The -T option is required, because a terminal attached to the command can corrupt the binary backup files.

    The --large-objects option is required, because ORT Server stores files like reports, file archives, and file lists as large objects. Large objects do not belong to a schema, so pg_dump leaves them out when the backup is limited to a schema with -n.

  4. Stop Docker Compose and delete the database volume:

    docker compose down
    docker volume rm ort-server_db

    The name of the volume starts with the name of the Compose project, which is the name of the directory containing docker-compose.yml by default. Use docker volume ls to find it if it differs.

  5. Update the PostgreSQL version in docker-compose.yml.

  6. Start the PostgreSQL service again:

    docker compose up -d postgres
  7. Create the ort_server schema and the pgcrypto extension that the ORT Server database uses. The backups do not contain the extension, because they are limited to single schemas. It must exist before the import, and it is installed into the ort_server schema, so the schema must be created first.

    docker compose exec -T postgres psql -U postgres -d ort_server -c "CREATE SCHEMA ort_server" -c "CREATE EXTENSION pgcrypto SCHEMA ort_server"
  8. Import the database backups:

    cat keycloak.dump | docker compose exec -T postgres pg_restore -U postgres -d ort_server -n public
    cat ort-server.dump | docker compose exec -T postgres pg_restore -U postgres -d ort_server

    The ORT Server backup is imported without the -n option, because pg_restore would skip the large objects otherwise. It reports an error that the schema ort_server already exists, which can be ignored, because the schema was created in the previous step.

    To check that all large objects were imported, run the following command, which must print 0:

    docker compose exec -T postgres psql -U postgres -d ort_server -Atc "SELECT count(*) FROM ort_server.storage s WHERE NOT EXISTS (SELECT 1 FROM pg_largeobject_metadata m WHERE m.oid = s.data)"
  9. Start all services:

    docker compose up -d

Using Podman instead of Docker​

By default, the Compose setup uses a logging driver that is not supported by Podman. To disable central logging, set the LOG_DRIVER environment variable to none:

LOG_DRIVER=none podman compose up