Skip to content

Commit

Permalink
Replaces in-memory database with Dolt, which is MySQL
Browse files Browse the repository at this point in the history
issue #114
  • Loading branch information
butschster committed May 1, 2024
1 parent c0964c8 commit 1ab9695
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 429 deletions.
7 changes: 7 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
ARG ROAD_RUNNER_IMAGE=2023.3.7
ARG CENTRIFUGO_IMAGE=v4
ARG DOLT_IMAGE=latest
ARG FRONTEND_IMAGE_TAG=latest

# Build centrifugo binary
FROM centrifugo/centrifugo:$CENTRIFUGO_IMAGE as centrifugo
# Build dolt binary
FROM dolthub/dolt:$DOLT_IMAGE as dolt
# Build rr binary
FROM ghcr.io/roadrunner-server/roadrunner:$ROAD_RUNNER_IMAGE as rr
# Build JS files
Expand All @@ -22,6 +25,7 @@ COPY --from=git /app /app
COPY --from=frontend /app /app/frontend
COPY --from=rr /usr/bin/rr /app
COPY --from=centrifugo /usr/local/bin/centrifugo /app/bin
COPY --from=dolt /usr/local/bin/dolt /app/bin

ARG APP_VERSION=v1.0
ENV COMPOSER_ALLOW_SUPERUSER=1
Expand All @@ -35,6 +39,9 @@ WORKDIR /app
RUN mkdir /app/runtime/configs -p
RUN php app.php configure

RUN mkdir .db
RUN bin/dolt --data-dir=.db sql -q "create database buggregator;"

EXPOSE 8082/tcp

ENV APP_VERSION=$APP_VERSION
Expand Down
64 changes: 0 additions & 64 deletions .github/workflows/phpunit-memory.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ protoc-gen-php-grpc*
.deptrac.cache
.phpunit.cache
.cache
.db
.sqlhistory
8 changes: 5 additions & 3 deletions .rr-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ tcp:
num_workers: ${RR_TCP_NUM_WORKERS}

kv:
events:
driver: memory
config: { }
local:
driver: memory
config: { }
Expand All @@ -64,6 +61,11 @@ service:
remain_after_exit: true
restart_sec: 1
command: "./bin/centrifugo --config=centrifugo.json"
dolt:
service_name_in_log: true
remain_after_exit: true
restart_sec: 1
command: "./bin/dolt sql-server --data-dir=.db"

centrifuge:
proxy_address: ${RR_CENTRIFUGE_PROXY_ADDRESS}
Expand Down
20 changes: 7 additions & 13 deletions .rr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,24 @@ tcp:
addr: 127.0.0.1:1025

kv:
events:
driver: memory
config: {}
local:
driver: memory
config: {}
config: { }

jobs:
consume: []
consume: [ ]

service:
# frontend:
# service_name_in_log: true
# remain_after_exit: true
# restart_sec: 1
# command: "npm run dev"
# env:
# VITE_EVENTS_WS_API: ws:https://127.0.0.1:8089/connection/websocket
# VITE_EVENTS_REST_API: https://127.0.0.1:8082
centrifuge:
service_name_in_log: true
remain_after_exit: true
restart_sec: 1
command: "./bin/centrifugo --config=centrifugo.json"
dolt:
service_name_in_log: true
remain_after_exit: true
restart_sec: 1
command: "./bin/dolt sql-server --data-dir=.db"

centrifuge:
proxy_address: "tcp:https://127.0.0.1:10001"
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ build:
if [ ! -d "vendor" ]; then \
composer i --ignore-platform-reqs; \
fi
if [ ! -d ".db" ]; then \
mkdir .db; \
chmod 0777 -R .db; \
bin/dolt --data-dir=.db sql -q "create database buggregator;"; \
fi

docker compose up --no-start;

start:
Expand All @@ -40,6 +46,9 @@ log-tail:
pull-latest:
docker compose pull;

build-server:
docker compose build buggregator-server --no-cache;

# =========================

