-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcastor.php
More file actions
125 lines (98 loc) · 3.44 KB
/
Copy pathcastor.php
File metadata and controls
125 lines (98 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
use Castor\Attribute\AsTask;
use function Castor\context;
use function Castor\guard_min_version;
use function Castor\import;
use function Castor\io;
use function Castor\notify;
use function Castor\variable;
use function docker\about;
use function docker\build;
use function docker\docker_compose_run;
use function docker\up;
// use function docker\workers_start;
// use function docker\workers_stop;
guard_min_version('1.5.0');
import(__DIR__ . '/.castor');
/**
* @return array{project_name: string, root_domain: string, registry: string}
*/
function create_default_variables(): array
{
$projectName = 'monologue';
$tld = 'test';
return [
'project_name' => $projectName,
'root_domain' => "{$projectName}.{$tld}",
'registry' => 'ghcr.io/jolicode/monologue',
];
}
#[AsTask(description: 'Builds and starts the infrastructure, then install the application (composer, ...)')]
function start(): void
{
io()->title('Starting the stack');
// workers_stop();
build();
install();
up(profiles: ['default']); // We can't start worker now, they are not installed
migrate();
// workers_start();
notify('The stack is now up and running.');
io()->success('The stack is now up and running.');
about();
}
#[AsTask(description: 'Installs the application (composer, ...)', namespace: 'app', aliases: ['install'])]
function install(): void
{
io()->title('Installing the application');
$basePath = variable('root_dir');
if (is_file("{$basePath}/composer.json")) {
io()->section('Installing PHP dependencies');
docker_compose_run(['composer', 'install', '-n', '--prefer-dist', '--optimize-autoloader']);
}
if (is_file("{$basePath}/importmap.php")) {
io()->section('Installing importmap');
docker_compose_run(['bin/console', 'importmap:install']);
}
qa\install();
}
#[AsTask(description: 'Update dependencies')]
function update(bool $withTools = false): void
{
io()->title('Updating dependencies...');
docker_compose_run(['composer', 'update', '-o']);
if ($withTools) {
qa\update();
}
}
#[AsTask(description: 'Clears the application cache', namespace: 'app', aliases: ['cache-clear'])]
function cache_clear(bool $warm = true): void
{
io()->title('Clearing the application cache');
docker_compose_run(['rm', '-rf', 'var/cache/']);
if ($warm) {
cache_warmup();
}
}
#[AsTask(description: 'Warms the application cache', namespace: 'app', aliases: ['cache-warmup'])]
function cache_warmup(): void
{
io()->title('Warming the application cache');
docker_compose_run(['bin/console', 'cache:warmup'], c: context()->withAllowFailure());
}
#[AsTask(description: 'Migrates database schema', namespace: 'app:db', aliases: ['migrate'])]
function migrate(): void
{
io()->title('Migrating the database schema');
docker_compose_run(['bin/console', 'doctrine:database:create', '--if-not-exists']);
docker_compose_run(['bin/console', 'doctrine:migration:migrate', '-n', '--allow-no-migration', '--all-or-nothing']);
}
#[AsTask(description: 'Loads fixtures', namespace: 'app:db', aliases: ['fixtures'])]
function fixtures(): void
{
io()->title('Loads fixtures');
// Uncomment one of them...
// docker_compose_run(['bin/console', 'doctrine:fixture:load', '-n']);
// docker_compose_run(['bin/console', 'foundry:load-fixtures', '-n']);
// docker_compose_run(['bin/console', 'sylius:fixture:load', '-n']);
}