Skip to content

Commit 6779316

Browse files
author
dcorroyer
committed
test: new infra archi
1 parent ab53779 commit 6779316

File tree

135 files changed

+7289
-9967
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+7289
-9967
lines changed

.castor/castor.composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
],
1010
"autoload": {
1111
"psr-4": {
12-
"dcorroyer\\mybudget\\": "./src/"
12+
"TheoD\\MusicAutoTagger\\": "./src/"
1313
}
1414
},
1515
"require": {
16-
"theod02/castor-class-task": "dev-main"
16+
"theod02/castor-class-task": "dev-main",
17+
"phlak/semver": "dev-master"
1718
},
1819
"repositories": [
1920
{

.castor/castor.composer.lock

+61-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.castor/castor.php

+93-36
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,28 @@
22

33
declare(strict_types=1);
44

5+
use Castor\Attribute\AsArgument;
56
use Castor\Attribute\AsOption;
67
use Castor\Attribute\AsTask;
7-
use dcorroyer\mybudget\Docker\DockerUtils;
8+
use TheoD\MusicAutoTagger\ContainerDefinitionBag;
9+
use TheoD\MusicAutoTagger\Docker\DockerUtils;
810

11+
use function Castor\Attribute\AsArgument;
912
use function Castor\capture;
1013
use function Castor\context;
1114
use function Castor\finder;
15+
use function Castor\fingerprint;
16+
use function Castor\fs;
1217
use function Castor\import;
1318
use function Castor\io;
14-
use function Castor\notify;
1519
use function Castor\run;
16-
use function dcorroyer\mybudget\delayed_fingerprint;
17-
use function dcorroyer\mybudget\docker;
18-
use function dcorroyer\mybudget\fgp;
19-
use function dcorroyer\mybudget\Runner\composer;
20-
use function dcorroyer\mybudget\Runner\npm;
21-
use function dcorroyer\mybudget\Runner\qa;
20+
use function TheoD\MusicAutoTagger\app_context;
21+
use function TheoD\MusicAutoTagger\docker;
22+
use function TheoD\MusicAutoTagger\fgp;
23+
use function TheoD\MusicAutoTagger\Runner\composer;
24+
use function TheoD\MusicAutoTagger\Runner\pnpm;
25+
use function TheoD\MusicAutoTagger\Runner\qa;
26+
use function TheoD\MusicAutoTagger\Runner\symfony;
2227

2328
import('composer://theod02/castor-class-task');
2429

@@ -35,18 +40,19 @@ function start(bool $force = false): void
3540
}
3641

3742
if (
38-
! delayed_fingerprint(
43+
! fingerprint(
3944
callback: static fn () => docker()
40-
->compose('--profile', 'app', 'build', '--no-cache')
45+
->compose('-f', 'compose.yaml', '-f', 'compose.override.yaml', 'build')
4146
->run(),
42-
fingerprint: static fn () => fgp()->php_docker(),
43-
force: $force
47+
id: 'docker',
48+
fingerprint: fgp()->php_docker(),
49+
force: $force,
4450
)
4551
) {
4652
io()->note('Docker images are already built.');
4753
}
4854

49-
docker()->compose('--profile', 'app', 'up', '-d', '--wait')->run();
55+
docker()->compose('-f', 'compose.yaml', '-f', 'compose.override.yaml', 'up', '-d', '--wait')->run();
5056
}
5157

5258
#[AsTask]
@@ -69,46 +75,71 @@ function install(bool $force = false): void
6975

7076
io()->title('Installing dependencies');
7177
io()->section('Composer');
72-
$forceVendor = $force || ! is_dir(context()->workingDirectory . '/vendor');
73-
if (! delayed_fingerprint(
78+
$forceVendor = $force || ! is_dir(app_context()->workingDirectory . '/vendor');
79+
if (! fingerprint(
7480
callback: static fn () => composer()->install()->run(),
75-
fingerprint: static fn () => fgp()->composer(),
76-
force: $forceVendor || $force
81+
id: 'composer',
82+
fingerprint: fgp()->composer(),
83+
force: $forceVendor || $force,
7784
)) {
7885
io()->note('Composer dependencies are already installed.');
7986
} else {
8087
io()->success('Composer dependencies installed');
8188
}
8289

90+
// io()->section('Generate auth Keypair');
91+
// if (fs()->exists(app_context()->workingDirectory . '/config/jwt/private.pem')) {
92+
// io()->note('Auth keypair already exists');
93+
// } else {
94+
// symfony()->console('lexik:jwt:generate-keypair')->run();
95+
// }
96+
8397
io()->section('QA tools');
8498
qa()->install();
8599

86-
io()->section('NPM');
87-
$forceNodeModules = $force || ! is_dir(context()->workingDirectory . '/node_modules');
88-
if (! delayed_fingerprint(
89-
callback: static fn () => npm()->install()->run(),
90-
fingerprint: static fn () => fgp()->npm(),
91-
force: $forceNodeModules || $force
92-
)) {
93-
io()->note('NPM dependencies are already installed.');
94-
} else {
95-
io()->success('NPM dependencies installed');
100+
if (pnpm()->hasPackageJson()) {
101+
io()->section('NPM');
102+
$forceNodeModules = $force || ! is_dir(app_context()->workingDirectory . '/node_modules');
103+
if (! fingerprint(
104+
callback: static fn () => pnpm()->install()->run(),
105+
id: 'npm',
106+
fingerprint: fgp()->npm(),
107+
force: $forceNodeModules || $force,
108+
)) {
109+
io()->note('NPM dependencies are already installed.');
110+
} else {
111+
io()->success('NPM dependencies installed');
112+
}
113+
114+
pnpm()->add('run', 'build')->run();
96115
}
97116

98-
npm()->add('run', 'build')->run();
117+
db_reset();
118+
119+
// notify('Dependencies installed');
120+
}
99121

100-
notify('Dependencies installed');
122+
#[AsTask(name: 'sync')]
123+
function sync(): void
124+
{
125+
symfony()->console('spotify:sync')->run();
126+
symfony()->console('spotify:sync:artists:full')->run();
127+
symfony()->console('spotify:sync:tracks:full')->run();
128+
symfony()->console('spotify:sync:tracks:full:audio-feature')->run();
101129
}
102130

103131
#[AsTask]
104132
function shell(
105133
#[AsOption(name: 'no-check', description: 'Don\'t check the dependencies')]
106-
bool $noCheck = false // Not used here, but used in listeners.php
134+
bool $noCheck = false, // Not used here, but used in listeners.php,
135+
#[AsArgument(name: 'cmd', description: 'Command to run')]
136+
?string $command = null,
107137
): void {
108138
docker(context()->withTty())
109139
->compose('exec')
110140
->add('--user', 'www-data')
111-
->add('app', 'fish')
141+
->add(ContainerDefinitionBag::php()->composeName, 'fish')
142+
->addIf($command !== null, '-c', "\"{$command}\"")
112143
->run()
113144
;
114145
}
@@ -117,10 +148,10 @@ function shell(
117148
#[AsTask]
118149
function generate_domain_dir(string $domainName): void
119150
{
120-
$srcDirectory = context()->workingDirectory . '/src';
151+
$srcDirectory = app_context()->workingDirectory . '/src';
121152
$domainName = ucfirst($domainName);
122153

123-
$domainDirectory = $srcDirectory . '/' . $domainName;
154+
$domainDirectory = "{$srcDirectory}/{$domainName}";
124155

125156
if (is_dir($domainDirectory)) {
126157
io()->error("Domain directory {$domainName} already exists");
@@ -212,13 +243,13 @@ function import_sql(): void
212243
#[AsTask(name: 'ui:install')]
213244
function ui_install(): void
214245
{
215-
npm()->install();
246+
pnpm()->install();
216247
}
217248

218249
#[AsTask(name: 'ui:dev')]
219250
function ui_dev(): void
220251
{
221-
npm(context()->withTty())->add('run', 'dev')->run();
252+
pnpm(context()->withTty())->add('run', 'dev')->run();
222253
}
223254

224255
#[AsTask(name: 'ui:format')]
@@ -265,7 +296,33 @@ function ui_http_schema(): void
265296
->compose('exec')
266297
->add('--user', 'www-data')
267298
->add('--workdir', '/app/assets')
268-
->add('app', 'npx', 'openapi-typescript', 'http://music-auto-tagger.web.localhost/api/docs.json', '-o', './src/api/schema.d.ts')
299+
->add(
300+
'app',
301+
'npx',
302+
'openapi-typescript',
303+
'http://mantine-starter-kit.web.localhost/api/docs.json',
304+
'-o',
305+
'./src/api/schema.d.ts',
306+
)
269307
->run()
270308
;
271309
}
310+
311+
#[AsTask(name: 'db:reset')]
312+
function db_reset(): void
313+
{
314+
// Check if the database app exists
315+
$output = docker(context()->withQuiet())->compose(
316+
"exec -it database sh -c \"psql -d app -c '\\l'\"",
317+
)->run()->getOutput();
318+
if (str_contains($output, 'app')) {
319+
if (io()->confirm('The database "app" already exists. Do you want to drop it?', false) === false) {
320+
return;
321+
}
322+
}
323+
324+
symfony()->console('doctrine:database:drop', '--force', '--if-exists')->run();
325+
symfony()->console('doctrine:database:create')->run();
326+
symfony()->console('doctrine:migrations:migrate', '--allow-no-migration', '--no-interaction')->run();
327+
symfony()->console('doctrine:fixtures:load', '--no-interaction', '--append')->run();
328+
}

.castor/src/ContainerDefinitionBag.php

+18-8
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22

33
declare(strict_types=1);
44

5-
namespace dcorroyer\mybudget;
5+
namespace TheoD\MusicAutoTagger;
66

7-
use dcorroyer\mybudget\Docker\ContainerDefinition;
7+
use TheoD\MusicAutoTagger\Docker\ContainerDefinition;
88

99
class ContainerDefinitionBag
1010
{
11-
public static function php(): ContainerDefinition
12-
{
13-
return new ContainerDefinition(composeName: 'app', name: 'mybudget-app-1', workingDirectory: '/app', user: 'www-data');
14-
}
15-
1611
public static function tools(?string $toolName = null): ContainerDefinition
1712
{
1813
if ($toolName === null) {
@@ -22,8 +17,23 @@ public static function tools(?string $toolName = null): ContainerDefinition
2217
return self::php()->withWorkingDirectory("/tools/{$toolName}");
2318
}
2419

20+
public static function php(): ContainerDefinition
21+
{
22+
return new ContainerDefinition(
23+
composeName: 'php',
24+
name: 'mybudget-php-1',
25+
workingDirectory: '/app',
26+
user: 'www-data',
27+
);
28+
}
29+
2530
public static function node(): ContainerDefinition
2631
{
27-
return new ContainerDefinition(composeName: 'app', name: 'mybudget-app-1', workingDirectory: '/app', user: 'www-data');
32+
return new ContainerDefinition(
33+
composeName: 'php',
34+
name: 'mybudget-php-1',
35+
workingDirectory: '/app',
36+
user: 'www-data',
37+
);
2838
}
2939
}

.castor/src/Docker/ContainerDefinition.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace dcorroyer\mybudget\Docker;
5+
namespace TheoD\MusicAutoTagger\Docker;
66

77
class ContainerDefinition
88
{

.castor/src/Docker/DockerRunner.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
declare(strict_types=1);
44

5-
namespace dcorroyer\mybudget\Docker;
5+
namespace TheoD\MusicAutoTagger\Docker;
66

77
use Castor\Context;
8-
use dcorroyer\mybudget\Runner\Runner;
8+
use TheoD\MusicAutoTagger\Runner\Runner;
99

1010
class DockerRunner extends Runner
1111
{

.castor/src/Docker/DockerUtils.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace dcorroyer\mybudget\Docker;
5+
namespace TheoD\MusicAutoTagger\Docker;
66

77
use function Castor\context;
88

0 commit comments

Comments
 (0)