Here's the docker-compose.yml file:
version: "3"
services:
db_cassandra:
container_name: db_cassandra
image: cassandra:latest
volumes:
- "./common/cassandra:/lua/cassandra_setup:rw"
environment:
WORKSPACE: "/tmp"
SERVICES_ROOT_DIR: "/services_root"
healthcheck:
test: ["CMD", "cqlsh", "-u", "cassandra", "-p", "cassandra" ]
interval: 5s
timeout: 5s
retries: 60
ports:
- "9042:9042"
remote_cassandra:
container_name: remote_cassandra
build:
context: ../.
dockerfile: ./it/remote_cassandra/Dockerfile
args:
BASE_IMAGE: cassandra:latest
depends_on:
dd_cassandra:
condition: service_healthy
volumes:
- "./common/cassandra:/lua/cassandra_setup:rw"
environment:
WORKSPACE: "/tmp"
SERVICES_ROOT_DIR: "/services_root"
Here's the remote_cassandra/Dockerfile:
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
COPY ./it/common/cassandra/cassandra-setup.sh /
RUN chmod +x /cassandra-setup.sh
CMD ["/cassandra-setup.sh", "db_cassandra"]
remote_cassandra remotely connects to the db_cassandra service and executes certain queries.
Here's how the cassandra-setup.sh script looks like:
#!/bin/bash
#code that creates schema.cql
.
.
.
DB_CONTAINER="$1"
while ! cqlsh $DB_CONTAINER 9042 -e 'describe cluster' ; do
echo "waiting for db_cassandra to be up..."
sleep .5
done
cqlsh $DB_CONTAINER 9042 -f "${WORKSPACE}/schema.cql"
When I pass the "dd_cassandra" as an argument to ENTRYPOINT, the docker containers are created and nothing happens after that, they keep waiting indefinitely.
However, if I don't pass the argument and simply hardcode it in the cassandra-setup.sh script like this below, then things run smoothly:
#!/bin/bash
#code that creates schema.cql
.
.
.
while ! cqlsh db_cassandra 9042 -e 'describe cluster' ; do
echo "waiting for db_cassandra to be up..."
sleep .5
done
cqlsh db_cassandra 9042 -f "${WORKSPACE}/schema.cql"
I've also tried with:
ENTRYPOINT ["/cassandra-setup.sh"]
CMD ["db_cassandra"]
and it doesn't work too.