add credentials to services

This commit is contained in:
2025-04-09 11:09:40 +01:00
parent a2a3e9002d
commit eefe6243bc
7 changed files with 39 additions and 29 deletions

View File

@@ -5,27 +5,28 @@ namespace App\Drivers\Postgres;
use App\Data\Deployments\Plan;
use App\Data\Deployments\PlannedStep as Step;
use App\Drivers\DatabaseDriver;
use Illuminate\Support\Str;
class Postgres17Driver extends DatabaseDriver
{
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,
public ?array $credentials = null,
) {
$user = $credentials['user'];
$password = $credentials['password'];
$db = $credentials['db'];
$this->deploymentPlan = new Plan(steps: [
new Step(
name: 'Run the docker image',
secrets: [
'defaultpassword' => $this->defaultPassword,
'password' => $password
],
script: function () {
script: function () use ($user, $password, $db) {
$script = collect();
if ($this->containerName) {
$script->push('docker stop '.$this->containerName.' || true');
@@ -37,14 +38,14 @@ class Postgres17Driver extends DatabaseDriver
if ($this->containerName) {
$runCommand .= " --name {$this->containerName}";
}
if ($this->defaultPassword) {
$runCommand .= ' -e POSTGRES_PASSWORD=[!defaultPassword!]';
if ($password) {
$runCommand .= ' -e POSTGRES_PASSWORD=[!password!]';
}
if ($this->defaultUser) {
$runCommand .= " -e POSTGRES_USER={$this->defaultUser}";
if ($user) {
$runCommand .= " -e POSTGRES_USER={$user}";
}
if ($this->defaultDb) {
$runCommand .= " -e POSTGRES_DB={$this->defaultDb}";
if ($db) {
$runCommand .= " -e POSTGRES_DB={$db}";
}
$runCommand .= ' -p 5432:5432 postgres:17';
@@ -58,4 +59,13 @@ class Postgres17Driver extends DatabaseDriver
),
]);
}
public function defaultCredentials(): array
{
return [
'password' => Str::random(16),
'user' => 'keystone',
'db' => 'keystone',
];
}
}