testcontainers / testcontainers-node

Testcontainers is a NodeJS library that supports tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
https://testcontainers.com
MIT License
1.91k stars 190 forks source link

Update redis module so that it can work with redis-stack similar to testcontainers-go #827

Open kevbook opened 2 months ago

kevbook commented 2 months ago

Expected Behaviour

const container = new RedisContainer('redis/redis-stack-server:7.2.0-v12')

This will fail because of the redis-server command. https://github.com/testcontainers/testcontainers-node/blob/9f7fd4eff5e6f05440016010964a78aa80557cb1/packages/modules/redis/src/redis-container.ts#L36-L39

As you can see from the docker images, redis uses CMD [redis-server] but redis-stack-server uses a custom entrypoint script. So I'm happy to open a PR, basically based on image string passed, we'll need to change how container.start() is handled (It's messy but not sure how else to solve it when you have 2 Redis images now!)

kevbook commented 2 months ago

Just add this line. All tests should pass

/* Make sure the redis image is a not a `redis-stack` image as `redis-stack` images have a custom entrypoint, see https://hub.docker.com/r/redis/redis-stack-server */
    if (!this.imageName.image.includes("redis-stack")) {
      this.withCommand([
        "redis-server",
        ...(this.password ? [`--requirepass "${this.password}"`] : []),
        ...(this.persistenceVolume ? ["--save 1 1 ", "--appendonly yes"] : []),
      ]);
    }

With redis-stack this.withCommand will not be applicable as all custom args are passed via env vars.