Skip to content

Commit a4563be

Browse files
authored
Merge pull request #9 from dployr-io/non-static-deploy
Non static deploy
2 parents f1b8b52 + 131e7dd commit a4563be

33 files changed

Lines changed: 189 additions & 199 deletions

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ jobs:
4040
run: vendor/bin/pint --test
4141

4242
- name: Lint Frontend
43-
run: pnpm run format:check
43+
run: pnpm run format:check && pnpm run lint

.github/workflows/release.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
name: Release
1+
name: release
22

33
on:
44
workflow_run:
5-
workflows: ["Test"]
5+
workflows: ["tests", "linter"]
66
types: [completed]
77
pull_request:
88
branches: ["master"]
@@ -12,9 +12,7 @@ permissions:
1212

1313
jobs:
1414
release:
15-
if: >
16-
github.event.workflow_run.conclusion == 'success' &&
17-
github.event.workflow_run.head_branch == 'master'
15+
if: github.event.pull_request.merged == true
1816
runs-on: ubuntu-latest
1917
steps:
2018
- name: Checkout

app/DTOs/Spec.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public function __construct(
1515
public string $runtime,
1616
public ?int $port,
1717
public ?string $image,
18-
public array $envVars = [],
19-
public array $secrets = [],
18+
public array $envVars,
19+
public array $secrets,
2020
public ?string $outputDir,
2121
public ?string $workingDir,
2222
public ?string $runCmd,
2323
) {}
24-
}
24+
}

app/Services/Blueprint/BlueprintService.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Services\Blueprint;
44

5+
use App\DTOs\Spec;
56
use App\Models\Blueprint;
67
use App\Models\Remote;
78
use App\Models\Service;
@@ -11,13 +12,11 @@
1112
use App\Services\DirectoryService;
1213
use App\Services\GitRepoService;
1314
use Illuminate\Support\Facades\Log;
14-
use App\Services\Blueprint\BlueprintValidatorService;
15-
use App\DTOs\Spec;
1615

1716
class BlueprintService
1817
{
1918
protected const BASE_PATH = '/home/dployr/services';
20-
19+
2120
public function __construct(
2221
private Blueprint $blueprint,
2322
) {
@@ -31,13 +30,15 @@ private function parseConfig()
3130

3231
private function validateBlueprint()
3332
{
34-
$validator = new BlueprintValidatorService();
33+
$validator = new BlueprintValidatorService;
34+
3535
return $validator->validate($this->parseConfig());
3636
}
3737

3838
private function getAttributes(): Spec
3939
{
4040
$config = $this->parseConfig();
41+
4142
return new Spec(
4243
id: $this->blueprint->id,
4344
serviceName: $config['name'],
@@ -54,16 +55,15 @@ private function getAttributes(): Spec
5455
runCmd: $config['run_cmd'] ?? null,
5556
);
5657
}
57-
58+
5859
public function processBlueprint()
59-
{
60+
{
6061
$validation = $this->validateBlueprint();
6162
$spec = $this->getAttributes();
62-
$path = rtrim(self::BASE_PATH, '/') . '/' . $spec->serviceName . '/' . ltrim($workingDir ?? '', '/');
63-
63+
$path = rtrim(self::BASE_PATH, '/').'/'.$spec->serviceName.'/'.ltrim($workingDir ?? '', '/');
64+
6465
try {
65-
if (! $validation['valid'])
66-
{
66+
if (! $validation['valid']) {
6767
throw new \RuntimeException($validation['errors']);
6868
}
6969

@@ -75,7 +75,7 @@ public function processBlueprint()
7575
// setup runtime
7676

7777
$remoteService = new GitRepoService;
78-
$remoteService->cloneRepo($remote->name, $remote->repository, $remote->provider, $this->$path."/".$spec->serviceName);
78+
$remoteService->cloneRepo($remote->name, $remote->repository, $remote->provider, $this->$path.'/'.$spec->serviceName);
7979

8080
$newBlock = <<<EOF
8181
:$spec->port {
@@ -130,4 +130,4 @@ public function processBlueprint()
130130
Log::error("Failed to create service $spec->serviceName: ".$errorMessage);
131131
}
132132
}
133-
}
133+
}

app/Services/Blueprint/BlueprintValidatorService.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
class BlueprintValidatorService extends SchemaValidatorService
88
{
99
private const SCHEMA_URL = 'https://dployr.dev/schema/1.0.0/service.json';
10+
1011
private const CACHE_KEY = 'service_schema_v1.0.0';
12+
1113
private const CACHE_TTL = 86400; // 24 hours
1214

1315
private function __construct(
1416
private string $schema_url = self::SCHEMA_URL,
1517
private string $cache_key = self::CACHE_KEY,
1618
private int $cache_ttl = self::CACHE_TTL,
17-
)
18-
{
19+
) {
1920
parent::__construct($schema_url, $cache_key, $cache_ttl);
2021
}
2122

@@ -33,4 +34,4 @@ public function clearCache(): void
3334
{
3435
return parent::clearCache();
3536
}
36-
}
37+
}

app/Services/CaddyService.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class CaddyService
77
public static function status(): bool
88
{
99
$result = CmdService::execute('systemctl is-active caddy');
10+
1011
return $result->output === 'active';
1112
}
1213

@@ -18,6 +19,7 @@ public static function config(): string
1819
if (! $result) {
1920
throw new \RuntimeException("Caddyfile not found or inaccessible in $path", 1);
2021
}
22+
2123
return trim($result);
2224
}
2325

@@ -26,13 +28,13 @@ public static function newConfig(string $serviceName, string $block)
2628
$baseConfig = '/etc/caddy/Caddyfile';
2729
$sitesDir = '/etc/caddy/sites-enabled';
2830
$filePath = "$sitesDir/{$serviceName}.conf";
29-
31+
3032
if (! is_dir($sitesDir)) {
3133
mkdir($sitesDir, 0750, true);
3234
}
3335

3436
$block = trim(str_replace(["\r\n", "\r"], "\n", $block));
35-
$tmp = tempnam(sys_get_temp_dir() . "/dployr", 'caddy');
37+
$tmp = tempnam(sys_get_temp_dir().'/dployr', 'caddy');
3638
file_put_contents($tmp, $block);
3739
$result = CmdService::execute("chown caddy:caddy $tmp");
3840

@@ -70,6 +72,7 @@ public static function checkPort(int $port): bool
7072
{
7173
$caddyfile = self::config();
7274
$pattern = "/^\\s*:$port\\b/m";
75+
7376
return preg_match($pattern, $caddyfile) === 1;
7477
}
7578

app/Services/CleanParseService.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ class CleanParseService
66
{
77
/**
88
* Strips out null values from an object
9-
* @param array $data
10-
* @return array
119
*/
1210
public static function withoutNulls(array $data): array
1311
{
14-
return array_filter($data, fn($v) => !is_null($v));
12+
return array_filter($data, fn ($v) => ! is_null($v));
1513
}
16-
}
14+
}

