rcloud-base
This repository contains all the rcloud-system components that are the backbone for ztka and gitops.
Prerequisites
- Postgres: Primary database
- Ory Kratos: API for user management
- Elasticsearch: Storage for audit logs
You can use the bitnami/charts for postgres and elastic/helm-charts for elasticsearch.
Development setup
Using docker-compose
Run following Docker Compose command to setup all requirements like Postgres db, Kratos etc. for the rcloud-base.
This will start up postgres and elasticsearch as well as kratos and run the kratos migrations. It will also run all the necessary migrations. It also starts up a mail slurper for you to use Kratos.
docker-compose up -d
Start rcloud-base:
go run github.com/RafayLabs/rcloud-base
Manual
Start databases
Postgres
docker run --network host \
--env POSTGRES_HOST_AUTH_METHOD=trust \
-v pgdata:/var/lib/postgresql/data \
-it postgres
Elasticsearch
docker run --network host \
-v elastic-data:/usr/share/elasticsearch/data \
-e "discovery.type=single-node" \
-e "xpack.security.enabled=false" \
-it docker.elastic.co/elasticsearch/elasticsearch:8.0.0
Create the initial db/user
Scripts for admindb:
create database admindb;
CREATE ROLE admindbuser WITH LOGIN PASSWORD '<your_password>';
GRANT ALL PRIVILEGES ON DATABASE admindb to admindbuser;
Now in the newly created db:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
grant execute on function uuid_generate_v4() to admindbuser;
Scripts for clusterdb:
create database clusterdb;
CREATE ROLE clusterdbuser WITH LOGIN PASSWORD '<your_password>';
GRANT ALL PRIVILEGES ON DATABASE clusterdb to clusterdbuser;
Now in the newly created db:
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
grant execute on function uuid_generate_v4() to clusterdbuser;
This will grant the necessary permission to the newly created user to run uuid_generate_v4()
Run application migrations
We use golang-migrate to perform migrations.
Install golang-migrate
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
-tags 'postgres' is important as otherwise it compiles without postgres support
You can refer to the guide for full details.
Run migrations
Example for admindb:
export POSTGRESQL_URL='postgres://<user>:<pass>@<host>:<port>/admindb?sslmode=disable'
migrate -path ./persistence/migrations/admindb -database "$POSTGRESQL_URL" up
See cli-usage for more info.
Development setup
Copy env.example to .env:
cp env.example .env
Run following Docker Compose command to setup all requirements like Postgres db, Kratos etc. for the rcloud-base:
docker-compose up -d
Start rcloud-base server:
go run github.com/RafayLabs/rcloud-base