Skip to content

Commit

Permalink
Adds ScyllaDB based docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
fr33m0nk committed Jun 29, 2024
1 parent 1b35c67 commit adab722
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN apk add --no-cache --update \
RUN curl -fsSL -o datomic-pro.zip https://datomic-pro-downloads.s3.amazonaws.com/${DATOMIC_VERSION}/datomic-pro-${DATOMIC_VERSION}.zip
RUN unzip -qq ./datomic-pro.zip -d / && true
RUN mv "/datomic-pro-${DATOMIC_VERSION}" /datomic-pro && true
RUN curl -fsSL -o /datomic-pro/lib/logstash-logback-encoder-7.4.jar https://repo1.maven.org/maven2/net/logstash/logback/logstash-logback-encoder/7.4/logstash-logback-encoder-7.4.jar
RUN curl -fsSL -o /datomic-pro/lib/logstash-logback-encoder-7.3.jar https://repo1.maven.org/maven2/net/logstash/logback/logstash-logback-encoder/7.3/logstash-logback-encoder-7.3.jar
COPY ./artifacts/logback.xml /datomic-pro/bin/logback.xml
RUN rm -rf ./datomic-pro.zip

Expand Down Expand Up @@ -60,6 +60,8 @@ ENV SQL_DRIVER_CLASS ""
# TRANSACTOR DDB-LOCAL Backend
ENV DYNAMO_DB_TABLE ""
ENV LOCAL_DYNAMO_DB_ENDPOINT ""
ENV AWS_ACCESS_KEY_ID="none"
ENV AWS_SECRET_ACCESS_KEY="none"

# TRANSACTOR DDB Backend
ENV AWS_DYNAMO_DB_REGION ""
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
| AWS_CLOUDWATCH_DIMENSION_VALUE | `TRANSACTOR`, `PEER`, `BACKUP_DB`, `RESTORE_DB`, `CONSOLE` WITH PROTOCOL `DDB` | | **None, provided by user** |
| DYNAMO_DB_TABLE | `TRANSACTOR`, `PEER`, `BACKUP_DB`, `RESTORE_DB`, `CONSOLE` WITH PROTOCOL `DDB` OR `DDB-LOCAL` | | **None, provided by user** |
| LOCAL_DYNAMO_DB_ENDPOINT | `TRANSACTOR`, `PEER`, `BACKUP_DB`, `RESTORE_DB`, `CONSOLE` WITH PROTOCOL `DDB` OR `DDB-LOCAL` | | **None, provided by user** |
| AWS_ACCESS_KEY_ID | `TRANSACTOR`, `PEER`, `BACKUP_DB`, `RESTORE_DB`, `CONSOLE` WITH PROTOCOL `DDB` OR `DDB-LOCAL` | | `none` |
| AWS_SECRET_ACCESS_KEY | `TRANSACTOR`, `PEER`, `BACKUP_DB`, `RESTORE_DB`, `CONSOLE` WITH PROTOCOL `DDB` OR `DDB-LOCAL` | | `none` |
| PEER_HOST | `PEER` | | `0.0.0.0` |
| PEER_PORT | `PEER` | | `8998` |
| PEER_ACCESSKEY | `PEER` | | `myaccesskey` |
Expand Down
4 changes: 4 additions & 0 deletions docker-compose/.env
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ CONSOLE_HOST_MAPPING_PORT=8888
IPV4_SUBNET_CIDR=192.168.29.0/24
IP_RANGE=192.168.29.64/26
GATEWAY_IP=192.168.29.1

SCYLLA_DB_PROTOCOL=DDB-LOCAL
SCYLLA_DB_HOST_MAPPING_PORT=8000
DYNAMO_DB_TABLE=test-database
59 changes: 57 additions & 2 deletions docker-compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@

## The configuration variables for docker compose file are in [`.env`](./.env) file

## Usage
## Usage with SQL backend

### Starting the docker compose
1. Start containers
```bash
docker compose up --build transactor peer datomic-db-initialization console -d
DOCKER_BUILDKIT=1 docker compose up \
--build \
transactor \
datomic-db-initialization \
peer \
console \
--force-recreate \
--remove-orphans \
-d
```
2. Connect via Datomic peer
```clojure
Expand Down Expand Up @@ -52,6 +60,53 @@ user=> (dc/connect client {:db-name "test-database"}) ;; DATOMIC_DB_NAME

```

