p2-inc / keycloak-orgs

Single realm, multi-tenancy for SaaS apps
https://phasetwo.io
Other
389 stars 66 forks source link

Extension deleted after restarting keycloak and postgres container #15

Closed ahamroun10 closed 1 year ago

ahamroun10 commented 1 year ago

I'm using keycloak 19.1 and postgres 13.5 in docker containers, after copying the .jar client admin and keycloak-orgs in /opt/providers and launch the kc.sh build command after restarting the docker-compose (keycloak and postgres) the extension is removed

xgp commented 1 year ago

This is not a bug of the extension, but of your Docker setup. You need to build an image that incorporates the extension, and then use that in your docker-compose. E.g.

Dockerfile example:

FROM quay.io/keycloak/keycloak:19.0.2 as builder

ENV KC_METRICS_ENABLED=true
ENV KC_HEALTH_ENABLED=true
ENV KC_FEATURES=preview
ENV KC_DB=postgres
ENV KC_HTTP_RELATIVE_PATH=/auth
ENV KC_CACHE_CONFIG_FILE=cache-ispn-jdbc-ping.xml

# copy extension -- make sure this is where your jar file is
COPY ./keycloak-orgs.jar /opt/keycloak/providers/

RUN /opt/keycloak/bin/kc.sh build

FROM quay.io/keycloak/keycloak:19.0.2

COPY --from=builder /opt/keycloak/lib/quarkus/ /opt/keycloak/lib/quarkus/
COPY --from=builder /opt/keycloak/providers/ /opt/keycloak/providers/

WORKDIR /opt/keycloak
# this cert shouldn't be used, as it's just to stop the startup from complaining
RUN keytool -genkeypair -storepass password -storetype PKCS12 -keyalg RSA -keysize 2048 -dname "CN=server" -alias server -ext "SAN:c=DNS:localhost,IP:127.0.0.1" -keystore conf/server.keystore

ENTRYPOINT ["/opt/keycloak/bin/kc.sh", "-v", "start", "--optimized" ]

Then build your new image with:

docker build -t my-keycloak:latest -f ./Dockerfile .

And then reference your new image in your docker-compose file like this:

  keycloak:
    image: my-keycloak:latest