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

Fix compatibility layer with castor v0.11.0 #263

Merged
merged 1 commit into from
Jan 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .castor/infra.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use function Castor\capture;
use function Castor\finder;
use function Castor\fs;
use function Castor\get_context;
use function Castor\context;
use function Castor\io;
use function Castor\run;
use function Castor\variable;
Expand Down Expand Up @@ -53,7 +53,7 @@ function stop(): void
#[AsTask(description: 'Opens a shell (bash) into a builder container', aliases: ['builder'])]
function builder(): void
{
$c = get_context()
$c = context()
->withTimeout(null)
->withTty()
->withEnvironment($_ENV + $_SERVER)
Expand All @@ -66,7 +66,7 @@ function builder(): void
#[AsTask(description: 'Displays infrastructure logs', aliases: ['logs'])]
function logs(): void
{
docker_compose(['logs', '-f', '--tail', '150'], c: get_context()->withTty());
docker_compose(['logs', '-f', '--tail', '150'], c: context()->withTty());
}

#[AsTask(description: 'Lists containers status', aliases: ['ps'])]
Expand Down
16 changes: 10 additions & 6 deletions .castor/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use function Castor\cache;
use function Castor\capture;
use function Castor\get_context;
use function Castor\context;
use function Castor\io;
use function Castor\log;
use function Castor\run;
Expand Down Expand Up @@ -70,8 +70,12 @@ function create_default_context(): Context
$data['docker_compose_files'][] = 'docker-compose.override.yml';
}

$data['composer_cache_dir'] = cache('composer_cache_dir', function () {
$composerCacheDir = capture(['composer', 'global', 'config', 'cache-dir', '-q'], onFailure: '');
// We need an empty context to run command, since the default context has
// not been set in castor, since we ARE creating it right now
$emptyContext = new Context();

$data['composer_cache_dir'] = cache('composer_cache_dir', function () use ($emptyContext): string {
$composerCacheDir = capture(['composer', 'global', 'config', 'cache-dir', '-q'], onFailure: '', context: $emptyContext);
// If PHP is broken, the output will not be a valid path but an error message
if (!is_dir($composerCacheDir)) {
$composerCacheDir = sys_get_temp_dir() . '/castor/composer';
Expand Down Expand Up @@ -109,7 +113,7 @@ function docker_exit_code(
string $workDir = null,
bool $withBuilder = true,
): int {
$c = ($c ?? get_context())->withAllowFailure();
$c = ($c ?? context())->withAllowFailure();

$process = docker_compose_run(
runCommand: $runCommand,
Expand Down Expand Up @@ -163,7 +167,7 @@ function docker_compose_run(
*/
function docker_compose(array $subCommand, Context $c = null, bool $withBuilder = false): Process
{
$c ??= get_context();
$c ??= context();

$domains = [variable('root_domain'), ...variable('extra_domains')];
$domains = '`' . implode('`) || Host(`', $domains) . '`';
Expand Down Expand Up @@ -204,7 +208,7 @@ function docker_compose(array $subCommand, Context $c = null, bool $withBuilder
// so this func allow them to run these tools on their host
function run_in_docker_or_locally_for_mac(string $command, Context $c = null): void
{
$c ??= get_context();
$c ??= context();

if (variable('macos')) {
run($command, context: $c->withPath(variable('root_dir')));
Expand Down