Reputation: 43
I took the Kafka UI image (provectuslabs/kafka-ui:v0.7.1): https://hub.docker.com/layers/provectuslabs/kafka-ui/master/images/sha256-633606ca07677d1c4b9405c5df1b6f0087aa75b36528a17eed142d06f65d0881?context=explore
I want to execute script before starting Kafka UI.
I don't want to store secrets in docker compose files, so I use docker swarm secrets. They are stored in /run/secrets/... The secrets are stored in docker files, so I use the sh script to turn them into environment variables. Code link: https://github.com/swarm-pack/swarm-sync/blob/master/env_secrets_expand.sh
#!/bin/bash
env_secret_expand() {
var="$1"
eval val=\$$var
if secret_name=$(expr match "$val" "DOCKER-SECRET->\([^}]\+\)$"); then
secret="${ENV_SECRETS_DIR}/${secret_name}"
env_secret_debug "Secret file for $var: $secret"
if [ -f "$secret" ]; then
val=$(cat "${secret}")
export "$var"="$val"
env_secret_debug "Expanded variable: $var=$val"
else
env_secret_debug "Secret file does not exist! $secret"
fi
fi
}
env_secrets_expand() {
for env_var in $(printenv | cut -f1 -d"=")
do
env_secret_expand $env_var
done
}
env_secrets_expand
In order to be able to execute the bash script, I added the line to the docker file:
FROM provectuslabs/kafka-ui:v0.7.1
# Secret for swarm
USER root
COPY env_secrets_expand_ui.sh /env_secrets_expand_ui.sh
RUN chmod +x /env_secrets_expand_ui.sh
RUN apk add --no-cache bash
EXPOSE 8080
CMD /env_secrets_expand_ui.sh && java --add-opens java.rmi/javax.rmi.ssl=ALL-UNNAMED -jar kafka-ui-api.jar
In the logs I see that the bash script is running, but kafka-ui ignores these variables, instead using the templates that are specified in the docker compose:
SPRING_SECURITY_USER_NAME: DOCKER-SECRET->kafka_ui_user
SPRING_SECURITY_USER_PASSWORD: DOCKER-SECRET->kafka_ui_password
Link to previous question: How i can embed my script into the image kafka-ui
How can I set environment variables for kafka-ui from docker swarm?
Upvotes: 0
Views: 159