Skip to content

Instantly share code, notes, and snippets.

@sombriks
Created July 16, 2024 20:37
Show Gist options
  • Save sombriks/aa3b476b4c166d2fbb1027ca0679b27f to your computer and use it in GitHub Desktop.
Save sombriks/aa3b476b4c166d2fbb1027ca0679b27f to your computer and use it in GitHub Desktop.
cassandra and init script via init-image strategy
#!/usr/bin/env bash
export RESULT=-1
until [ $RESULT -eq 0 ]; do
sleep 3;
echo "attempt to create keyspace"
cqlsh cassandra-local \
-u cassandra \
-p cassandra \
-e "create keyspace if not exists my_keyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'};"
RESULT=$?
done
echo "keyspace created"
#
# start this compose if you plan to use the 'local' profile and test things in a
# running app without rely on AWS Keyspaces
#
---
services:
cassandra-local:
image: cassandra:3.11
ports:
- "9042:9042"
# https://dev.to/dripto/execute-startup-scripts-in-cassandra-docker-cp2
init-cassandra:
image: cassandra:3.11
depends_on: [cassandra-local]
restart: "no"
entrypoint: ["sh", "/cassandra-init.sh"]
volumes:
- ./cassandra-init.sh:/cassandra-init.sh
postgres-local:
image: postgres:16-alpine
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_DB: ${POSTGRES_DB:-myrealdb}
volumes:
- ../test/resources/initial.sql:/docker-entrypoint-initdb.d/init.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment