Reputation: 829
I am using podman for starting a keycloak with a postgres in a pod. I am using GitLab for that. The postgres which is created does not have the role keyclock. I used the official Dockerfile from https://www.keycloak.org/server/containers with modifications as bellow:
ENV KC_FEATURES=token-exchange
ENV KC_DB=postgres
RUN /opt/keycloak/bin/kc.sh build
FROM quay.io/keycloak/keycloak:latest
COPY --from=builder /opt/keycloak/lib/quarkus/ /opt/keycloak/lib/quarkus/
WORKDIR /opt/keycloak
# for demonstration purposes only, please make sure to use proper certificates in production instead
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
ENV KEYCLOAK_ADMIN=admin
ENV KC_DB_URL=jdbc:postgresql://localhost/keycloak
# change these values to point to a running postgres instance
ENV KC_DB_USERNAME=${DB_USERNAME}
ENV KC_DB_PASSWORD=${DB_PASS}
ENV KEYCLOAK_ADMIN_PASSWORD=${KC_ADMIN_PASS}
ENV KC_HOSTNAME=https://localhost:8443
EXPOSE 8443
ENTRYPOINT ["/opt/keycloak/bin/kc.sh", "start"]
and the yml file is:
stages:
- build
build_pod:
tags:
- auth-runner
stage: build
script:
- podman pod rm -i -f user-authentification
- podman pod create --name user-authentification -p 9175:8443
only:
- main
build_db:
image: postgres:14
tags:
- auth-runner
stage: build
script:
- podman run -dt --name postgres --pod user-authentification -v ~/postgres-data:/var/lib/postgresql/data:z
-e POSTGRES_DB="$KEYCLOAK_DB_NAME" -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD="$KEYCLOAK_DB_PASS" postgres
only:
- main
build_keycloak:
tags:
- auth-runner
stage: build
script:
- podman build --build-arg DB_USERNAME=postgres --build-arg DB_PASS=$KEYCLOAK_DB_PASS --build-arg KC_ADMIN_PASS=$KEYCLOAK_ADMIN_PASS -t sdx-keycloak .
- podman run -dt --name sdx-keyclaok-container --pod user-authentification sdx-keycloak
only:
- main
postgres error:
2022-02-22 21:08:45.800 UTC [1] LOG: starting PostgreSQL 14.2 (Debian 14.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-02-22 21:08:45.801 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-02-22 21:08:45.801 UTC [1] LOG: listening on IPv6 address "::", port 5432
2022-02-22 21:08:45.803 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-02-22 21:08:45.808 UTC [26] LOG: database system was shut down at 2022-02-22 21:08:40 UTC
2022-02-22 21:08:45.815 UTC [1] LOG: database system is ready to accept connections
2022-02-22 21:08:54.605 UTC [33] FATAL: role "keycloak" does not exist
2022-02-22 21:08:57.867 UTC [34] FATAL: role "keycloak" does not exist
Keycloak error:
2022-02-23 08:03:49,005 INFO [org.keycloak.common.Profile] (main) Preview feature enabled: token_exchange
2022-02-23 08:03:49,025 INFO [org.keycloak.quarkus.runtime.hostname.DefaultHostnameProvider] (main) Hostname settings: FrontEnd: https://localhost:8443, Strict
HTTPS: true, Path: <request>, Strict BackChannel: false, Admin: <request>
2022-02-23 08:03:49,561 WARN [io.agroal.pool] (agroal-11) Datasource '<default>': FATAL: role "keycloak" does not exist
2022-02-23 08:03:49,562 WARN [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (JPA Startup Thread: keycloak-default) HHH000342: Could not obtain connection to query metadata: org.postgresql.util.PSQLException: FATAL: role "keycloak" does not exist
Upvotes: 1
Views: 3901
Reputation: 829
found the answer in https://github.com/docker-library/postgres/issues/453#issuecomment-393939412
needed to delete the volume.
Upvotes: 1