-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathcastor.php
More file actions
139 lines (111 loc) · 4.01 KB
/
castor.php
File metadata and controls
139 lines (111 loc) · 4.01 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
use Castor\Attribute\AsTask;
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('0.26.0');
import(__DIR__ . '/.castor');
/**
* @return array{project_name: string, root_domain: string, extra_domains: string[], php_version: string}
*/
function create_default_variables(): array
{
$projectName = 'app';
$tld = 'test';
return [
'project_name' => $projectName,
'root_domain' => "{$projectName}.{$tld}",
'extra_domains' => [
"www.{$projectName}.{$tld}",
],
// In order to test docker stater, we need a way to pass different values.
// You should remove the `$_SERVER` and hardcode your configuration.
'php_version' => $_SERVER['DS_PHP_VERSION'] ?? '8.5',
'registry' => $_SERVER['DS_REGISTRY'] ?? null,
];
}
#[AsTask(description: 'Builds and starts the infrastructure, then install the application (composer, yarn, ...)')]
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, yarn, ...)', namespace: 'app', aliases: ['install'])]
function install(): void
{
io()->title('Installing the application');
$basePath = sprintf('%s/application', 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}/yarn.lock")) {
io()->section('Installing Node.js dependencies');
docker_compose_run('yarn install --frozen-lockfile');
} elseif (is_file("{$basePath}/package.json")) {
io()->section('Installing Node.js dependencies');
if (is_file("{$basePath}/package-lock.json")) {
docker_compose_run('npm ci');
} else {
docker_compose_run('npm install');
}
}
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');
// docker_compose_run('bin/console doctrine:fixture:load -n');
}