Skip to content

Commit

Permalink
fix: swoole binary and local exec
Browse files Browse the repository at this point in the history
  • Loading branch information
praswicaksono committed Nov 17, 2024
1 parent 0c059d6 commit d07bab5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 28 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/mager-build-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- "macos-x86_64"
- "macos-aarch64"
php-version:
- "8.3.12"
- "8.3"
runner:
- "ubuntu-latest"
steps:
Expand Down Expand Up @@ -72,8 +72,7 @@ jobs:
- name: Download Micro With ${{ matrix.php-version }}-${{ matrix.arch }}
run: |
mkdir downloads
wget https://dl.static-php.dev/static-php-cli/bulk/php-${{ matrix.php-version }}-micro-${{ matrix.arch }}.tar.gz -O downloads/php-${{ matrix.php-version }}-${{ matrix.arch }}.tar.gz
tar -xvzf downloads/php-${{ matrix.php-version }}-${{ matrix.arch }}.tar.gz --directory downloads
wget https://dl.praswicaksono.pw/php-${{ matrix.php-version }}-minimal-${{ matrix.arch }}.sfx -O downloads/micro.sfx
- name: "Install Dependencies"
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
Expand Down
18 changes: 5 additions & 13 deletions bin/mager
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,23 @@
use App\Kernel;
use App\ConsoleApplication;
use Swoole\ExitException;
use Swoole\Runtime;

if (!is_dir(dirname(__DIR__).'/vendor')) {
throw new LogicException('Dependencies are missing. Try running "composer install".');
}

require dirname(__DIR__).'/vendor/autoload.php';
Runtime::setHookFlags(SWOOLE_HOOK_ALL & ~SWOOLE_HOOK_FILE);

//if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
// throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
//}
//
//require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
$loader = require dirname(__DIR__).'/vendor/autoload.php';

$app = function (array $context) {
if (\PHP_SAPI === 'micro') {
$context['APP_ENV'] = 'prod';
$context['APP_DEBUG'] = false;
}

$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

$app = new ConsoleApplication($kernel);

$app->setName('Mager Deploy');
$app->setVersion('v0.0.8');
$app->setVersion('v0.0.9');

return $app;
};
Expand All @@ -46,7 +38,7 @@ $app = $app(...$args);

$exitCode = 0;

\Co\run(function () use (&$exitCode, $app, $runtime) {
\Co\run(function () use (&$exitCode, $app, $runtime, $loader) {
try {
$runtime->getRunner($app)->run();
} catch (ExitException $e) {
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"friendsofphp/php-cs-fixer": "^3.64",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^9.5",
"swoole/ide-helper": "^5.0.0",
"swoole/ide-helper": "~5.0.0",
"symfony/browser-kit": "7.1.*",
"symfony/css-selector": "7.1.*",
"symfony/maker-bundle": "^1.61",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions src/Command/ExecCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,18 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$namespace = $input->getArgument('namespace');
$serviceName = $input->getArgument('serviceName');
$command = implode(' ', $input->getArgument('cmd'));

if ($this->config->isLocal($namespace)) {
$result = runLocally(function () use ($namespace, $command) {
runLocally(function () use ($namespace, $serviceName, $command) {
$cmd = <<<CMD
docker exec -ti `docker ps -a --filter name={$namespace}-{$namespace} --format '{{ .ID}}'` {$command}
docker exec -ti `docker ps -a --filter name={$namespace}-{$serviceName} --format '{{ .ID}}' | head -n1` {$command}
CMD;

return yield $cmd;
}, tty: true);
$io->writeln($result);

return Command::SUCCESS;
}
Expand Down

0 comments on commit d07bab5

Please sign in to comment.