在 Github 操作和查询中设置 Cassandra 容器

Setup Cassandra container in Github Actions and query

我有这个 .yml 文件:

name: CasDB

on: push

env:
  CARGO_TERM_COLOR: always


jobs:
  test:
    runs-on: ubuntu-latest
    services:
      cassandra:
        image: cassandra
        ports:
          - 9042:9042
        options: --health-cmd "cqlsh --debug" --health-interval 5s --health-retries 10
    steps:
      - run: docker ps
      - run: docker exec ${{ job.services.cassandra.id }} cqlsh --debug localhost:9042 --execute="use somekeyspace;"

我想在 Github 操作中启动 Cassandra 数据库,然后执行一些查询。 Cassandra 数据库是 运行,但是当我想执行查询(“使用一些键空间”)时,它失败并显示以下错误消息:

Using CQL driver: <module ‘cassandra’ from ‘/opt/cassandra/bin/…/lib/cassandra-driver-internal-only-3.11.0-bb96859b.zip/cassandra-driver-3.11.0-bb96859b/cassandra/init.py’> Using connect timeout: 5 seconds Using ‘utf-8’ encoding Using ssl: False Traceback (most recent call last): File “/opt/cassandra/bin/cqlsh.py”, line 2459, in main(*read_options(sys.argv[1:], os.environ)) File “/opt/cassandra/bin/cqlsh.py”, line 2437, in main encoding=options.encoding) File “/opt/cassandra/bin/cqlsh.py”, line 485, in init load_balancing_policy=WhiteListRoundRobinPolicy([self.hostname]), File “/opt/cassandra/bin/…/lib/cassandra-driver-internal-only-3.11.0-bb96859b.zip/cassandra-driver-3.11.0-bb96859b/cassandra/policies.py”, line 417, in init socket.gaierror: [Errno -2] Name or service not known ##[error]Process completed with exit code 1.

我需要将 .yml 中的哪些内容更改为:

  1. 执行一个.sql脚本(多个数据库脚本)
  2. 执行单个 cqlsh 语句

谢谢

你只是 运行 cqlsh 参数错误:你不能给它 localhost:9042 作为主机名。主机名和端口是单独的参数。尝试:

cqlsh localhost 9042

而不是 cqlsh localhost:9042