我目前有一个docker合成文件,它建立了一个psql数据库,并运行了大约80个sql文件来为我的应用程序创建关系。我现在想做的是添加一个keycloak层到应用程序。我也试图通过合成文件来做这件事,但我一直得到一个错误,说我的一个关系已经存在。我认为发生的是,当我keycloak服务正在运行它试图覆盖数据库,我不希望发生这种情况。我不知道如何解决这个问题,我已经尝试了一堆其他方法找到网上,但没有一个工作。
下面是我的合成文件(删除一些sql脚本以使其更简单):
---
version: "3.8"
services:
database:
container_name: database
environment:
# add multiple schemas
# POSTGRES_MULTIPLE_DATABASES: ${POSTGRESQL_DATABASE},${POSTGRESQL_KEYCLOAK_DATABASE}
POSTGRES_USER: ${POSTGRESQL_USER}
POSTGRES_PASSWORD: ${POSTGRESQL_PASSWORD}
POSTGRES_DB: ${POSTGRESQL_DATABASE}
# POSTGRES_KEYCLOAK_USER: ${POSTGRESQL_KEYCLOAK_USER}
# POSTGRES_KEYCLOAK_PASSWORD: ${POSTGRESQL_KEYCLOAK_PASSWORD}
# POSTGRES_DB2: ${POSTGRESQL_KEYCLOAK_DATABASE}
hostname: local
image: postgres:12
restart: always
volumes:
- /pgdata
- ./sql/access_attempt.sql:/docker-entrypoint-initdb.d/A.sql
- ./sql/bceid.sql:/docker-entrypoint-initdb.d/B.sql
- ./sql/lookup_activitytype.sql:/docker-entrypoint-initdb.d/C.sql
- ./sql/lookup_gender_pronoun.sql:/docker-entrypoint-initdb.d/D.sql
- ./sql/client.sql:/docker-entrypoint-initdb.d/E.sql
ports:
- "5432:5432"
networks:
- db-keycloak
backend:
container_name: backend
entrypoint:
- "sh"
- "-c"
- "npm i && npm run start"
environment:
NODE_ENV: development
POSTGRESQL_HOST: ${POSTGRESQL_HOST}
POSTGRESQL_USER: ${POSTGRESQL_USER}
POSTGRESQL_PASSWORD: ${POSTGRESQL_PASSWORD}
POSTGRESQL_DATABASE: ${POSTGRESQL_DATABASE}
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 40s
hostname: backend
image: node:14
links:
- database
ports:
- "3001:3000"
volumes:
- ./backend:/app:z
- /app/node_modules
working_dir: "/app"
keycloak:
image: jboss/keycloak:13.0.1
container_name: keycloak-service
environment:
DB_VENDOR: POSTGRES
DB_ADDR: database
DB_SCHEMA: public
DB_DATABASE: ${POSTGRESQL_DATABASE}
DB_USER: ${POSTGRESQL_USER}
DB_PASSWORD: ${POSTGRESQL_PASSWORD}
KEYCLOAK_USER: ${POSTGRESQL_KEYCLOAK_USER}
KEYCLOAK_PASSWORD: ${POSTGRESQL_KEYCLOAK_PASSWORD}
ports:
- "28080:8080"
depends_on:
- database
restart: always
links:
- database
networks:
- db-keycloak
frontend:
container_name: frontend
entrypoint:
- "sh"
- "-c"
- "npm i && npm run start"
environment:
NODE_ENV: development
BACKEND_URL: backend
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 40s
hostname: frontend
image: node:14
links:
- backend
ports:
- "3000:3000"
volumes:
- ./frontend:/app:z
- /app/node_modules
working_dir: "/app"
networks:
db-keycloak:
错误如下:
18:05:57,142 ERROR [org.keycloak.connections.jpa.updater.liquibase.conn.DefaultLiquibaseConnectionProvider] (ServerService Thread Pool -- 69) Change Set META-INF/jpa-changelog-1.0.0.Final.xml::1.0.0.Final-KEYCLOAK-5461::sthorger@redhat.com failed. Error: ERROR: relation "client" already exists [Failed SQL: CREATE TABLE public.CLIENT (DTYPE VARCHAR(31) NOT NULL, ID VARCHAR(36) NOT NULL, ALLOWED_CLAIMS_MASK BIGINT, ENABLED BOOLEAN DEFAULT FALSE NOT NULL, FULL_SCOPE_ALLOWED BOOLEAN DEFAULT FALSE NOT NULL, NAME VARCHAR(255), NOT_BEFORE INT, PUBLIC_CLIENT BOOLEAN DEFAULT FALSE NOT NULL, SECRET VARCHAR(255), BASE_URL VARCHAR(255), BEARER_ONLY BOOLEAN DEFAULT FALSE NOT NULL, MANAGEMENT_URL VARCHAR(255), SURROGATE_AUTH_REQUIRED BOOLEAN DEFAULT FALSE NOT NULL, DIRECT_GRANTS_ONLY BOOLEAN DEFAULT FALSE NOT NULL, REALM_ID VARCHAR(36))]
18:05:57,142 ERROR
[org.keycloak.connections.jpa.updater.liquibase.LiquibaseJpaUpdaterProvider] (ServerService Thread Pool -- 69) Error has occurred while updating the database: liquibase.exception.MigrationFailedException: Migration failed for change set META-INF/jpa-changelog-1.0.0.Final.xml::1.0.0.Final-KEYCLOAK-5461::sthorger@redhat.com:
Reason: liquibase.exception.DatabaseException: ERROR: relation "client" already exists [Failed SQL: CREATE TABLE public.CLIENT (DTYPE VARCHAR(31) NOT NULL, ID VARCHAR(36) NOT NULL, ALLOWED_CLAIMS_MASK BIGINT, ENABLED BOOLEAN DEFAULT FALSE NOT NULL, FULL_SCOPE_ALLOWED BOOLEAN DEFAULT FALSE NOT NULL, NAME VARCHAR(255), NOT_BEFORE INT, PUBLIC_CLIENT BOOLEAN DEFAULT FALSE NOT NULL, SECRET VARCHAR(255), BASE_URL VARCHAR(255), BEARER_ONLY BOOLEAN DEFAULT FALSE NOT NULL, MANAGEMENT_URL VARCHAR(255), SURROGATE_AUTH_REQUIRED BOOLEAN DEFAULT FALSE NOT NULL, DIRECT_GRANTS_ONLY BOOLEAN DEFAULT FALSE NOT NULL, REALM_ID VARCHAR(36))]
1条答案
按热度按时间tjrkku2a1#
根据错误,您现有的postgres数据库已经有名为
client
的表/关系。但Keycloak正在尝试创建自己的client
表,这导致了此错误。为了解决这个问题,我建议使用两个不同的postgres
databases/schemas
,一个用于您的应用程序,另一个用于keycloak示例。