Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more debug logs #282

Merged
merged 1 commit into from Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 23 additions & 3 deletions .castor/docker.php
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']);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really boring, when you have a builder running, and starting something

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