app/Services/SchemaValidatorService.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,29 @@
22

33
namespace App\Services;
44

5-
use JsonSchema\Validator;
6-
use JsonSchema\Constraints\Constraint;
7-
use App\Services\HttpService;
85
use Illuminate\Support\Facades\Cache;
6+
use JsonSchema\Constraints\Constraint;
7+
use JsonSchema\Validator;
98

109
abstract class SchemaValidatorService
1110
{
1211
public function __construct(
13-
protected string $schema_url,
14-
protected string $cache_key,
12+
protected string $schema_url,
13+
protected string $cache_key,
1514
protected int $cache_ttl
1615
) {}
1716

1817
/**
1918
* Validate the blueprint config against the JSON schema
2019
*
21-
* @param array $config The config array to validate
20+
* @param array $config The config array to validate
2221
* @return array Returns ['valid' => bool, 'errors' => array]
2322
*/
2423
public function validate(array $config): array
2524
{
2625
$schema = $this->getSchema();
2726
$configObject = json_decode(json_encode($config));
28-
$validator = new Validator();
27+
$validator = new Validator;
2928
$validator->validate(
3029
$configObject,
3130
$schema,
@@ -35,7 +34,7 @@ public function validate(array $config): array
3534
if ($validator->isValid()) {
3635
return [
3736
'valid' => true,
38-
'errors' => []
37+
'errors' => [],
3938
];
4039
}
4140
$errors = [];
@@ -46,17 +45,17 @@ public function validate(array $config): array
4645
'constraint' => $error['constraint'] ?? null,
4746
];
4847
}
48+
4949
return [
5050
'valid' => false,
51-
'errors' => $errors
51+
'errors' => $errors,
5252
];
5353
}
5454

5555
/**
5656
* Get validation errors as a formatted string
5757
*
58-
* @param array $errors The errors array from validate()
59-
* @return string
58+
* @param array $errors The errors array from validate()
6059
*/
6160
public function formatErrors(array $errors): string
6261
{
@@ -72,17 +71,16 @@ public function formatErrors(array $errors): string
7271
/**
7372
* Fetch and cache the JSON schema
7473
*
75-
* @return object
7674
* @throws \RuntimeException
7775
*/
7876
private function getSchema(): object
7977
{
80-
$schema = Cache::remember($this->cache_key, $this->cache_ttl, function () {
78+
$schema = Cache::remember($this->cache_key, $this->cache_ttl, function () {
8179
try {
8280
return HttpService::makeRequest('get', $this->schema_url);
8381
} catch (\Exception $e) {
8482
throw new \RuntimeException(
85-
"Unable to fetch schema from " . $this->schema_url . ": " . $e->getMessage()
83+
'Unable to fetch schema from '.$this->schema_url.': '.$e->getMessage()
8684
);
8785
}
8886
});
@@ -97,4 +95,4 @@ public function clearCache(): void
9795
{
9896
Cache::forget($this->schema_url);
9997
}
100-
}
98+
}

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
"@php artisan test"
6767
],
6868
"lint": [
69+
"vendor/bin/pint"
70+
],
71+
"lint:check": [
6972
"vendor/bin/pint --test"
7073
],
7174
"sync": [

resources/js/components/app-sidebar.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@ import { NavFooter } from '@/components/nav-footer';
22
import { NavMain } from '@/components/nav-main';
33
import { NavUser } from '@/components/nav-user';
44
import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarMenu, SidebarMenuButton, SidebarMenuItem } from '@/components/ui/sidebar';
5-
import { console, deploymentsIndex, imagesIndex, logs, projectsIndex, remotesIndex, specsIndex, notificationsIndex, resourceManagerIndex } from '@/routes';
5+
import {
6+
console,
7+
deploymentsIndex,
8+
imagesIndex,
9+
logs,
10+
notificationsIndex,
11+
projectsIndex,
12+
remotesIndex,
13+
resourceManagerIndex,
14+
specsIndex,
15+
} from '@/routes';
616
import { type NavItem } from '@/types';
717
import { Link } from '@inertiajs/react';
818
import {

0 commit comments

Comments
 (0)