docker-library / cassandra

Docker Official Image packaging for Cassandra
Apache License 2.0
262 stars 282 forks source link

Add ability to extend CASSANDRA_xxx style env configs #247

Closed clintwood closed 2 years ago

clintwood commented 2 years ago

This PR adds the ability to extend the limited set of CASSANDRA_xxx style env vars that update the cassandra.yaml via docker_entrypoint.sh

This is done by setting an env variable EXTEND_CONFIG with a space separated list of config keys that the docker_entrypoint.sh will add to it's limited list of keys to replace in cassandra.yaml.

One could add this to a docker-compose.yml e.g.:

    environment:
      # Extend the config to additionally use/recognise keys:
      #  enable_materialized_views
      #  enable_sasi_indexes
      #  enable_user_defined_functions
      - EXTEND_CONFIG=enable_materialized_views enable_sasi_indexes enable_user_defined_functions
      - CASSANDRA_CLUSTER_NAME=my-cluster
      # More known CASSANDRA_xxx config 
      - CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch
      # Extended CASSANDRA_xxx configs
      - CASSANDRA_ENABLE_MATERIALIZED_VIEWS=true
      - CASSANDRA_ENABLE_SASI_INDEXES=true
      - CASSANDRA_ENABLE_USER_DEFINED_FUNCTIONS=true
    networks:
    ...

The above would recognize the last 3 env variables and set these appropriately in the cassandra.yaml config file.

yosifkit commented 2 years ago

Stance is unchanged from https://github.com/docker-library/cassandra/pull/122#issuecomment-426774071:

I'm sorry, but honestly if we're going to do anything more with environment variables it would likely be in the opposite direction (which we won't do due to the backwards compatibility implications) -- modifying a YAML file via shell script is very fragile, and setting complex configuration in this way is not great. For custom configuration, the only/best recommendation is to provide an appropriate cassandra.yaml file to your running instance (via a new image with FROM / COPY in a short Dockerfile, via Docker Configs, via bind mount, [kubernetes ConfigMap,] etc).

clintwood commented 2 years ago

@yosifkit I totally agree, however, it appears this repo is what is used to build cassandra images for docker hub which leaves us with no way to extend it. I guess I could add a volume in my compose file to point to an external directory with a cassandra.yaml file and use -Dcassandra.config=/path/to/cassandra.yaml but this is all over the place.

I've copied the Dockerfile and docker-entrypoint.sh to my local project but that's also not ideal.

Please feel free to close this PR.

tianon commented 2 years ago

You should be able to just overwrite the docker-entrypoint.sh script within the published images to get yourself custom behavior:

FROM cassandra:x.y
COPY docker-entrypoint.sh /usr/local/bin/
clintwood commented 2 years ago

@tianon awesome yes - that will be a solution that will keep me up to date with fixes/releases as they happen - thank you