theod02/castor-docker
Composer 安装命令:
composer require theod02/castor-docker
包简介
Set of classes for using docker
README 文档
README
This repository contains a set of classes for interacting with Docker containers in PHP trough Castor.
Description
Classes and helpers provide you an API to interact with Docker containers in PHP.
Classes reflect the Docker CLI commands.
Some helper like docker()->utils()->isRunningInsideContainer() can be used to detect if the PHP script is running
inside a Docker container.
Usage
import('composer://theod02/castor-class-task'); // context() can be provided to docker() to use a specific context (is not a required argument) docker(context())->compose()->exec( service: 'my-service', args: ['ls', '-la'], user: 'www-data', workdir: '/var/www/html', );
This repository provide a RunnerTrait that can be used to run commands automatically in a Docker container from host
or from a Docker container directly.
Example classe for running composer commands :
class Composer { use RunnerTrait { __construct as private __runnerTraitConstruct; } public function __construct( private readonly Context $context, ?string $workingDirectory = null ) { $this->addIf($workingDirectory, '--working-dir', $workingDirectory); $this->__runnerTraitConstruct($context); } protected function getBaseCommand(): string { return 'composer'; } protected function allowRunningUsingDocker(): bool { return true; } public function createProject(string $name, string $path): Process { $this->add('create-project', $name, $path); return $this->runCommand(); } public function install(): Process { return $this->add('install')->runCommand(); } public function require(string|array $packages, bool $dev = false, bool $withDependencies = false): Process { $packages = is_string($packages) ? [$packages] : $packages; $this->addIf($dev, '--dev'); $this->addIf($withDependencies, '--with-dependencies'); return $this->add('require', ...$packages)->runCommand(); } public function update( string|array|null $packages = null, bool $dev = false, bool $withDependencies = false ): Process { $packages = is_string($packages) ? [$packages] : ($packages ?? []); $this->addIf($dev, '--dev'); $this->addIf($withDependencies, '--with-all-dependencies'); return $this->add('update', ...$packages)->runCommand(); } } function composer(?Context $context = null, ?string $workingDirectory = null): Composer { return new Composer(context: $context ?? context(), workingDirectory: $workingDirectory); } // Usage composer()->install(); composer()->require('symfony/console', dev: true);
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-04-06