diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 91058460fd..2994222f42 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -37,4 +37,37 @@ jobs: cache: true - name: Run tests - run: go test -v ./storage/crdb/... \ No newline at end of file + run: go test -v ./storage/crdb/... + + integration-crdb: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-go@v3 + with: + go-version: '1.19' + check-latest: true + cache: true + + - name: Run CockroachDB + run: docker run --rm -d --name=roach -p 8080:8080 -p 26257:26257 -v "${PWD}/cockroach-data:/cockroach/cockroach-data" cockroachdb/cockroach:latest start-single-node --insecure + + - name: Wait for CockroachDB + uses: nick-fields/retry@v2 + with: + timeout_seconds: 15 + max_attempts: 3 + retry_on: error + command: docker exec roach ./cockroach sql --insecure -e "SELECT 1" + + - name: Get crdb logs + run: docker logs roach + + - name: Run tests + run: ./integration/integration_test.sh + env: + TEST_COCKROACHDB_URI: postgresql://root@localhost:26257/defaultdb?sslmode=disable + CRDB_IN_CONTAINER: true + CRDB_CONTAINER_NAME: roach + LOGGING_OPTS: -alsologtostderr diff --git a/integration/functions.sh b/integration/functions.sh index bc66730081..a669d048e8 100755 --- a/integration/functions.sh +++ b/integration/functions.sh @@ -122,7 +122,11 @@ log_prep_test() { local log_signer_count=${2:-1} # Wipe the test database - yes | bash "${TRILLIAN_PATH}/scripts/resetdb.sh" + if [[ "${TEST_MYSQL_URI}" != "" ]]; then + yes | bash "${TRILLIAN_PATH}/scripts/resetdb.sh" + elif [[ "${TEST_COCKROACHDB_URI}" != "" ]]; then + yes | bash "${TRILLIAN_PATH}/scripts/resetcrdb.sh" + fi local logserver_opts='' local logsigner_opts='' @@ -131,6 +135,9 @@ log_prep_test() { if [[ "${TEST_MYSQL_URI}" != "" ]]; then logserver_opts+=" --mysql_uri=${TEST_MYSQL_URI}" logsigner_opts+=" --mysql_uri=${TEST_MYSQL_URI}" + elif [[ "${TEST_COCKROACHDB_URI}" != "" ]]; then + logserver_opts+="--storage_system=crdb --crdb_uri=${TEST_COCKROACHDB_URI}" + logsigner_opts+="--storage_system=crdb --crdb_uri=${TEST_COCKROACHDB_URI}" fi # Start a local etcd instance (if configured). diff --git a/scripts/resetcrdb.sh b/scripts/resetcrdb.sh index c21e6fe2b2..75a4931e73 100755 --- a/scripts/resetcrdb.sh +++ b/scripts/resetcrdb.sh @@ -19,6 +19,10 @@ Accepts environment variables: (default: zaphod). - CRDB_USER_HOST: The host that the Trillian user will connect from; use '%' as a wildcard (default: localhost). +- CRDB_IN_CONTAINER: If set, the script will assume it is running in a Docker + container and will exec into the container to operate. +- CRDB_CONTAINER_NAME: The name of the Docker container to exec into (default: + roach). EOF } @@ -37,6 +41,8 @@ collect_vars() { [ -z ${CRDB_PASSWORD+x} ] && CRDB_PASSWORD="zaphod" [ -z ${CRDB_USER_HOST+x} ] && CRDB_USER_HOST="localhost" [ -z ${CRDB_INSECURE+x} ] && CRDB_INSECURE="true" + [ -z ${CRDB_IN_CONTAINER+x} ] && CRDB_IN_CONTAINER="false" + [ -z ${CRDB_CONTAINER_NAME+x} ] && CRDB_CONTAINER_NAME="roach" FLAGS=() # handle flags @@ -68,6 +74,12 @@ collect_vars() { # append password if supplied [ -z ${CRDB_ROOT_PASSWORD+x} ] || FLAGS+=(-p"${CRDB_ROOT_PASSWORD}") + + if [[ ${CRDB_IN_CONTAINER} = 'true' ]]; then + CMD="docker exec ${CRDB_CONTAINER_NAME} cockroach" + else + CMD="cockroach" + fi } main() { @@ -84,20 +96,20 @@ main() { then echo "Resetting DB..." set -eux - cockroach sql "${FLAGS[@]}" -e "DROP DATABASE IF EXISTS ${CRDB_DATABASE};" || \ + $CMD sql "${FLAGS[@]}" -e "DROP DATABASE IF EXISTS ${CRDB_DATABASE};" || \ die "Error: Failed to drop database '${CRDB_DATABASE}'." - cockroach sql "${FLAGS[@]}" -e "CREATE DATABASE ${CRDB_DATABASE};" || \ + $CMD sql "${FLAGS[@]}" -e "CREATE DATABASE ${CRDB_DATABASE};" || \ die "Error: Failed to create database '${CRDB_DATABASE}'." if [[ ${CRDB_INSECURE} = 'true' ]]; then - cockroach sql "${FLAGS[@]}" -e "CREATE USER IF NOT EXISTS ${CRDB_USER};" || \ + $CMD sql "${FLAGS[@]}" -e "CREATE USER IF NOT EXISTS ${CRDB_USER};" || \ die "Error: Failed to create user '${CRDB_USER}'." else - cockroach sql "${FLAGS[@]}" -e "CREATE USER IF NOT EXISTS ${CRDB_USER} WITH PASSWORD '${CRDB_PASSWORD}';" || \ + $CMD sql "${FLAGS[@]}" -e "CREATE USER IF NOT EXISTS ${CRDB_USER} WITH PASSWORD '${CRDB_PASSWORD}';" || \ die "Error: Failed to create user '${CRDB_USER}'." fi - cockroach sql "${FLAGS[@]}" -e "GRANT ALL PRIVILEGES ON DATABASE ${CRDB_DATABASE} TO ${CRDB_USER} WITH GRANT OPTION" || \ + $CMD sql "${FLAGS[@]}" -e "GRANT ALL PRIVILEGES ON DATABASE ${CRDB_DATABASE} TO ${CRDB_USER} WITH GRANT OPTION" || \ die "Error: Failed to grant '${CRDB_USER}' user all privileges on '${CRDB_DATABASE}'." - cockroach sql "${FLAGS[@]}" -d ${CRDB_DATABASE} < ${TRILLIAN_PATH}/storage/crdb/schema/storage.sql || \ + $CMD sql "${FLAGS[@]}" -d ${CRDB_DATABASE} < ${TRILLIAN_PATH}/storage/crdb/schema/storage.sql || \ die "Error: Failed to create tables in '${CRDB_DATABASE}' database." echo "Reset Complete" fi