Skip to content

Commit

Permalink
Added CockroachDB Docker Compose setup for Simple Pongo sample
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Oct 1, 2024
1 parent ca81e7f commit 0e27f26
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 0 deletions.
7 changes: 7 additions & 0 deletions samples/simple-ts/cockroachdb/haproxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM haproxy:lts-bullseye

COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg

EXPOSE 26257
EXPOSE 8080
EXPOSE 8081
37 changes: 37 additions & 0 deletions samples/simple-ts/cockroachdb/haproxy/haproxy.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
global
log stdout format raw local0 info
maxconn 20000

defaults
log global
timeout connect 10m
timeout client 30m
timeout server 30m
option clitcpka
option tcplog

listen cockroach-jdbc
bind :26000
mode tcp
balance leastconn
option httpchk GET /health?ready=1
server roach-0 roach-0:26257 check port 8080
server roach-1 roach-1:26257 check port 8080
server roach-2 roach-2:26257 check port 8080

listen cockroach-ui
bind :8080
mode tcp
balance leastconn
option httpchk GET /health
server roach-0 roach-0:8080 check port 8080
server roach-1 roach-1:8080 check port 8080
server roach-2 roach-2:8080 check port 8080

listen stats
bind :8081
mode http
stats enable
stats hide-version
stats realm Haproxy\ Statistics
stats uri /
69 changes: 69 additions & 0 deletions samples/simple-ts/docker-compose-cockroachdb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
version: '3.9'

# Took from: https://github.com/dbist/cockroach-docker
# Connect to db console with: docker exec -it roach-0 ./cockroach sql --host=roach-0:26257 --insecure

services:
roach-0:
container_name: roach-0
hostname: roach-0
image: cockroachdb/cockroach-unstable:v23.2.0-beta.1
command: start --insecure --join=roach-0,roach-1,roach-2 --listen-addr=roach-0:26257 --advertise-addr=roach-0:26257 --max-sql-memory=.25 --cache=.25
environment:
- 'ALLOW_EMPTY_PASSWORD=yes'
- 'COCKROACH_USER=postgres'
- 'COCKROACH_PASSWORD=postgres'
- 'COCKROACH_DATABASE=postgres'

roach-1:
container_name: roach-1
hostname: roach-1
image: cockroachdb/cockroach-unstable:v23.2.0-beta.1
command: start --insecure --join=roach-0,roach-1,roach-2 --listen-addr=roach-1:26257 --advertise-addr=roach-1:26257 --max-sql-memory=.25 --cache=.25
environment:
- 'ALLOW_EMPTY_PASSWORD=yes'
- 'COCKROACH_USER=postgres'
- 'COCKROACH_PASSWORD=postgres'
- 'COCKROACH_DATABASE=postgres'

roach-2:
container_name: roach-2
hostname: roach-2
image: cockroachdb/cockroach-unstable:v23.2.0-beta.1
command: start --insecure --join=roach-0,roach-1,roach-2 --listen-addr=roach-2:26257 --advertise-addr=roach-2:26257 --max-sql-memory=.25 --cache=.25
environment:
- 'ALLOW_EMPTY_PASSWORD=yes'
- 'COCKROACH_USER=postgres'
- 'COCKROACH_PASSWORD=postgres'
- 'COCKROACH_DATABASE=postgres'

init:
container_name: init
image: cockroachdb/cockroach-unstable:v23.2.0-beta.1
command: init --host=roach-0 --insecure
environment:
- 'ALLOW_EMPTY_PASSWORD=yes'
- 'COCKROACH_USER=postgres'
- 'COCKROACH_PASSWORD=postgres'
- 'COCKROACH_DATABASE=postgres'
depends_on:
- roach-0

lb:
container_name: lb
hostname: lb
build: cockroachdb/haproxy
ports:
- '5432:26000'
- '8080:8080'
- '8081:8081'
depends_on:
- roach-0
- roach-1
- roach-2

client:
container_name: client
hostname: client
image: cockroachdb/cockroach-unstable:v23.2.0-beta.1
entrypoint: ['/usr/bin/tail', '-f', '/dev/null']
1 change: 1 addition & 0 deletions samples/simple-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type User = { _id?: string; name: string; age: number };

const connectionString =
'postgresql://postgres:postgres@localhost:5432/postgres';
// 'postgresql://root@localhost:26000/defaultdb?sslmode=disable'; // cockroachdb

const pongo = pongoClient(connectionString);
const pongoDb = pongo.db();
Expand Down
1 change: 1 addition & 0 deletions samples/simple-ts/src/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type User = { name: string; age: number };

const connectionString =
'postgresql://postgres:postgres@localhost:5432/postgres';
// 'postgresql://root@localhost:26000/defaultdb?sslmode=disable'; // cockroachdb

const pongoClient = new MongoClient(connectionString);
const pongoDb = pongoClient.db('postgres');
Expand Down
1 change: 1 addition & 0 deletions samples/simple-ts/src/typedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import config from './pongo.config';

const connectionString =
'postgresql://postgres:postgres@localhost:5432/postgres';
// 'postgresql://root@localhost:26000/defaultdb?sslmode=disable'; // cockroachdb

const pongo = pongoClient(connectionString, {
schema: { definition: config.schema, autoMigration: 'None' },
Expand Down

0 comments on commit 0e27f26

Please sign in to comment.