Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bitnami/kafka] Docker environment variable for topic creation #77410

Open
cardosomartins opened this issue Feb 12, 2025 · 1 comment
Open

[bitnami/kafka] Docker environment variable for topic creation #77410

cardosomartins opened this issue Feb 12, 2025 · 1 comment
Assignees
Labels

Comments

@cardosomartins
Copy link

cardosomartins commented Feb 12, 2025

Name and Version

[bitnami/kafka] - docker env variable for topic creation

What is the problem this feature will solve?

Name and Version
bitnami/kafka

I am dealing with a project in which I need my containers to run only after the Kafka container is up and has a topic running in it.
I cannot create a topic using RUN, CMD or ENTRYPOINT commands in Docker.

What is the feature you are proposing to solve the problem?

The feature would be a docker variable to start a topic automatically and the posisbility of checking whether it's running with a health check.

What alternatives have you considered?

Currently I have another container init_kafka in which I ping to the original kafka container and then I create a topic in it.
Then, my topic dependent containers have a depends_only condition that depend on the init_kafka

### Examples in other docker images
A good example of such a feature that was implemented elsewhere is in wurstmeister image. They have a variable called "KAFKA_CREATE_TOPICS". Something along those lines would work just fine.

@github-actions github-actions bot added the triage Triage is needed label Feb 12, 2025
@carrodher carrodher transferred this issue from bitnami/charts Feb 12, 2025
@carrodher carrodher removed their assignment Feb 13, 2025
@javsalgar javsalgar changed the title Docker environment variable for topic creation [bitnami/kafka] Docker environment variable for topic creation Feb 13, 2025
@javsalgar
Copy link
Contributor

Hi!

The kafka container has an option to run custom init scripts mounted at /docker-entrypoint-initdb.d

kafka_custom_init_scripts() {
    if [[ -n $(find "${KAFKA_INITSCRIPTS_DIR}/" -type f -regex ".*\.\(sh\)") ]] && [[ ! -f "${KAFKA_VOLUME_DIR}/.user_scripts_initialized" ]]; then
        info "Loading user's custom files from $KAFKA_INITSCRIPTS_DIR"
        for f in /docker-entrypoint-initdb.d/*; do
            debug "Executing $f"
            case "$f" in
            *.sh)
                if [[ -x "$f" ]]; then
                    if ! "$f"; then
                        error "Failed executing $f"
                        return 1
                    fi
                else
                    warn "Sourcing $f as it is not executable by the current user, any error may cause initialization to fail"
                    . "$f"
                fi
                ;;
            *)
                warn "Skipping $f, supported formats are: .sh"
                ;;
            esac
        done
        touch "$KAFKA_VOLUME_DIR"/.user_scripts_initialized
    fi
}

You could try mounting a script that creates a topic. Would that work for your use case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants