/keycloak-buildpack

Scalingo buildpack to install Keycloak with PostgreSQL database

Primary LanguageShellMIT LicenseMIT

Scalingo Keycloak buildpack

This buildpack aims at installing a Keycloak instance on Scalingo and let you configure it at your convenance.

Deploy to Scalingo

Usage

Add this buildpack environment variable to your Scalingo application to install the Keycloak server:

BUILDPACK_URL=https://github.com/MTES-MCT/keycloak-buildpack

Default version is 11.0.2, but you can choose another one:

scalingo env-set KEYCLOAK_VERSION=10.0.2

See Keycloak docs to use keycloak image server.

Configuration

You must have an add-on database postgresql.

Environment variables are set in a .env file. You copy the sample one:

cp .env.sample .env

Add a user admin

In .env set these vars:

KEYCLOAK_ADMIN_USERNAME=your-admin-name
KEYCLOAK_ADMIN_PASSWORD=your-admin-password

then build again.

Export or import data

/app/keycloak/bin/standalone.sh \
-Djboss.socket.binding.port-offset=100 -Dkeycloak.migration.action=export \
-Dkeycloak.migration.provider=singleFile \
-Dkeycloak.migration.realmName=my_realm \
-Dkeycloak.migration.usersExportStrategy=REALM_FILE \
-Dkeycloak.migration.file=/tmp/my_realm.json

Don't forget the -Djboss.socket.binding.port-offset=100 change ports to not stop server running.

You can do the same with import. See Export/import docs

With scalingo CLI you can download or upload these files.

Hacking

Run an interactive docker scalingo stack:

 docker run --name keycloak -it -p 8080:8080 -v "$(pwd)"/.env:/env/.env -v "$(pwd)":/buildpack scalingo/scalingo-18:latest bash

And test in it:

bash buildpack/bin/detect
bash buildpack/bin/env.sh /env/.env /env
bash buildpack/bin/compile /build /cache /env
bash buildpack/bin/release

Run Keycloak server:

export PATH=$PATH:/app/java/bin
./bin/run -b 0.0.0.0

You can also use docker-compose stack:

docker-compose up --build -d