## Usage with Scylla DB backend

### Starting the docker compose

```bash
DOCKER_BUILDKIT=1 docker compose \
-f ./docker-compose-scylla-db.yml \
up \
--build \
transactor \
datomic-db-initialization \
peer \
console \
--force-recreate \
--remove-orphans \
-d
```

2. Connect via Datomic peer
```clojure
(require '[datomic.api :as d])
;; nil

;; assuming DATOMIC DB name is stored in environment variable `DATOMIC_DB_NAME`
(def db-uri (format "datomic:ddb-local://localhost:8000/%s" (System/getenv "DATOMIC_DB_NAME")))
;; #'user/db-uri

user=> (d/connect db-uri)
;; #object[datomic.peer.Connection 0x738da6f2 "{:unsent-updates-queue 0, :pending-txes 0, :next-t 1000, :basis-t 66, :index-rev 0, :db-id \"hello-275c1f24-482a-4ae2-86a8-844555f04f46\"}"]

```
3. Connect via Datomic client
```clojure
(require '[datomic.client.api :as dc])

(def client (dd/client {:server-type :peer-server
:access-key "myaccesskey" ;; PEER_ACCESSKEY
:secret "mysecret" ;; PEER_SECRET
:endpoint "localhost:8998"
:validate-hostnames false}))
;; #'user/client

user=> (dc/connect client {:db-name "test-database"}) ;; DATOMIC_DB_NAME
{:db-name "hello", :database-id "hello-275c1f24-482a-4ae2-86a8-844555f04f46", :t 66, :next-t 1000, :type :datomic.client/conn}

```

