Skip to content

Commit

Permalink
Merge pull request - improve Cassandra init by using a dedicated buil…
Browse files Browse the repository at this point in the history
…d step

chore: improve Cassandra init by using a dedicated build step
  • Loading branch information
ranzyblessings authored Feb 21, 2025
2 parents 1580412 + 1ba7c90 commit c209f06
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ To run the project locally using Docker, follow these steps:
```
2. **Start Dependencies with Docker Compose:**
```bash
docker compose up -d
docker compose up --build -d
```

**Note:** This command will start the following services:
Expand Down
14 changes: 2 additions & 12 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ services:
timeout: 10s

cassandra-init:
image: 'python:3.9-slim-buster'
image: 'cassandra-init:latest'
build: ./config/cassandra-init-scripts
container_name: 'cassandra-init'
depends_on:
cassandra:
Expand All @@ -65,17 +66,6 @@ services:
- ./config/cassandra-init-scripts:/scripts
networks:
- dev-network
entrypoint:
- sh
- -c
- |
apt-get update && apt-get install -y netcat-openbsd;
pip install cassandra-driver;
while ! nc -zv cassandra 9042; do
echo "Waiting for Cassandra to be available...";
sleep 1;
done;
python3 /scripts/init_cassandra.py
restart: no

redis:
Expand Down
15 changes: 15 additions & 0 deletions config/cassandra-init-scripts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Use a minimal Python image
FROM python:3.9-slim-buster

# Install required packages
RUN apt-get update && apt-get install -y netcat-openbsd && \
pip install cassandra-driver

# Set working directory
WORKDIR /scripts

# Copy init script into container
COPY init_cassandra.py /scripts/init_cassandra.py

# Entrypoint command: wait for Cassandra to be ready, then execute the script
CMD sh -c "while ! nc -zv cassandra 9042; do echo 'Waiting for Cassandra...'; sleep 1; done; python3 /scripts/init_cassandra.py"

0 comments on commit c209f06

Please sign in to comment.