Skip to content

Commit 2a3e837

Browse files
committed
Use docker-compose to spin up a local CockroachDB cluster for testing
1 parent b005ae8 commit 2a3e837

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
COMPOSE=docker-compose -f docker-compose.yml
2+
13
.PHONY: all
24
all: test lint
35

@@ -27,3 +29,15 @@ clean:
2729
.PHONY: detox
2830
detox: clean
2931
rm -rf .tox
32+
33+
.PHONY: db-up
34+
db-up:
35+
${COMPOSE} up -d
36+
37+
.PHONY: db-down
38+
db-down:
39+
${COMPOSE} down
40+
41+
.PHONY: db-recreate
42+
db-recreate:
43+
${COMPOSE} exec cockroach-0 ./cockroach sql --insecure -e 'drop database defaultdb; create database defaultdb;'

docker-compose.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: "3.7"
2+
3+
x-cockroach-base: &cockroach-base
4+
image: cockroachdb/cockroach:v21.1.2
5+
6+
services:
7+
cockroach-0:
8+
<<: *cockroach-base
9+
container_name: cockroach-0
10+
command: start --insecure --advertise-addr=cockroach-0 --join=cockroach-0,cockroach-1,cockroach-2 --store=type=mem,size=1GB
11+
ports:
12+
- "26257:26257"
13+
14+
cockroach-1:
15+
<<: *cockroach-base
16+
container_name: cockroach-1
17+
command: start --insecure --advertise-addr=cockroach-1 --join=cockroach-0,cockroach-1,cockroach-2 --store=type=mem,size=1GB
18+
19+
cockroach-2:
20+
<<: *cockroach-base
21+
container_name: cockroach-2
22+
command: start --insecure --advertise-addr=cockroach-2 --join=cockroach-0,cockroach-1,cockroach-2 --store=type=mem,size=1GB
23+
24+
cockroach-init:
25+
<<: *cockroach-base
26+
container_name: cockroach-init
27+
depends_on:
28+
- cockroach-0
29+
- cockroach-1
30+
- cockroach-2
31+
command: init --insecure --host=cockroach-0

0 commit comments

Comments
 (0)