Ticket Title: Resolve jq Installation and Duplicate Client Creation in Keycloak Docker Configuration
Description:
When attempting to run the Keycloak initialization script (gendox-local-init.sh) multiple times, there are two primary issues that prevent successful execution:
jq Not Found During Execution:
In the Dockerfile, jq is installed in a separate build stage but is not available in the final Keycloak image, causing failures in the script (gendox-local-init.sh) at lines 61 and 110. Specifically, the command:
CLIENT_UUID=$($KCADM get clients -r "$REALM_NAME" -q clientId="$CLIENT_ID" --fields id --format json | jq -r '.[0].id')
results in an error due to the absence of jq, which is required to parse JSON output.
Duplicate Client Creation:
When jq is missing, the script fails to retrieve existing client IDs. As a result, the script attempts to recreate the client, leading to a unique constraint violation:
ERROR: duplicate key value violates unique constraint "uk_b71cjlbenv945rb6gcon438at"
This indicates the script is not identifying existing clients correctly, causing duplication issues in Keycloak.
Proposed Solution:
Ensure jq is Available in Final Image:
Modify the Dockerfile to install jq directly in the final Keycloak image stage, ensuring it is available at runtime.
Example:
FROM alpine:3.18
RUN apk add --no-cache jq
Update gendox-local-init.sh to Check for Existing Clients:
Add a condition before creating the client to verify if it already exists, avoiding redundant creation and potential errors.
Additional Notes:
Log output for troubleshooting:
CLIENT_UUID=$($KCADM get clients -r "$REALM_NAME" -q clientId="$CLIENT_ID" --fields id --format json | jq -r '.[0].id')
ERROR: duplicate key value violates unique constraint "uk_b71cjlbenv945rb6gcon438at"
Ticket Title: Resolve
jq
Installation and Duplicate Client Creation in Keycloak Docker ConfigurationDescription:
When attempting to run the Keycloak initialization script (
gendox-local-init.sh
) multiple times, there are two primary issues that prevent successful execution:jq
Not Found During Execution: In the Dockerfile,jq
is installed in a separate build stage but is not available in the final Keycloak image, causing failures in the script (gendox-local-init.sh
) at lines 61 and 110. Specifically, the command:results in an error due to the absence of
jq
, which is required to parse JSON output.Duplicate Client Creation: When
jq
is missing, the script fails to retrieve existing client IDs. As a result, the script attempts to recreate the client, leading to a unique constraint violation:This indicates the script is not identifying existing clients correctly, causing duplication issues in Keycloak.
Proposed Solution:
Ensure
jq
is Available in Final Image:jq
directly in the final Keycloak image stage, ensuring it is available at runtime.Update
gendox-local-init.sh
to Check for Existing Clients:Additional Notes:
Log output for troubleshooting: