Skip to content

Commit

Permalink
Merge pull request #282 from jolicode/more-log
Browse files Browse the repository at this point in the history
Add more debug logs
  • Loading branch information
lyrixx committed Feb 26, 2024
2 parents bde300b + 29342db commit fed9df7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
26 changes: 23 additions & 3 deletions .castor/docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#[AsTask(description: 'Displays some help and available urls for the current project', namespace: '')]
function about(): void
{
io()->section('About this project');
io()->title('About this project');

io()->comment('Run <comment>castor</comment> to display all available commands.');
io()->comment('Run <comment>castor about</comment> to display this project help.');
Expand Down Expand Up @@ -53,9 +53,17 @@ function about(): void
io()->listing(array_map(fn ($url) => "https://{$url}", $urls));
}

#[AsTask(description: 'Opens the project in your browser', namespace: '')]
function open(): void
{
run(['open', 'https://' . variable('root_domain')], quiet: true);
}

#[AsTask(description: 'Builds the infrastructure', aliases: ['build'])]
function build(): void
{
io()->title('Building infrastructure');

$userId = variable('user_id');
$phpVersion = variable('php_version');

Expand All @@ -71,8 +79,10 @@ function build(): void
#[AsTask(description: 'Builds and starts the infrastructure', aliases: ['up'])]
function up(): void
{
io()->title('Starting infrastructure');

try {
docker_compose(['up', '--remove-orphans', '--detach', '--no-build']);
docker_compose(['up', '--detach', '--no-build']);
} catch (ExceptionInterface $e) {
io()->error('An error occured while starting the infrastructure.');
io()->note('Did you forget to run "castor docker:build"?');
Expand All @@ -85,6 +95,8 @@ function up(): void
#[AsTask(description: 'Stops the infrastructure', aliases: ['stop'])]
function stop(): void
{
io()->title('Stopping infrastructure');

docker_compose(['stop']);
}

Expand Down Expand Up @@ -117,6 +129,8 @@ function destroy(
#[AsOption(description: 'Force the destruction without confirmation', shortcut: 'f')]
bool $force = false,
): void {
io()->title('Destroying infrastructure');

if (!$force) {
io()->warning('This will permanently remove all containers, volumes, networks... created for this project.');
io()->note('You can use the --force option to avoid this confirmation.');
Expand All @@ -136,7 +150,7 @@ function destroy(
fs()->remove($files);
}

#[AsTask(description: 'Generates SSL certificates (with mkcert if available or self-signed if not)')]
#[AsTask(description: 'Generates SSL certificates (with mkcert if available or self-signed if not)', namespace: '')]
function generate_certificates(
#[AsOption(description: 'Force the certificates re-generation without confirmation', shortcut: 'f')]
bool $force = false,
Expand All @@ -150,6 +164,8 @@ function generate_certificates(
return;
}

io()->title('Generating SSL certificates');

if ($force) {
if (file_exists($f = "{$sslDir}/cert.pem")) {
io()->comment('Removing existing certificates in infrastructure/docker/services/router/certs/*.pem.');
Expand Down Expand Up @@ -206,6 +222,8 @@ function generate_certificates(
#[AsTask(description: 'Starts the workers', namespace: 'docker:worker', name: 'start', aliases: ['start-workers'])]
function workers_start(): void
{
io()->title('Starting workers');

$workers = get_workers();

if (!$workers) {
Expand All @@ -229,6 +247,8 @@ function workers_start(): void
#[AsTask(description: 'Stops the workers', namespace: 'docker:worker', name: 'stop', aliases: ['stop-workers'])]
function workers_stop(): void
{
io()->title('Stopping workers');

$workers = get_workers();

if (!$workers) {
Expand Down
12 changes: 11 additions & 1 deletion .castor/qa.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Castor\Attribute\AsTask;

use function Castor\io;
use function docker\docker_compose_run;
use function docker\docker_exit_code;

Expand All @@ -13,17 +14,26 @@ function all(): int
install();
$cs = cs();
$phpstan = phpstan();
// $phpunit = phpunit();

return max($cs, $phpstan);
return max($cs, $phpstan/*, $phpunit*/);
}

#[AsTask(description: 'Installs tooling')]
function install(): void
{
io()->title('Installing QA tooling');

docker_compose_run('composer install -o', workDir: '/var/www/tools/php-cs-fixer');
docker_compose_run('composer install -o', workDir: '/var/www/tools/phpstan');
}

// #[AsTask(description: 'Runs PHPUnit', aliases: ['phpunit'])]
// function phpunit(): int
// {
// return docker_exit_code('phpunit');
// }

#[AsTask(description: 'Runs PHPStan', aliases: ['phpstan'])]
function phpstan(): int
{
Expand Down
12 changes: 12 additions & 0 deletions castor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ function create_default_variables(): array
#[AsTask(description: 'Builds and starts the infrastructure, then install the application (composer, yarn, ...)')]
function start(): void
{
io()->title('Starting the stack');

workers_stop();
generate_certificates(force: false);
build();
Expand All @@ -55,17 +57,23 @@ function start(): void
#[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');
docker_compose_run('npm ci');
}
if (is_file("{$basePath}/importmap.php")) {
io()->section('Installing importmap');
docker_compose_run('bin/console importmap:install');
}

Expand All @@ -75,12 +83,16 @@ function install(): void
#[AsTask(description: 'Clear the application cache', namespace: 'app', aliases: ['cache-clear'])]
function cache_clear(): void
{
// io()->title('Clearing the application cache');

// docker_compose_run('rm -rf var/cache/ && bin/console cache:warmup');
}

#[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');
}

0 comments on commit fed9df7

Please sign in to comment.