adorsys / keycloak-config-cli

Import YAML/JSON-formatted configuration files into Keycloak - Configuration as Code for Keycloak.
Apache License 2.0
778 stars 140 forks source link

Failed to bind properties under keycloak #825

Closed zyriuse75 closed 1 day ago

zyriuse75 commented 1 year ago

Current Behavior

hi everyone .

Currently i've an issue when i try to run keycloak-cli latest version when i run the command docker-compose -f keycloak-cli.yaml up

keycloak-config-cli

version: '3'
services:
  keycloak-config-cli:
    build: .
    image: quay.io/adorsys/keycloak-config-cli:latest
    environment:
      - keycloak.url=http://127.0.0.1:8080
      - keycloak.user=admin
      - keycloak.password=admin123
      - import.files.locations=./config/*
      - keycloak.ssl-verify=false

i get this output

Attaching to keycloak-keycloak-config-cli-1
keycloak-keycloak-config-cli-1  | 2022-12-20 09:36:53.152  INFO 1 --- [           main] d.a.k.config.KeycloakConfigApplication   : Starting KeycloakConfigApplication v5.5.0 using Java 17.0.5 on 840d9bbe0325 with PID 1 (/app/keycloak-config-cli.jar started by nobody in /)
keycloak-keycloak-config-cli-1  | 2022-12-20 09:36:53.153  INFO 1 --- [           main] d.a.k.config.KeycloakConfigApplication   : No active profile set, falling back to 1 default profile: "default"
keycloak-keycloak-config-cli-1  | 2022-12-20 09:36:53.696  INFO 1 --- [           main] d.a.k.config.KeycloakConfigApplication   : Started KeycloakConfigApplication in 1.112 seconds (JVM running for 1.424)
keycloak-keycloak-config-cli-1  | 2022-12-20 09:36:54.337  INFO 1 --- [           main] ConditionEvaluationReportLoggingListener : 
keycloak-keycloak-config-cli-1  | 
keycloak-keycloak-config-cli-1  | Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
keycloak-keycloak-config-cli-1  | 2022-12-20 09:36:54.354 ERROR 1 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
keycloak-keycloak-config-cli-1  | 
keycloak-keycloak-config-cli-1  | ***************************
keycloak-keycloak-config-cli-1  | APPLICATION FAILED TO START
keycloak-keycloak-config-cli-1  | ***************************
keycloak-keycloak-config-cli-1  | 
keycloak-keycloak-config-cli-1  | Description:
keycloak-keycloak-config-cli-1  | 
keycloak-keycloak-config-cli-1  | Binding to target org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'keycloak' to de.adorsys.keycloak.config.properties.KeycloakConfigProperties failed:
keycloak-keycloak-config-cli-1  | 
keycloak-keycloak-config-cli-1  |     Property: keycloak.url
keycloak-keycloak-config-cli-1  |     Value: "null"
keycloak-keycloak-config-cli-1  |     Reason: must not be null
keycloak-keycloak-config-cli-1  | 
keycloak-keycloak-config-cli-1  | 
keycloak-keycloak-config-cli-1  | Action:
keycloak-keycloak-config-cli-1  | 
keycloak-keycloak-config-cli-1  | Update your application's configuration
keycloak-keycloak-config-cli-1  | 
Gracefully stopping... (press Ctrl+C again to force)

the result of docker ps -a command as you can see keycloak is running

CONTAINER ID   IMAGE                                             COMMAND        CREATED              STATUS              PORTS                  NAMES
fb3e206492bf     quay.io/keycloak/keycloak:20.0.2   "/opt/keycloak/bin/k…"   About a minute ago   Up About a minute   0.0.0.0:8080->8080/tcp, 0.0.0.0:8787->8787/tcp, 8443/tcp   keycloak-keycloak-1
$ tree
.
├── config
│   └── 00_realm.json
├── keycloak-cli.log
├── keycloak-cli.yaml

I ve read your documentation or that one i check different configuration on internet despite that i still don't find where is my issue .

Expected Behavior

keycloak-cli running without displaying the error Failed to bind properties under 'keycloak'.

Steps To Reproduce

No response

Environment

Anything else?

No response

martinmeneval commented 1 year ago

Hey @zyriuse75 , I had the same issue, but could fix it by replacing the . with _ in the environment block:

environment:
      - keycloak_url=http://127.0.0.1:8080
      - keycloak_user=admin
      - keycloak_password=admin123
      - import_files_locations=./config/*
      - keycloak_ssl-verify=false

As per the documentation for the env variables. This would indicate, IIUC, a possible blunder in the docker-compose.yaml, as it also uses . instead of _. https://github.com/adorsys/keycloak-config-cli/blob/main/docker-compose.yml#L57-L63

AssahBismarkabah commented 2 days ago

hi @martinmeneval @zyriuse75

the project's documentation primarily focuses on using Docker run commands, notDocker Compose. Docker Compose has its own variable substitution mechanism that allows for dot notation in environment variables, which is why the project's docker-compose.yml file works differently for sure. When using Docker Compose, the environment variables with dot notation are not being correctly interpreted by the application inside the container. This is why you're seeing the error "Failed to bind properties under ``'keycloak'" and "keycloak.url Value: "null"".

To resolve this issue, you can modify your keycloak-cli.yaml file to use the correct environment variable format for Docker containers as stated by @martinmeneval

example

version: '3'
services:
  keycloak-config-cli:
    image: quay.io/adorsys/keycloak-config-cli:latest
    environment:
      - KEYCLOAK_URL=http://host.docker.internal:8080
      - KEYCLOAK_USER=admin
      - KEYCLOAK_PASSWORD=your-password
      - IMPORT_FILES_LOCATIONS=/config/*
      - KEYCLOAK_SSL_VERIFY=false
    volumes:
      - ./config:/config

thank you for pointing that out.

AssahBismarkabah commented 1 day ago

the ticket https://github.com/adorsys/keycloak-config-cli/issues/825 can be closed already @Motouom