Skip to content

Commit f80989f

Browse files
committed
Add Bigtable infrastructure scripts and Makefile
1 parent 9b089b4 commit f80989f

3 files changed

Lines changed: 136 additions & 0 deletions

File tree

Makefile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
.PHONY: build test test-integration test-all clean doc bigtable-up bigtable-down help
2+
3+
# Default target
4+
help:
5+
@echo "rust-bigtable Makefile"
6+
@echo ""
7+
@echo "Build targets:"
8+
@echo " make build - Build the library"
9+
@echo " make check - Check compilation without building"
10+
@echo " make doc - Generate documentation"
11+
@echo " make clean - Clean build artifacts"
12+
@echo ""
13+
@echo "Test targets:"
14+
@echo " make test - Run doc tests"
15+
@echo " make test-integration - Run integration tests (requires Bigtable)"
16+
@echo " make test-all - Run all tests"
17+
@echo ""
18+
@echo "Bigtable infrastructure:"
19+
@echo " make bigtable-up - Create Bigtable instance and table"
20+
@echo " make bigtable-down - Delete Bigtable instance"
21+
@echo ""
22+
@echo "Environment variables:"
23+
@echo " PROJECT_ID - GCP project ID (default: gen-lang-client-0421059902)"
24+
@echo " INSTANCE_ID - Bigtable instance ID (default: test-inst)"
25+
@echo " TABLE_NAME - Table name (default: my-table)"
26+
@echo " COLUMN_FAMILY - Column family name (default: cf1)"
27+
28+
# Build targets
29+
build:
30+
cargo build
31+
32+
check:
33+
cargo check
34+
35+
doc:
36+
cargo doc --no-deps --open
37+
38+
clean:
39+
cargo clean
40+
41+
# Test targets
42+
test:
43+
cargo test
44+
45+
test-integration:
46+
cargo test --test integration_tests -- --ignored --test-threads=1
47+
48+
test-all: test test-integration
49+
50+
# Bigtable infrastructure
51+
bigtable-up:
52+
./scripts/bigtable-up.sh
53+
54+
bigtable-down:
55+
./scripts/bigtable-down.sh

scripts/bigtable-down.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# Deletes the Bigtable instance (and all tables within it)
3+
set -e
4+
5+
PROJECT_ID="${PROJECT_ID:-gen-lang-client-0421059902}"
6+
INSTANCE_ID="${INSTANCE_ID:-test-inst}"
7+
8+
echo "Deleting Bigtable instance..."
9+
echo " Project: $PROJECT_ID"
10+
echo " Instance: $INSTANCE_ID"
11+
echo ""
12+
13+
# Check if instance exists
14+
if ! gcloud bigtable instances describe "$INSTANCE_ID" --project="$PROJECT_ID" &>/dev/null; then
15+
echo "Instance '$INSTANCE_ID' does not exist, nothing to delete."
16+
exit 0
17+
fi
18+
19+
read -p "Are you sure you want to delete instance '$INSTANCE_ID'? This will delete ALL tables. [y/N] " -n 1 -r
20+
echo ""
21+
22+
if [[ $REPLY =~ ^[Yy]$ ]]; then
23+
gcloud bigtable instances delete "$INSTANCE_ID" --project="$PROJECT_ID" --quiet
24+
echo "Instance '$INSTANCE_ID' deleted."
25+
else
26+
echo "Aborted."
27+
exit 1
28+
fi

scripts/bigtable-up.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
# Creates a Bigtable instance, table, and column family for testing
3+
set -e
4+
5+
PROJECT_ID="${PROJECT_ID:-gen-lang-client-0421059902}"
6+
INSTANCE_ID="${INSTANCE_ID:-test-inst}"
7+
CLUSTER_ID="${CLUSTER_ID:-test-cluster}"
8+
ZONE="${ZONE:-us-central1-c}"
9+
TABLE_NAME="${TABLE_NAME:-my-table}"
10+
COLUMN_FAMILY="${COLUMN_FAMILY:-cf1}"
11+
12+
echo "Creating Bigtable instance..."
13+
echo " Project: $PROJECT_ID"
14+
echo " Instance: $INSTANCE_ID"
15+
echo " Cluster: $CLUSTER_ID"
16+
echo " Zone: $ZONE"
17+
18+
# Check if instance already exists
19+
if gcloud bigtable instances describe "$INSTANCE_ID" --project="$PROJECT_ID" &>/dev/null; then
20+
echo "Instance '$INSTANCE_ID' already exists, skipping creation."
21+
else
22+
gcloud bigtable instances create "$INSTANCE_ID" \
23+
--project="$PROJECT_ID" \
24+
--cluster="$CLUSTER_ID" \
25+
--cluster-zone="$ZONE" \
26+
--display-name="Test Instance"
27+
echo "Instance created."
28+
fi
29+
30+
echo ""
31+
echo "Creating table '$TABLE_NAME' with column family '$COLUMN_FAMILY'..."
32+
33+
# Check if table exists
34+
if cbt -project="$PROJECT_ID" -instance="$INSTANCE_ID" ls 2>/dev/null | grep -q "^$TABLE_NAME$"; then
35+
echo "Table '$TABLE_NAME' already exists, skipping creation."
36+
else
37+
cbt -project="$PROJECT_ID" -instance="$INSTANCE_ID" createtable "$TABLE_NAME"
38+
echo "Table created."
39+
fi
40+
41+
# Check if column family exists
42+
if cbt -project="$PROJECT_ID" -instance="$INSTANCE_ID" ls "$TABLE_NAME" 2>/dev/null | grep -q "$COLUMN_FAMILY"; then
43+
echo "Column family '$COLUMN_FAMILY' already exists, skipping creation."
44+
else
45+
cbt -project="$PROJECT_ID" -instance="$INSTANCE_ID" createfamily "$TABLE_NAME" "$COLUMN_FAMILY"
46+
echo "Column family created."
47+
fi
48+
49+
echo ""
50+
echo "Bigtable setup complete!"
51+
echo " Instance: $INSTANCE_ID"
52+
echo " Table: $TABLE_NAME"
53+
echo " Column Family: $COLUMN_FAMILY"

0 commit comments

Comments
 (0)