inquid/yii-cd-ci
Composer 安装命令:
composer require inquid/yii-cd-ci
包简介
Tools for Yii to use Continuous Delivery and Continuous Integration
README 文档
README
Yii tools for CI / CD
This extension allows automatic project updating in case its source code is maintained via version control system, such as GIT. Such update includes following steps:
- check if there are any changes at VSC remote repository
- link web server web directories to the stubs, while project update is running
- apply remote VCS changes
- update 'vendor' directory via Composer
- clear application cache and temporary directories
- perform additional actions, like applying database migrations
- link web server web directories to the project web directories, once update is complete
- notify developer(s) about update result via email, SMS, calls, Telegram and Slack
For license information check the LICENSE-file.
Requirements
This extension requires Linux OS.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist inquid/yii-cd-ci
or add
"inquid/yii-cd-ci": "*"
to the require section of your composer.json.
Usage
This extension provides special console controller [[inquid\yii-cd-ci\SelfUpdateController]], which allows automatic updating of
the project, if its source code is maintained via version control system.
In order to enable this controller in your project, you should add it to your console application controllerMap at
configuration file:
return [ 'controllerMap' => [ 'self-update' => 'inquid\yii-cd-ci\SelfUpdateController' ], // ... ];
Now you should able to use 'self-update' command via console:
yii self-update
Project preparation
In order to use 'self-update' command, you should perform several preparations in your project, allowing certain shell commands to be executed in non-interactive (without user prompt) mode.
First of all, you should clone (checkout) your project from version control system and switch project working copy to the branch, which should be used at this particular server. Using GIT this actions can be performed via following commands:
cd /path/to/my/project
git clone git@my-git-server.com/myproject.git
git checkout production
Attention: you need to configure your VCS (or at least your project working copy) in the way interacting with remote repository does NOT require user prompt, like input of username or password! This can be achieved using authentication keys or 'remember password' feature.
Then you should make project operational performing all necessary actions for its initial deployment, like running 'composer install', creating necessary directories and so on.
Using self-update command
Once project is setup you need to create a configuration for its updating. This can be done using 'self-update/config' command:
yii self-update/config @app/config/self-update.php
This will generate configuration file, which should be manually adjusted depending on the particular project structure and server environment. For the common project such configuration file may look like following:
<?php return [ // list of email addresses, which should be used to send execution reports 'emails' => [ 'developer@domain.com', ], // Mailer component to be used 'mailer' => 'mailer', // Mutex component to be used 'mutex' => 'mutex', // path to project root directory (VCS root directory) 'projectRootPath' => '@app', // web path stubs configuration 'webPaths' => [ [ 'path' => '@app/web', 'link' => '@app/httpdocs', 'stub' => '@app/webstub', ], ], // cache components to be flushed 'cache' => [ 'cache' ], // temporary directories, which should be cleared after project update 'tmpDirectories' => [ '@app/web/assets', '@runtime/URI', '@runtime/HTML', '@runtime/debug', ], // list of shell commands, which should be executed after project update 'afterUpdateCommands' => [ 'php ' . escapeshellarg($_SERVER['SCRIPT_FILENAME']) . ' migrate/up --interactive=0', ], ];
Please refer to [[\inquid\yii-cd-ci\SelfUpdateController]] for particular option information.
Once you have made all necessary adjustments at configuration file, you can run 'self-update/perform' command with it:
yii self-update @app/config/self-update.php
You may setup default configuration file name inside the controllerMap specification via [[inquid\yii-cd-ci\SelfUpdateController::$configFile]]:
return [ 'controllerMap' => [ 'self-update' => [ 'class' => 'inquid\yii-cd-ci\SelfUpdateController', 'configFile' => '@app/config/self-update.php', ] ], // ... ];
Then invocation of the self-update command will be much more clear:
yii self-update
Note: it is not necessary to create a separated configuration file: you can configure all necessary fields of [[inquid\yii-cd-ci\SelfUpdateController]] inside
controllerMapspecification, but such approach is not recommended.
Self Update Workflow
While running, [[inquid\yii-cd-ci\SelfUpdateController]] performs following steps:
- check if there are any changes at VSC remote repository
- link web server web directories to the stubs, while project update is running
- apply remote VCS changes
- update 'vendor' directory via Composer
- clear application cache and temporary directories
- perform additional actions, like applying database migrations
- link web server web directories to the project web directories, once update is complete
- notify developer(s) about update result via email
At the first stage there is a check for any changes in the remote repository. If there is no changes in remote repository for the current project VCS working copy branch, no further actions will be performed!
If remote changes detected, the symbolic links pointing to the project '@web' directory will be switched to another directory, which should contain a 'stub' - some static HTML page, which says something like 'Application is under the maintenance, please check again later'. Although, usage of such stub it is up to you, it is recommended, because actual project update may take significant time before being complete. Project web directory will be linked back instead of stub, only after all update actions are performed.
During update itself VCS remote changes are applied, vendor directory is updated via Composer, specified temporary
directories will be cleared and cache flushed.
Note: in order for Composer be able to apply necessary changes, the 'composer.lock' file should be tracked by version control system!
inquid/yii-cd-ci 适用场景与选型建议
inquid/yii-cd-ci 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 05 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「git」 「update」 「mercurial」 「deployment」 「vcs」 「integration」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 inquid/yii-cd-ci 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 inquid/yii-cd-ci 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 inquid/yii-cd-ci 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Checks if any composer packages needs to be updated.
Easily manage git hooks in your composer config
Tools for releasing library packages; supports Git, Mercurial, Github, Gitlab, and Bitbucket.
MediaWiki extension that allows embedding external content, specified by URL, into your wiki pages
Simple wrapper to log command for git/hg/svn
Nagios plugin to verify a git repository.
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2019-05-02