axy/docker-compose-config
Composer 安装命令:
composer require axy/docker-compose-config
包简介
Work with docker-compose config
README 文档
README
Work with docker-compose config.
The library don't create and load any files, don't parse and build Yml. Regular PHP arrays are used for input and output.
ComposeConfig
ComposeConfig is main class of the library.
You can create an empty config or load an existing.
use axy\docker\compose\config\ComposeConfig; // data loading is a matter of external code $data = Yaml::parse(file_get_contents('docker-compose.yml')); $config = new ComposeConfig($data); // manipulation $service = $config->services->create('php'); $service->build->context = './build'; // ... // data saving is a matter of external code $data = $config->getData(); $yaml = Yaml::dump($data, 5); file_put_contents('docker-compose.yml', $yaml);
The constructor new ComposeConfig() without argument creates an empty config.
Validation
The library doesn't strictly validate on load. If a field has wrong format it will be converted to correct value or ignored.
Structures
A class of a config component has its own set of properties that correspond to the fields of that component.
For example, ComposeConfig has properties $version, $services, $volumes, $network.
For simple fields are created simple properties.
Nullable strings (such $version) or arrays.
Complex field correspond to object of the specific class.
For example, $config->services is container of service objects.
All structures are initialized on load even if they are not specified in the source file.
For example, you can work with $service->build as with an object even if build section is not specified for this service or specified as string.
It is just that all fields of $service->build will be empty and this field will not be put to result unless you change it.
Usually fields with NULL, empty strings or empty values are not put to the result. Objects themselves decide this issue.
additional
Some classes have public array additional.
All fields that don't correspond to other property fall to there.
version: "3.8" services: www: image: nginx foo: bar bar: foo
version and services are standard fields but foo and bar will be added to additional.
All addition fields will be added to result as is.
TDisable
Trait TDisable define follow methods:
isEnabled(): booldisable(): voidenable(): void
Objects with this trait can be disabled:
$config->services['db']->disable(); // disable service "db"
Disabled components will be removed from result config.
Disabled object stores all its data and will be restored after enable().
$config->services
List of services.
Implements ArrayAccess.
$php = $config->services->create('php'); // create empty service php $www = $config->services->create('www', ['image' => 'nginx']); // create service based on loaded config $config->services['php']->build->context = './build'; // get service by name $config->services->disableService('db'); // disable services if it exists $config->services->clear(); // clear the service list
Service object
ComposeService instance contains follow properties:
- ?string
$image - ?string
$container_name - ?string
$restart - BuildSection
$build - PortsSection
$ports - ExposeSection
$expose - EnvironmentSection
$environment - LabelsSection
$labels - ?string
$network_mode - ServiceNetworksSection
$networks - DependsOnSection
$depends_on - array
$additional
Keys
Some sections like ports, expose and volumes (inside a service) are just a list of unnamed values.
Three are methods for search like $volumes->findBySource().
Can also use "keys" and "groups".
You can bind a value with a key (an arbitrary string) or add it to a group. Keys and groups will be not represented in yml file, but you can use for config manipulations.
// Base template $service->volumes->add('./app:/var/www/app'); // bind volume without key $service->volumes->add('./log:/var/log/nginx', 'nginx_log'); // with key "nginx_log" // ... // I want disable mount nginx log $service->volumes->getByKey('nginx_log')->disable();
axy/docker-compose-config 适用场景与选型建议
axy/docker-compose-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 363 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 06 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 axy/docker-compose-config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 axy/docker-compose-config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 363
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-06-16