bash:
Expand Down
2 changes: 0 additions & 2 deletions app/config/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
return [
'default' => env('CACHE_STORAGE', 'roadrunner'),
'aliases' => [
'events' => ['storage' => $defaultStorage, 'prefix' => 'events:'],
'projects' => ['storage' => $defaultStorage, 'prefix' => 'projects:'],
'webhooks' => ['storage' => $defaultStorage, 'prefix' => 'webhooks:'],
'local' => ['storage' => $defaultStorage, 'prefix' => 'local:'],
'smtp' => ['storage' => $defaultStorage, 'prefix' => 'smtp:'],
Expand Down
4 changes: 2 additions & 2 deletions app/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'databases' => [
'default' => [
'driver' => env('DB_DRIVER', 'pgsql'),
'driver' => env('DB_DRIVER', 'mysql'),
],
],

Expand Down Expand Up @@ -52,7 +52,7 @@
// Only for testing purposes
// SQLite does not support multiple connections in the same time
'sqlite' => new Config\SQLiteDriverConfig(
connection: new Config\SQLite\MemoryConnectionConfig(),
connection: new Config\SQLite\FileConnectionConfig(database: directory('runtime') . 'test.db'),
options: [
'logQueryParameters' => env('DB_LOG_QUERY_PARAMETERS', false),
],
Expand Down
18 changes: 0 additions & 18 deletions app/src/Application/Bootloader/PersistenceBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
use App\Integration\CycleOrm\Persistence\CycleOrmProjectRepository;
use App\Integration\MongoDb\Persistence\MongoDBEventRepository;
use App\Integration\MongoDb\Persistence\MongoDBProjectRepository;
use App\Integration\RoadRunner\Persistence\CacheEventRepository;
use App\Integration\RoadRunner\Persistence\CacheProjectRepository;
use App\Interfaces\Console\RegisterModulesCommand;
use Cycle\ORM\EntityManagerInterface;
use Cycle\ORM\ORMInterface;
Expand All @@ -21,8 +19,6 @@
use Modules\Projects\Domain\ProjectRepositoryInterface;
use MongoDB\Database;
use Spiral\Boot\Bootloader\Bootloader;
use Spiral\Boot\EnvironmentInterface;
use Spiral\Cache\CacheStorageProviderInterface;
use Spiral\Console\Bootloader\ConsoleBootloader;
use Spiral\Core\FactoryInterface;
use Spiral\Cycle\Bootloader as CycleBridge;
Expand Down Expand Up @@ -53,7 +49,6 @@ public function defineSingletons(): array
): EventRepositoryInterface => match ($driver) {
DriverEnum::Database => $factory->make(CycleOrmEventRepository::class),
DriverEnum::MongoDb => $factory->make(MongoDBEventRepository::class),
DriverEnum::InMemory => $factory->make(CacheEventRepository::class),
},
CycleOrmEventRepository::class => static fn(
ORMInterface $orm,
Expand All @@ -64,13 +59,6 @@ public function defineSingletons(): array
): MongoDBEventRepository => new MongoDBEventRepository(
$database->selectCollection('events'),
),
CacheEventRepository::class => static fn(
CacheStorageProviderInterface $provider,
EnvironmentInterface $env,
): EventRepositoryInterface => new CacheEventRepository(
cache: $provider->storage('events'),
ttl: (int) $env->get('EVENTS_CACHE_TTL', 60 * 60 * 2),
),

// Projects
ProjectRepositoryInterface::class => static fn(
Expand All @@ -79,7 +67,6 @@ public function defineSingletons(): array
): ProjectRepositoryInterface => match ($driver) {
DriverEnum::Database => $factory->make(CycleOrmProjectRepository::class),
DriverEnum::MongoDb => $factory->make(MongoDBProjectRepository::class),
DriverEnum::InMemory => $factory->make(CacheProjectRepository::class),
},
CycleOrmProjectRepository::class => static fn(
ORMInterface $orm,
Expand All @@ -90,11 +77,6 @@ public function defineSingletons(): array
): ProjectRepositoryInterface => new MongoDBProjectRepository(
$database->selectCollection('projects'),
),
CacheProjectRepository::class => static fn(
CacheStorageProviderInterface $provider,
): ProjectRepositoryInterface => new CacheProjectRepository(
cache: $provider->storage('projects'),
),
];
}

Expand Down
4 changes: 1 addition & 3 deletions app/src/Application/Persistence/DriverEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
#[ProvideFrom('detect')]
enum DriverEnum implements InjectableEnumInterface
{
case InMemory;
case Database;
case MongoDb;

public static function detect(EnvironmentInterface $env): self
{
return match ($env->get('PERSISTENCE_DRIVER', 'memory')) {
'cache', 'memory', 'in-memory' => self::InMemory,
return match ($env->get('PERSISTENCE_DRIVER', 'db')) {
'cycle', 'database', 'db' => self::Database,
'mongodb', 'mongo' => self::MongoDb,
};
Expand Down
Loading

0 comments on commit 1ab9695

Please sign in to comment.