Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds projects support #150

Merged
merged 21 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/docker-dev-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: 'Get Previous tag'
id: previoustag
uses: "WyriHaximus/github-action-get-previous-tag@v1"
with:
fallback: v0.1

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
Expand All @@ -38,5 +44,6 @@ jobs:
build-args: |
APP_VERSION=${{ steps.previoustag.outputs.tag }}
FRONTEND_IMAGE_TAG=dev
BRANCH=${{ steps.previoustag.outputs.tag }}
tags:
ghcr.io/${{ github.repository }}:dev, ghcr.io/${{ github.repository }}:${{ steps.previoustag.outputs.tag }}
1 change: 1 addition & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@ jobs:
build-args:
APP_VERSION=${{ steps.previoustag.outputs.tag }}
FRONTEND_IMAGE_TAG=latest
BRANCH=${{ steps.previoustag.outputs.tag }}
tags:
${{ secrets.DOCKER_HUB_USERNAME }}/buggregator:latest, ${{ secrets.DOCKER_HUB_USERNAME }}/buggregator:${{ steps.previoustag.outputs.tag }}
21 changes: 21 additions & 0 deletions .github/workflows/phpunit-database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
pull_request: null

name: phpunit

env:
PERSISTENCE_DRIVER: db
DB_DRIVER: sqlite

jobs:
phpunit-db:
uses: spiral/gh-actions/.github/workflows/phpunit.yml@master
with:
extensions: >-
['sockets', 'mongodb', 'pgsql', 'pdo_pgsql', 'pdo_mysql']
os: >-
['ubuntu-latest']
php: >-
['8.3']
stability: >-
['prefer-stable']
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ on:

name: phpunit

env:
PERSISTENCE_DRIVER: memory

jobs:
phpunit:
phpunit-memory:
uses: spiral/gh-actions/.github/workflows/phpunit.yml@master
with:
install_protoc: true
extensions: >-
['sockets', 'mongodb', 'pgsql', 'pdo_pgsql', 'pdo_mysql']
os: >-
['ubuntu-latest']
php: >-
['8.2', '8.3']
['8.3']
stability: >-
['prefer-stable']
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ protoc-gen-php-grpc*
.phpunit.result.cache
.php-cs-fixer.cache
.deptrac.cache
.phpunit.cache
build
8 changes: 5 additions & 3 deletions .rr-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ rpc:
server:
command: 'php app.php'
relay: pipes
env:
- MODE: 'roadrunner'
on_init:
command: "php app.php configure"

Expand Down Expand Up @@ -42,13 +44,13 @@ tcp:
kv:
events:
driver: memory
config: {}
config: { }
local:
driver: memory
config: {}
config: { }

jobs:
consume: []
consume: [ ]

service:
nginx:
Expand Down
2 changes: 2 additions & 0 deletions .rr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ rpc:
server:
command: 'php app.php'
relay: pipes
env:
- MODE: 'roadrunner'
on_init:
command: "php app.php configure"

Expand Down
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
build:
docker compose up --no-start;

start:
docker compose up --remove-orphans -d;

up: build start

stop:
docker compose stop;

down:
docker compose down;

restart:
docker compose restart;

list:
docker compose ps;

log-tail:
docker compose logs --tail=50 -f;

pull-latest:
docker compose pull;

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

bash:
docker compose exec buggregator-server /bin/sh;

reset-server:
docker compose exec buggregator-server ./rr reset;

reset: reset-server
2 changes: 2 additions & 0 deletions app/config/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
'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:'],
],
'storages' => [
'array' => [
Expand Down
19 changes: 0 additions & 19 deletions app/config/cycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,6 @@
'factories' => ['doctrine' => new DoctrineCollectionFactory()],
],
'generators' => null,
// 'generators' => [
// \Cycle\Annotated\Embeddings::class,
// \Cycle\Annotated\Entities::class,
// \Cycle\Annotated\MergeColumns::class,
// \Cycle\Schema\Generator\ResetTables::class,
// \Cycle\Schema\Generator\GenerateRelations::class,
// \Cycle\Schema\Generator\ValidateEntities::class,
// \Cycle\Schema\Generator\RenderTables::class,
// \Cycle\Schema\Generator\RenderRelations::class,
// \Cycle\Annotated\TableInheritance::class,
// \Cycle\Annotated\MergeIndexes::class
// \Cycle\Schema\Generator\GenerateTypecast::class,
// ],
],
'warmup' => env('CYCLE_SCHEMA_WARMUP', false),
'customRelations' => [
// \Cycle\ORM\Relation::EMBEDDED => [
// \Cycle\ORM\Config\RelationConfig::LOADER => \Cycle\ORM\Select\Loader\EmbeddedLoader::class,
// \Cycle\ORM\Config\RelationConfig::RELATION => \Cycle\ORM\Relation\Embedded::class,
// ]
],
];
28 changes: 10 additions & 18 deletions app/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,14 @@
'drivers' => [],
],