### Stopping the docker compose
```bash
docker compose down
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
(require '[datomic.api :as d])
(import '[clojure.lang ExceptionInfo])

(def uri (format "datomic:sql://%s?%s?user=%s&password=%s"
(System/getenv "DATOMIC_DB_NAME")
(System/getenv "SQL_JDBC_URL")
(System/getenv "SQL_USER")
(System/getenv "SQL_PASSWORD")))
(def uri
(cond
(= (System/getenv "PROTOCOL") "DDB-LOCAL")
(format "datomic:ddb-local://%s/%s/%s"
(System/getenv "LOCAL_DYNAMO_DB_ENDPOINT")
(System/getenv "DYNAMO_DB_TABLE")
(System/getenv "DATOMIC_DB_NAME"))

:else (format "datomic:sql://%s?%s?user=%s&password=%s"
(System/getenv "DATOMIC_DB_NAME")
(System/getenv "SQL_JDBC_URL")
(System/getenv "SQL_USER")
(System/getenv "SQL_PASSWORD"))))

(defn database-migrator
[uri]
Expand Down
174 changes: 174 additions & 0 deletions docker-compose/docker-compose-scylla-db.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
version: '3.9'
name: datomic-cluster

services:
memcached:
container_name: memcached
image: memcached:${MEMCACHED_IMAGE_TAG}
command: memcached -m ${MEMCACHED_MAX_RAM}
ports:
- ${MEMCACHED_HOST_MAPPING_PORT}:11211
restart: always
networks:
datomic-network:
ipv4_address: 192.168.200.2
healthcheck:
test: echo stats | nc 127.0.0.1 11211
interval: 10s
retries: 60

scylla-db:
container_name: scylla-db
image: scylladb/scylla
ports:
- ${SCYLLA_DB_HOST_MAPPING_PORT}:8000
command: "--smp 1 --memory=750M --alternator-port=8000 --alternator-write-isolation=always_use_lwt"
volumes:
- scylla-db:/var/lib/scylla
networks:
datomic-network:
ipv4_address: 192.168.200.3
restart: always
healthcheck:
test: cqlsh -e "SHOW VERSION" || exit 1
interval: 15s
retries: 10
start_period: 30s
timeout: 30s

transactor:
build:
context: ../
args:
DATOMIC_VERSION: ${DATOMIC_VERSION}
dockerfile: Dockerfile
ports:
- "4336:4336"
- "4335:4335"
- "4334:4334"
- "9999:9999"
environment:
- RUN_MODE=TRANSACTOR
- PROTOCOL=${SCYLLA_DB_PROTOCOL}
- DYNAMO_DB_TABLE=${DYNAMO_DB_TABLE}
- LOCAL_DYNAMO_DB_ENDPOINT=scylla-db:8000
- TRANSACTOR_HOST=192.168.200.4
- TRANSACTOR_ALT_HOST=127.0.0.1
- MEMCACHED_HOST=192.168.200.2
volumes:
- datomic-transactor-log:/datomic-pro/log
healthcheck:
test: ["CMD-SHELL", 'if [[ $(curl -s -o /dev/null -w "%{http_code}" -X GET http://transactor:9999/health) = "200" ]]; then echo 0; else echo 1; fi']
interval: 10s
timeout: 3s
retries: 30
networks:
datomic-network:
ipv4_address: 192.168.200.4
restart: always
depends_on:
scylla-db:
condition: service_healthy
memcached:
condition: service_healthy

datomic-db-initialization:
build:
context: ../
args:
DATOMIC_VERSION: ${DATOMIC_VERSION}
dockerfile: Dockerfile
environment:
- RUN_MODE=TRANSACTOR
- PROTOCOL=${SCYLLA_DB_PROTOCOL}
- DYNAMO_DB_TABLE=${DYNAMO_DB_TABLE}
- LOCAL_DYNAMO_DB_ENDPOINT=scylla-db:8000
- DATOMIC_DB_NAME=${DATOMIC_DB_NAME}
- RETRIES=${DATOMIC_DB_CREATION_RETRIES}
volumes:
- "./datomic-database-initialization/initialize_database.clj:/datomic-pro/initialize_database.clj"
restart: on-failure:1
entrypoint: /datomic-pro/bin/run /datomic-pro/initialize_database.clj
networks:
datomic-network:
ipv4_address: 192.168.200.254
depends_on:
scylla-db:
condition: service_healthy
memcached:
condition: service_healthy
transactor:
condition: service_healthy

peer:
build:
context: ../
args:
DATOMIC_VERSION: ${DATOMIC_VERSION}
dockerfile: Dockerfile
ports:
- "8998:8998"
environment:
- RUN_MODE=PEER
- PROTOCOL=${PROTOCOL}
- PEER_HOST=192.168.200.5
- PROTOCOL=${SCYLLA_DB_PROTOCOL}
- DYNAMO_DB_TABLE=${DYNAMO_DB_TABLE}
- LOCAL_DYNAMO_DB_ENDPOINT=scylla-db:8000
- DATOMIC_DB_NAME=${DATOMIC_DB_NAME}
- PEER_ACCESSKEY=${PEER_ACCESSKEY}
- PEER_SECRET=${PEER_SECRET}
- MEMCACHED_HOST=192.168.200.2
restart: always
networks:
datomic-network:
ipv4_address: 192.168.200.5
depends_on:
scylla-db:
condition: service_healthy
memcached:
condition: service_healthy
transactor:
condition: service_healthy
datomic-db-initialization:
condition: service_completed_successfully

console:
build:
context: ../
args:
DATOMIC_VERSION: ${DATOMIC_VERSION}
dockerfile: Dockerfile
ports:
- ${CONSOLE_HOST_MAPPING_PORT}:8888
environment:
- RUN_MODE=CONSOLE
- PROTOCOL=${SCYLLA_DB_PROTOCOL}
- DYNAMO_DB_TABLE=${DYNAMO_DB_TABLE}
- LOCAL_DYNAMO_DB_ENDPOINT=scylla-db:8000
- TRANSACTOR_ALIAS=home-txn
networks:
datomic-network:
ipv4_address: 192.168.200.6
restart: always
depends_on:
scylla-db:
condition: service_healthy
transactor:
condition: service_healthy
datomic-db-initialization:
condition: service_completed_successfully


networks:
datomic-network:
driver: bridge
ipam:
driver: default
config:
-
subnet: 192.168.200.0/24

volumes:
scylla-db:
datomic-transactor-log:

0 comments on commit adab722

Please sign in to comment.