Skip to content

rgl/use-cockroachdb-go

Repository files navigation

About

Build

My CockroachDB Go example.

Usage

This can be tested in docker compose or in a kind kubernetes cluster.

List this repository dependencies (and which have newer versions):

GITHUB_COM_TOKEN='YOUR_GITHUB_PERSONAL_TOKEN' ./renovate.sh

Usage (docker compose)

Install docker and docker compose.

Create the environment:

docker compose up --build --detach
docker compose ps
docker compose logs

Start the cockroachdb client:

docker compose exec cockroachdb cockroach sql --no-line-editor --insecure

Execute some commands:

-- show information the postgresql version.
select version();
-- list roles.
\dg
-- list databases.
\l
-- insert a quote.
insert into quote(id, author, text, url) values(100, 'Hamlet', 'To be, or not to be, that is the question.', null);
-- select all quotes.
select text || ' -- ' || author as quote from quote;
-- exit
\q

Get a quote from the service:

wget -qO- http://localhost:4000

Destroy the environment:

docker compose down --volumes --remove-orphans --timeout=0

Usage (Kubernetes)

Install docker, kind, kubectl, and helm.

Create the local test infrastructure:

./.github/workflows/kind/create.sh

Access the test infrastructure kind Kubernetes cluster:

export KUBECONFIG="$PWD/kubeconfig.yml"
kubectl get nodes -o wide

Start the cockroachdb client:

kubectl exec --quiet --stdin --tty statefulset/cockroachdb -- \
    cockroach sql \
        --certs-dir /cockroach/cockroach-certs \
        --no-line-editor

Execute some commands:

-- show information the postgresql version.
select version();
-- list roles.
\dg
-- list databases.
\l
-- insert a quote.
insert into quote(id, author, text, url) values(100, 'Hamlet', 'To be, or not to be, that is the question.', null);
-- select all quotes.
select text || ' -- ' || author as quote from quote;
-- exit
\q

Build and use the use-cockroachdb-go example:

./build.sh && ./deploy.sh && ./test.sh && xdg-open index.html

Destroy the local test infrastructure:

./.github/workflows/kind/destroy.sh

References