afterflow / chisel
工作中
Requires
- symfony/process: 4.*|5.*
- symfony/yaml: 4.*|5.*
Requires (Dev)
- phpunit/phpunit: 8.*
- squizlabs/php_codesniffer: ^3.5
Suggests
- ext-pcntl: *
README
工作中。这意味着API可能会随时更改。
Afterflow Chisel
Chisel是一个轻量级、可扩展的PHP编写的docker-compose包装器。
需求
Laravel、Docker和docker-compose。
安装
获取Laravel的新安装版本
laravel new chisel-project
使用composer安装Chisel
composer require afterflow/chisel
然后运行
php artisan chisel:up
完成!您有一个Caddy Web服务器在 https://,phpMyAdmin在 https://:8080。
MySQL、队列工作者和带有cron的工作空间在后台运行。
Chisel与Vessel
Chris Fidao的Vessel是一个围绕docker-compose的小巧包装器。它用bash编写,不需要在本地机器上安装php。
通过编辑docker-compose文件扩展基本容器。
Chisel使用PHP类定义其服务(仍然在底层依赖docker-compose)。在Chisel中,项目配置定义在docker/docker.php
中。您可以轻松扩展或重新配置服务,现在您还可以将一些Chisel服务类与您的composer包一起打包,或在使用项目脚手架时重用它们。
Chisel与Laradock
Laradock是一个包含Laravel所有用途的Docker镜像的全透明集合。实际上,Chisel使用其中的一些开发,但方式略有不同。
由于Laradock镜像的特性,构建时间可能非常大,您需要构建和发布中间镜像才能与多个项目/服务器一起使用。此外,配置Laradock可能会有些令人不知所措。相反,您可以使用Laradock构建一个镜像,然后使用Chisel使用它。
Chisel与Laravel Valet
Mac上的Docker使用慢速虚拟化,因此,本机服务器软件比docker化版本运行得更快。因此,您可能会更喜欢使用Valet进行Web堆栈。尽管如此,Chisel仍然非常有帮助。例如,您可以使用Chisel运行Browserless或Redis或Kibana,而其他一切都可以使用Valet或本机。
Chisel与Laravel Homestead
理想情况下,在所有情况下都应使用Chisel代替Homestead。Chisel的目标是提供与Homestead相同级别的便利性,但具有生产就绪的Docker环境和更好的可扩展性。
Chisel与docker-compose
目前,Chisel在底层使用docker-compose,提供了另一层抽象,使compose可通过PHP进行配置,因此,可通过Composer包进行扩展。
使用Chisel代替Compose可以在多个项目上使用时简化脚手架并加快速度,因为您只需使用composer require
即可获取您所需的一切,无需捆绑compose文件并将它们复制粘贴到新项目中。
基本用法示例
尝试从您的宿主机器迁移数据库
php artisan migrate
相同,但来自docker化工作空间内部
php artisan chisel exec workspace migrate
注意它如何仅使用单个默认.env
文件,从宿主机器和容器中无缝与MySQL协同工作。
从工作空间容器编译前端资源
php artisan chisel:workspace npm install npm run dev
查看MySQL日志
php artisan chisel:logs mysql
在容器上执行任意命令
php artisan chisel:exec caddy sh
执行快捷命令
php artisan chisel:exec mysql @dump
配置
运行以下命令以发布一切
php artisan chisel:install
这将创建项目根目录中的docker
目录。
docker/docker.php
<?php use Afterflow\Chisel\Docker\Services\Caddy\Caddy; use Afterflow\Chisel\Docker\Services\MySQL\MySQL; use Afterflow\Chisel\Docker\Services\PhpFpm\PhpFpm; use Afterflow\Chisel\Docker\Services\PhpMyAdmin\PhpMyAdmin; use Afterflow\Chisel\Docker\Services\Worker\Worker; /* |---------------------------------------------------------------------------- | Docker Networks |---------------------------------------------------------------------------- | | Docker networks are good way to separate access to your services. Each | network has it's own containers. Containers can only "see" other containers | from their own network. You can add container to multiple networks though. | */ Docker::network( 'frontend' ); Docker::network( 'backend' ); /* |---------------------------------------------------------------------------- | Workspace Container |---------------------------------------------------------------------------- | | There is a special "workspace" container stuffed with developer tools like | bash, fish, node, npm, mysql-client and much more, so that you can use all | of them without installing them to your local system. This service is also | responsible for running scheduled tasks. Get a workspace bash shell: | | php artisan chisel:workspace | */ Docker::workspace()->networks( [ 'frontend', 'backend' ] ); /* |---------------------------------------------------------------------------- | Docker Services |---------------------------------------------------------------------------- | | This section describes local, production and common containers of your | application. You can add arbitrary Docker containers or override the | defaults. Use php artisan chisel:publish to tweak these services. | */ // Web Server with automatic HTTPS Docker::service( 'caddy', Caddy::class ); // PHP-FPM backend for the web server Docker::service( 'php-fpm', PhpFpm::class ); // MySQL Database Docker::service( 'mysql', MySQL::class )->networks( [ 'backend' ] ); // MySQL Administration Tool Docker::service( 'phpmyadmin', PhpMyAdmin::class ); // Queue worker service. Docker::service( 'worker', Worker::class )->restart( 'always' ); /* |---------------------------------------------------------------------------- | Pre-Built Chisel Services Collection |---------------------------------------------------------------------------- | | Here you can find a collection of pre-configured drop-in examples for more | Docker services. You can comment them out and everything should work out of | the box. With new versions of Chisel, this section will probably get more | and more examples. Contributions are welcome! | */ // Docker::image( 'browserless', 'browserless/chrome' ) // ->networks( [ 'frontend', 'backend' ] ) // ->ports( [ 3000 => 3000 ] ); /* |---------------------------------------------------------------------------- | Environment Specific Configuration Example |---------------------------------------------------------------------------- | | Here you can define some local-only services like mailtrap, selenium, etc. | or define the same services with different volumes and so on... | */ if ( app()->environment( 'local' ) ) { // Local services } else { // Other services }
测试
composer test
许可证
MIT许可证(MIT)。