mirror of
https://github.com/bec-project/bec_atlas.git
synced 2025-07-13 22:51:49 +02:00
ci: moved checks to separate file
This commit is contained in:
@ -15,13 +15,15 @@ services:
|
||||
before_script:
|
||||
# Check if ScyllaDB is ready (retry until successful)
|
||||
- pip install ./backend
|
||||
- |
|
||||
echo "Waiting for ScyllaDB to be ready..."
|
||||
until python -c "from cassandra.cluster import Cluster; cluster = Cluster(['scylla']); session = cluster.connect(); session.set_keyspace('test_bec_atlas');" 2>/dev/null; do
|
||||
echo "ScyllaDB is not ready yet, retrying in 5 seconds..."
|
||||
sleep 5
|
||||
done
|
||||
echo "ScyllaDB is up and running."
|
||||
# - |
|
||||
# echo "Waiting for ScyllaDB to be ready..."
|
||||
# until python -c "from cassandra.cluster import Cluster; cluster = Cluster(['scylla']); session = cluster.connect(); session.set_keyspace('test_bec_atlas');" 2>/dev/null; do
|
||||
# echo "ScyllaDB is not ready yet, retrying in 5 seconds..."
|
||||
# sleep 5
|
||||
# done
|
||||
# echo "ScyllaDB is up and running."
|
||||
- python ./backend/ci/healthchecks.py
|
||||
|
||||
|
||||
test:
|
||||
stage: test
|
||||
|
43
backend/ci/healthchecks.py
Normal file
43
backend/ci/healthchecks.py
Normal file
@ -0,0 +1,43 @@
|
||||
import sys
|
||||
import time
|
||||
|
||||
from cassandra.cluster import Cluster
|
||||
|
||||
SCYLLA_HOST = "scylla"
|
||||
SCYLLA_KEYSPACE = "test_bec_atlas"
|
||||
|
||||
|
||||
def wait_for_scylladb():
|
||||
print("Waiting for ScyllaDB to be ready...")
|
||||
while True:
|
||||
try:
|
||||
cluster = Cluster([SCYLLA_HOST])
|
||||
session = cluster.connect()
|
||||
session.set_keyspace(SCYLLA_KEYSPACE)
|
||||
print("Connected to ScyllaDB")
|
||||
break
|
||||
except Exception as e:
|
||||
print(f"ScyllaDB not ready yet: {e}")
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
def create_keyspace():
|
||||
print(f"Creating keyspace '{SCYLLA_KEYSPACE}' if not exists...")
|
||||
try:
|
||||
cluster = Cluster([SCYLLA_HOST])
|
||||
session = cluster.connect()
|
||||
session.execute(
|
||||
f"""
|
||||
CREATE KEYSPACE IF NOT EXISTS {SCYLLA_KEYSPACE}
|
||||
WITH replication = {{'class': 'SimpleStrategy', 'replication_factor': 1}}
|
||||
"""
|
||||
)
|
||||
print(f"Keyspace '{SCYLLA_KEYSPACE}' created successfully.")
|
||||
except Exception as e:
|
||||
print(f"Failed to create keyspace: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
wait_for_scylladb()
|
||||
create_keyspace()
|
Reference in New Issue
Block a user