enum case consistency, wip creating service
This commit is contained in:
31
app/Actions/Services/CreateService.php
Normal file
31
app/Actions/Services/CreateService.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Services;
|
||||||
|
|
||||||
|
use App\Enums\ServiceCategory;
|
||||||
|
use App\Enums\ServiceStatus;
|
||||||
|
use App\Enums\ServiceType;
|
||||||
|
use App\Jobs\Services\InstallService;
|
||||||
|
use App\Models\Server;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
class CreateService
|
||||||
|
{
|
||||||
|
public function execute(
|
||||||
|
Server $server,
|
||||||
|
string $name,
|
||||||
|
ServiceCategory $category,
|
||||||
|
ServiceType $type,
|
||||||
|
string $version,
|
||||||
|
string $driverName,
|
||||||
|
) {
|
||||||
|
$service = $server->services()->create([
|
||||||
|
'name' => $name,
|
||||||
|
'category' => $category,
|
||||||
|
'type' => $type,
|
||||||
|
'version' => $version, // 17
|
||||||
|
'driver_name' => $driverName, // postgres
|
||||||
|
'status' => ServiceStatus::NOT_INSTALLED,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,8 +4,16 @@ namespace App\Data\Deployments;
|
|||||||
|
|
||||||
class Step
|
class Step
|
||||||
{
|
{
|
||||||
|
public string $script;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
public string $name = 'Step',
|
||||||
|
string|callable $script = 'echo "Incomplete Step"',
|
||||||
) {
|
) {
|
||||||
//
|
if (is_callable($script)) {
|
||||||
|
$this->script = $script();
|
||||||
|
} else {
|
||||||
|
$this->script = $script;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,5 +4,12 @@ namespace App\Drivers;
|
|||||||
|
|
||||||
interface DatabaseDriver extends Driver
|
interface DatabaseDriver extends Driver
|
||||||
{
|
{
|
||||||
//
|
public string $defaultUser = 'keystone';
|
||||||
|
public string $defaultDb = 'keystone';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public ?string $containerName = null,
|
||||||
|
public ?string $containerId = null,
|
||||||
|
public ?string $defaultPassword = null,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Drivers;
|
namespace App\Drivers;
|
||||||
|
|
||||||
|
use App\Data\Deployments\Plan;
|
||||||
|
|
||||||
interface Driver
|
interface Driver
|
||||||
{
|
{
|
||||||
//
|
public Plan $deploymentPlan { get; }
|
||||||
}
|
}
|
||||||
@@ -2,9 +2,54 @@
|
|||||||
|
|
||||||
namespace App\Drivers\Postgres;
|
namespace App\Drivers\Postgres;
|
||||||
|
|
||||||
|
use App\Data\Deployments\Plan;
|
||||||
|
use App\Data\Deployments\Step;
|
||||||
use App\Drivers\DatabaseDriver;
|
use App\Drivers\DatabaseDriver;
|
||||||
|
|
||||||
class Postgres17Driver implements DatabaseDriver
|
class Postgres17Driver implements DatabaseDriver
|
||||||
{
|
{
|
||||||
// @todo
|
public Plan $deploymentPlan;
|
||||||
|
public string $defaultUser = 'keystone';
|
||||||
|
public string $defaultDb = 'keystone';
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public ?string $containerName = null,
|
||||||
|
public ?string $containerId = null,
|
||||||
|
public ?string $defaultPassword = null,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
$this->deploymentPlan = new Plan(steps: [
|
||||||
|
new Step(
|
||||||
|
name: 'Check docker is installed',
|
||||||
|
script: 'command -v docker >/dev/null 2>&1 || { echo >&2 "Docker is not installed. Aborting."; exit 1; }',
|
||||||
|
),
|
||||||
|
new Step(
|
||||||
|
name: 'Run the docker image',
|
||||||
|
script: function () {
|
||||||
|
$script = collect();
|
||||||
|
if ($this->containerName) {
|
||||||
|
$script->push('docker stop ' . $this->containerName . ' || true');
|
||||||
|
} else if ($this->containerId) {
|
||||||
|
$script->push('docker stop ' . $this->containerId . ' || true');
|
||||||
|
}
|
||||||
|
|
||||||
|
$runCommand = "docker run -d";
|
||||||
|
if ($this->containerName) {
|
||||||
|
$runCommand .= " --name {$this->containerName}";
|
||||||
|
}
|
||||||
|
if ($this->defaultPassword) {
|
||||||
|
$runCommand .= " -e POSTGRES_PASSWORD={$this->defaultPassword}";
|
||||||
|
}
|
||||||
|
if ($this->defaultUser) {
|
||||||
|
$runCommand .= " -e POSTGRES_USER={$this->defaultUser}";
|
||||||
|
}
|
||||||
|
if ($this->defaultDb) {
|
||||||
|
$runCommand .= " -e POSTGRES_DB={$this->defaultDb}";
|
||||||
|
}
|
||||||
|
|
||||||
|
$runCommand .= " -p 5432:5432 postgres:17";
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,6 @@ namespace App\Enums;
|
|||||||
|
|
||||||
enum OrganisationRole: string
|
enum OrganisationRole: string
|
||||||
{
|
{
|
||||||
case Admin = 'admin';
|
case ADMIN = 'admin';
|
||||||
case Member = 'member';
|
case MEMBER = 'member';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ namespace App\Enums;
|
|||||||
|
|
||||||
enum RepositoryType: string
|
enum RepositoryType: string
|
||||||
{
|
{
|
||||||
case Git = 'git';
|
case GIT = 'git';
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,6 @@ namespace App\Enums;
|
|||||||
|
|
||||||
enum ServerProvider: string
|
enum ServerProvider: string
|
||||||
{
|
{
|
||||||
case Hetzner = 'hetzner';
|
case HETZNER = 'hetzner';
|
||||||
case DigitalOcean = 'digital-ocean';
|
case DIGITAL_OCEAN = 'digital-ocean';
|
||||||
}
|
}
|
||||||
|
|||||||
12
app/Enums/ServiceCategory.php
Normal file
12
app/Enums/ServiceCategory.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum ServiceCategory: string
|
||||||
|
{
|
||||||
|
case DATABASE = 'database';
|
||||||
|
case APPLICATION = 'application';
|
||||||
|
case GATEWAY = 'gateway';
|
||||||
|
case STORAGE = 'storage';
|
||||||
|
case CACHE = 'cache';
|
||||||
|
}
|
||||||
@@ -4,6 +4,8 @@ namespace App\Enums;
|
|||||||
|
|
||||||
enum ServiceStatus: string
|
enum ServiceStatus: string
|
||||||
{
|
{
|
||||||
|
case NOT_INSTALLED = 'not-installed';
|
||||||
|
case INSTALLING = 'installing';
|
||||||
case RUNNING = 'running';
|
case RUNNING = 'running';
|
||||||
case STOPPED = 'stopped';
|
case STOPPED = 'stopped';
|
||||||
case ERROR = 'error';
|
case ERROR = 'error';
|
||||||
|
|||||||
16
app/Enums/ServiceType.php
Normal file
16
app/Enums/ServiceType.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum ServiceType: string {
|
||||||
|
case FRANKENPHP = 'frankenphp';
|
||||||
|
case PHP_FPM = 'php-fpm';
|
||||||
|
case POSTGRES = 'postgres';
|
||||||
|
case CADDY = 'caddy';
|
||||||
|
case VALKEY = 'valkey';
|
||||||
|
|
||||||
|
// future?
|
||||||
|
case MYSQL = 'mysql';
|
||||||
|
case NGINX = 'nginx';
|
||||||
|
case REDIS = 'redis';
|
||||||
|
}
|
||||||
@@ -3,7 +3,9 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Drivers\Driver;
|
use App\Drivers\Driver;
|
||||||
|
use App\Enums\ServiceCategory;
|
||||||
use App\Enums\ServiceStatus;
|
use App\Enums\ServiceStatus;
|
||||||
|
use App\Enums\ServiceType;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
@@ -16,6 +18,8 @@ class Service extends Model
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'status' => ServiceStatus::class,
|
'status' => ServiceStatus::class,
|
||||||
|
'category' => ServiceCategory::class,
|
||||||
|
'type' => ServiceType::class,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class User extends Authenticatable
|
|||||||
'slug' => Organisation::createUniqueSlug($user->name),
|
'slug' => Organisation::createUniqueSlug($user->name),
|
||||||
'owner_id' => $user->id,
|
'owner_id' => $user->id,
|
||||||
]);
|
]);
|
||||||
$organisation->members()->attach($user, ['role' => OrganisationRole::Admin]);
|
$organisation->members()->attach($user, ['role' => OrganisationRole::ADMIN]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
101
config/app.php
101
config/app.php
@@ -1,126 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Application Name
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| This value is the name of your application, which will be used when the
|
|
||||||
| framework needs to place the application's name in a notification or
|
|
||||||
| other UI elements where an application name needs to be displayed.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'name' => env('APP_NAME', 'Laravel'),
|
'name' => env('APP_NAME', 'Laravel'),
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Application Environment
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| This value determines the "environment" your application is currently
|
|
||||||
| running in. This may determine how you prefer to configure various
|
|
||||||
| services the application utilizes. Set this in your ".env" file.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'env' => env('APP_ENV', 'production'),
|
'env' => env('APP_ENV', 'production'),
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Application Debug Mode
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| When your application is in debug mode, detailed error messages with
|
|
||||||
| stack traces will be shown on every error that occurs within your
|
|
||||||
| application. If disabled, a simple generic error page is shown.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'debug' => (bool) env('APP_DEBUG', false),
|
'debug' => (bool) env('APP_DEBUG', false),
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Application URL
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| This URL is used by the console to properly generate URLs when using
|
|
||||||
| the Artisan command line tool. You should set this to the root of
|
|
||||||
| the application so that it's available within Artisan commands.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'url' => env('APP_URL', 'http://localhost'),
|
'url' => env('APP_URL', 'http://localhost'),
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Application Timezone
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| Here you may specify the default timezone for your application, which
|
|
||||||
| will be used by the PHP date and date-time functions. The timezone
|
|
||||||
| is set to "UTC" by default as it is suitable for most use cases.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'timezone' => 'UTC',
|
'timezone' => 'UTC',
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Application Locale Configuration
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| The application locale determines the default locale that will be used
|
|
||||||
| by Laravel's translation / localization methods. This option can be
|
|
||||||
| set to any locale for which you plan to have translation strings.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'locale' => env('APP_LOCALE', 'en'),
|
'locale' => env('APP_LOCALE', 'en'),
|
||||||
|
|
||||||
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),
|
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),
|
||||||
|
|
||||||
'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'),
|
'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'),
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Encryption Key
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| This key is utilized by Laravel's encryption services and should be set
|
|
||||||
| to a random, 32 character string to ensure that all encrypted values
|
|
||||||
| are secure. You should do this prior to deploying the application.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'cipher' => 'AES-256-CBC',
|
'cipher' => 'AES-256-CBC',
|
||||||
|
|
||||||
'key' => env('APP_KEY'),
|
'key' => env('APP_KEY'),
|
||||||
|
|
||||||
'previous_keys' => [
|
'previous_keys' => [
|
||||||
...array_filter(
|
...array_filter(
|
||||||
explode(',', env('APP_PREVIOUS_KEYS', ''))
|
explode(',', env('APP_PREVIOUS_KEYS', ''))
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Maintenance Mode Driver
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| These configuration options determine the driver used to determine and
|
|
||||||
| manage Laravel's "maintenance mode" status. The "cache" driver will
|
|
||||||
| allow maintenance mode to be controlled across multiple machines.
|
|
||||||
|
|
|
||||||
| Supported drivers: "file", "cache"
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'maintenance' => [
|
'maintenance' => [
|
||||||
'driver' => env('APP_MAINTENANCE_DRIVER', 'file'),
|
'driver' => env('APP_MAINTENANCE_DRIVER', 'file'),
|
||||||
'store' => env('APP_MAINTENANCE_STORE', 'database'),
|
'store' => env('APP_MAINTENANCE_STORE', 'database'),
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
11
config/keystone.php
Normal file
11
config/keystone.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Drivers\Postgres\Postgres17Driver;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'drivers' => [
|
||||||
|
'postgres' => [
|
||||||
|
'17' => Postgres17Driver::class,
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
@@ -31,12 +31,12 @@ class DatabaseSeeder extends Seeder
|
|||||||
'owner_id' => 1,
|
'owner_id' => 1,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$organisation->members()->attach($user, ['role' => OrganisationRole::Admin]);
|
$organisation->members()->attach($user, ['role' => OrganisationRole::ADMIN]);
|
||||||
|
|
||||||
$application = $organisation->applications()->create([
|
$application = $organisation->applications()->create([
|
||||||
'name' => 'ClipBin',
|
'name' => 'ClipBin',
|
||||||
'repository_url' => 'git@github.com:hjbdev/clipbin.git',
|
'repository_url' => 'git@github.com:hjbdev/clipbin.git',
|
||||||
'repository_type' => RepositoryType::Git,
|
'repository_type' => RepositoryType::GIT,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$application->environments()->create([
|
$application->environments()->create([
|
||||||
|
|||||||
Reference in New Issue
Block a user