/**
* Default database connection
*/
'default' => 'default',

/**
* The Spiral/Database module provides support to manage multiple databases
* in one application, use read/write connections and logically separate
* multiple databases within one connection using prefixes.
*
* To register a new database simply add a new one into
* "databases" section below.
*/
'databases' => [
'default' => [
'driver' => env('DB_DRIVER', 'pgsql'),
],
],

/**
* Each database instance must have an associated connection object.
* Connections used to provide low-level functionality and wrap different
* database drivers. To register a new connection you have to specify
* the driver class and its connection options.
*/
'drivers' => [
'pgsql' => new Config\PostgresDriverConfig(
connection: new Config\Postgres\TcpConnectionConfig(
Expand All @@ -56,7 +39,7 @@
database: env('DB_DATABASE', 'buggregator'),
host: env('DB_HOST', '127.0.0.1'),
port: env('DB_PORT', 3306),
user: env('DB_USERNAME', 'postgres'),
user: env('DB_USERNAME', 'root'),
password: env('DB_PASSWORD'),
),
queryCache: true,
Expand All @@ -65,5 +48,14 @@
'logQueryParameters' => env('DB_LOG_QUERY_PARAMETERS', false),
],
),

// Only for testing purposes
// SQLite does not support multiple connections in the same time
'sqlite' => new Config\SQLiteDriverConfig(
connection: new Config\SQLite\MemoryConnectionConfig(),
options: [
'logQueryParameters' => env('DB_LOG_QUERY_PARAMETERS', false),
],
),
],
];
2 changes: 1 addition & 1 deletion app/config/migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Directory to store migration files
*/
'directory' => directory('app') . 'migrations/',
'directory' => directory('app') . 'database/Migrations/',

/**
* Table name to store information about migrations status (per database)
Expand Down
8 changes: 5 additions & 3 deletions app/config/queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use Spiral\RoadRunner\Jobs\Queue\MemoryCreateInfo;
use Spiral\RoadRunnerBridge\Queue\Queue;

$defaultConnection = env('QUEUE_DEFAULT_CONNECTION', 'roadrunner');

return [
'default' => env('QUEUE_CONNECTION', 'sync'),
'default' => env('QUEUE_CONNECTION', 'memory'),
'aliases' => [
'webhook' => 'roadrunner',
'events' => 'roadrunner',
'webhook' => $defaultConnection,
'events' => $defaultConnection,
],
'pipelines' => [
'memory' => [
Expand Down
1 change: 1 addition & 0 deletions app/config/swagger.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
directory('app') . 'src/Application/HTTP/Response',
directory('app') . 'src/Interfaces/Http',
directory('app') . 'modules/Events/Interfaces/Http',
directory('app') . 'modules/Projects/Interfaces/Http',
directory('app') . 'modules/Webhooks/Interfaces/Http',
],
];
76 changes: 76 additions & 0 deletions app/database/Factory/EventFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

declare(strict_types=1);

namespace Database\Factory;

use App\Application\Domain\Entity\Json;
use App\Application\Domain\ValueObjects\Uuid;
use Database\Factory\Partials\InspectorType;
use Database\Factory\Partials\MonologType;
use Database\Factory\Partials\ProfilerType;
use Database\Factory\Partials\RayType;
use Database\Factory\Partials\SentryType;
use Database\Factory\Partials\SmtpType;
use Database\Factory\Partials\VarDumperType;
use Modules\Events\Domain\Event;
use Modules\Events\Domain\ValueObject\Timestamp;
use Modules\Projects\Domain\ValueObject\Key;
use Spiral\DatabaseSeeder\Factory\AbstractFactory;

/**
* @implements AbstractFactory<Event>
*/
final class EventFactory extends AbstractFactory
{
use SmtpType,
ProfilerType,
SentryType,
MonologType,
InspectorType,
VarDumperType,
RayType;

public function entity(): string
{
return Event::class;
}

public function definition(): array
{
return [
'uuid' => Uuid::generate(),
'type' => $this->faker->randomElement(['sentry', 'monolog', 'var-dump', 'inspector', 'ray', 'profiler']),
'timestamp' => Timestamp::create(),
'project' => null,
];
}


public function makeEntity(array $definition): object
{
return new Event(
uuid: $definition['uuid'],
type: $definition['type'],
payload: new Json($this->getPayload($definition['type'])),
timestamp: $definition['timestamp'],
project: $definition['project']
? ($definition['project'] instanceof Key ? $definition['project'] : Key::create($definition['project']))
: null,
);
}

public function getPayload(string $type): array
{
return match ($type) {
'sentry' => self::getSentryPayload(),
'monolog' => self::getMonologPayload(),
'var-dump' => self::getVarDumperPayload(),
'inspector' => self::getInspectorPayload(),
'ray' => self::getRayPayload(),
'profiler' => self::getProfilerPayload(),
'smtp' => self::getSmtpPayload(),
default => ['foo' => 'bar'],
};
}
}
Loading
Loading