mirror of https://github.com/hauke68/Magallanes
Claudio Zizza
10 years ago
27 changed files with 904 additions and 110 deletions
@ -0,0 +1,123 @@ |
|||||||
|
Contributor guidelines for Magallanes |
||||||
|
===================================== |
||||||
|
Welcome to Magallanes! We are much appreciated you've decided to contribute to this project! |
||||||
|
Please read the following guidelines to make your and our work easier and cleaner. |
||||||
|
|
||||||
|
**TL;DR** |
||||||
|
|
||||||
|
1. Write clean code with no mess left |
||||||
|
2. Contribute the docs when adding configurable new feature |
||||||
|
3. Create your pull request from `develop` branch |
||||||
|
4. Ensure your code is fully covered by tests |
||||||
|
|
||||||
|
|
||||||
|
---------- |
||||||
|
|
||||||
|
# Reporting issues |
||||||
|
If you have a problem or you've noticed some bug, please feel free to open new issue. However please follow the rules below: |
||||||
|
* First, make sure that similar/the same issue doesn't already exist |
||||||
|
* If you've already found the solution of the problem you are about to report, please feel free to open a new pull request. Then follow the rules below in **Developing Magallanes** section. |
||||||
|
* If you are able to, include some test cases or steps to reproduce the bug for us to examine the problem to reach the problem origin. |
||||||
|
|
||||||
|
## Opening pull requests |
||||||
|
Pull Request are actually some kind of issues with code, so please follow the rules above in **Reporting issues** section before making the pull requests. |
||||||
|
Our code isn't so beautiful, tested and testable as we would like it to be but if you're pushing your code please be sure it meets the requirements from **Organization and code quality** chapter. We want to improve the existing code to facilitate extending it and making fixes quicker. So if you are editing some class and you find it ugly, please do not ignore it. Following [The Boy Scout Rule](http://www.informit.com/articles/article.aspx?p=1235624&seqNum=6) - *Leave the campground cleaner than you found it* - we all can improve the existing code. |
||||||
|
Keep your git commits as atomic as possible. It brings better history description only by commit messages and allow us to eventually revert the single commits with no affects. Your commit messages should be also descriptive. The first line of commit should be short, try to limit it up to 50 characters. The messages should be written imperatively, like following: |
||||||
|
``` |
||||||
|
Add MyCustomTask |
||||||
|
``` |
||||||
|
If you need to write more about your tasks, please enter the description in the next lines. There you can write whatever you want, like why you made this commit and what it consists of. |
||||||
|
``` |
||||||
|
Add MyCustomTask |
||||||
|
|
||||||
|
This task has very important role for the project. I found this very useful for all developers. I think the deploy with it should be a lot easier. |
||||||
|
``` |
||||||
|
|
||||||
|
Optionally you can tag your messages in square brackets. It can be issue number or simple flag. Examples: |
||||||
|
``` |
||||||
|
[#183] Add new CONTRIBUTING document |
||||||
|
[FIX] Set correct permissions on deploy stage |
||||||
|
[FEATURE] Create new PermissionsTask |
||||||
|
``` |
||||||
|
Remember of square brackets when adding issue number. If you'd forget adding them, your whole message will be a comment! |
||||||
|
|
||||||
|
## Contributing the documentation |
||||||
|
Magallanes is made to deploy your application quick and with no need to write redudant code. Usage is as simple as writing the configuration for target project in YAML files. In the nearest future we would like to make some Wiki with all available options, tasks and commands. For now, the only "documentation" are example files in `docs` directory. If the code you are going to include in your pull requests adds or changes config options, please make sure that you create a new sample in those files. You should also do the same with commands. |
||||||
|
|
||||||
|
# Developing Magallanes |
||||||
|
## Branches |
||||||
|
The flow is pretty simple. |
||||||
|
In most common cases we work on `develop` branch. It's a branch with the newest changes which sometimes need more testing. All pull requests are opened to be merged into that branch. That keeps us safe to not deploy unsafe code into production - `master` branch. When we decide that every changeset in `develop` is tested manually and works as it's intented, we merge it to master. |
||||||
|
If the change you commited is pretty hot and needs to be released ASAP, you are allowed to make a pull request to `master` branch. But it's the only case, please try to avoid it. All pull request that are not made on `develop` will be rejected. |
||||||
|
If you want to use develop branch in your code, simple pass `dev-develop` to dependency version in your `composer.json` file: |
||||||
|
```json |
||||||
|
{ |
||||||
|
"require": { |
||||||
|
"andres-montanez/magallanes": "dev-develop" |
||||||
|
} |
||||||
|
} |
||||||
|
``` |
||||||
|
## Organization and code quality |
||||||
|
We use [PSR2](http://www.php-fig.org/psr/psr-2/) as PHP coding standard. |
||||||
|
Some of the rules we follow that are not included in document above: |
||||||
|
|
||||||
|
* Variables' and properties' names are camelCased (e.g.: `$thisIsMyVariable`) |
||||||
|
* Avoid too long or too short variables' and methods' names, like `$thisIsMyAwesomeVariableAndImProudOfIt` |
||||||
|
* Names of your properties/methods should be intuitive and self-describing - that means your code should look like a book. Developers who read the code should immediately know what a variable includes or what a method does. |
||||||
|
* Let your methods will be verbs. For boolean methods, prefix it with `is`, `has`, and so on. E.g.: `isConfigurable`, `hasChildren`. |
||||||
|
* Be [SOLID](http://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29) and follow [KISS](http://en.wikipedia.org/wiki/KISS_principle) - let the class be responsible only for its tasks. |
||||||
|
* Write testable code and if there's a need - easy extendible. |
||||||
|
* Avoid duplications |
||||||
|
|
||||||
|
The rules above have been set a long time after the project has started. If you notice some violations, please open a new issue or even pull request with fixes. It'll be much appreciated. |
||||||
|
|
||||||
|
### Tools you can use to ensure your code quality |
||||||
|
|
||||||
|
1. **PHP-CodeSniffer** |
||||||
|
2. **PHP Mess Detector** |
||||||
|
3. PHP Copy/Paste Detector |
||||||
|
4. PHP Dead Code Detector |
||||||
|
5. [PHP Coding Standards Fixer](http://cs.sensiolabs.org) |
||||||
|
|
||||||
|
## Testing and quality |
||||||
|
We use PHPUnit to test our code. The whole project is not covered with tests right now but we've been working on it for some time. If you want your code to be merged into Magallanes, we want you to push it with proper tests. We would love to reach and keep at least 90% of line code coverage. In short time we want to configure quality tools to make sure your code is tested properly with minimum coverage. Anyway, try to keep 100% of Code Coverage in your pull requests. To run your tests with code coverage report, you can either run it with: |
||||||
|
``` |
||||||
|
bin/phpunit --coverage-text |
||||||
|
``` |
||||||
|
or with more friendly and detailed user graphical representation, into HTML: |
||||||
|
``` |
||||||
|
bin/phpunit --coverate-html report |
||||||
|
``` |
||||||
|
where `report` is the directory where html report files shall be stored. |
||||||
|
Tests structure follow the same structure as production code with `Test` suffix in class and file name. All tests should go to `tests` directory in project root. So if you've created a class `Mage\Tasks\BuilIn\NewTask` the testing class should be called `MageTest\Tasks\BuiltIn\NewTaskTest`. |
||||||
|
To provide more strict tests, point what the method actually test and omit testing some classes indirectly, remember to add annotations to your tests: |
||||||
|
|
||||||
|
* **`@coversDefaultClass` class annotations** |
||||||
|
This prevent to to write full class name each time you write `@covers` for test method (see next point) |
||||||
|
```php |
||||||
|
|
||||||
|
/** |
||||||
|
* @coversDefaultClass Mage\Console\Colors |
||||||
|
*/ |
||||||
|
class ColorsTest extends PHPUnit_Framework_TestCase |
||||||
|
{ |
||||||
|
``` |
||||||
|
* **`@covers` methods annotations** |
||||||
|
```php |
||||||
|
/** |
||||||
|
* @covers ::add |
||||||
|
*/ |
||||||
|
public function testAddOnePlusOne() |
||||||
|
{ |
||||||
|
// ... |
||||||
|
} |
||||||
|
``` |
||||||
|
**Note:** If you omit `coversDefaultClass` for test class, you need to write full class name in `@covers` annotation. |
||||||
|
|
||||||
|
**Test class musn't test more than one class and any other classes than class being actually tested** |
||||||
|
|
||||||
|
## Configuration |
||||||
|
Magallanes configuration is kept in YAML files. Please follow those rules while adding or changing the configuration: |
||||||
|
* Keep 2 spaces indentation in each level |
||||||
|
* Multi-word config keys should be joined with dash (`-`), like `my-custom-task` |
||||||
|
* If your contribution includes new config key, please be sure that you've documented it in configuration documentation. |
@ -0,0 +1,60 @@ |
|||||||
|
<?php |
||||||
|
namespace Mage\Task\BuiltIn\Filesystem; |
||||||
|
|
||||||
|
use Mage\Task\SkipException; |
||||||
|
|
||||||
|
/** |
||||||
|
* Task for giving only to web server read permissions on given paths. |
||||||
|
* |
||||||
|
* Usage : |
||||||
|
* pre-deploy: |
||||||
|
* - filesystem/permissions-readable-only-by-web-server: {paths: /var/www/myapp/app/config/config.yml:/var/www/myapp/app/config/parameters.yml, recursive: false, checkPathsExist: true} |
||||||
|
* - filesystem/permissions-readable-only-by-web-server: |
||||||
|
* paths: |
||||||
|
* - /var/www/myapp/app/config/config.yml |
||||||
|
* - /var/www/myapp/app/config/parameters.yml |
||||||
|
* recursive: false |
||||||
|
* checkPathsExist: true |
||||||
|
* on-deploy: |
||||||
|
* - filesystem/permissions-readable-only-by-web-server: {paths: app/config/config.yml:app/config/parameters.yml, recursive: false, checkPathsExist: true} |
||||||
|
* |
||||||
|
* @author Jérémy Huet <jeremy.huet@gmail.com> |
||||||
|
*/ |
||||||
|
class PermissionsReadableOnlyByWebServerTask extends PermissionsTask |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Set group with web server user and give group write permissions. |
||||||
|
*/ |
||||||
|
public function init() |
||||||
|
{ |
||||||
|
parent::init(); |
||||||
|
|
||||||
|
$this->setGroup($this->getParameter('group') ? $this->getParameter('group') : $this->getWebServerUser()) |
||||||
|
->setRights('040'); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getName() |
||||||
|
{ |
||||||
|
return "Giving read permissions only to web server user for given paths [built-in]"; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Tries to guess the web server user by going thru the running processes. |
||||||
|
* |
||||||
|
* @return string |
||||||
|
* @throws SkipException |
||||||
|
*/ |
||||||
|
protected function getWebServerUser() |
||||||
|
{ |
||||||
|
$this->runCommand("ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1", $webServerUser); |
||||||
|
|
||||||
|
if (empty($webServerUser)) { |
||||||
|
throw new SkipException("Can't guess web server user. Please check if it is running or force it by setting the group parameter"); |
||||||
|
} |
||||||
|
|
||||||
|
return $webServerUser; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,324 @@ |
|||||||
|
<?php |
||||||
|
namespace Mage\Task\BuiltIn\Filesystem; |
||||||
|
|
||||||
|
use Mage\Task\AbstractTask; |
||||||
|
use Mage\Task\SkipException; |
||||||
|
|
||||||
|
/** |
||||||
|
* Task for setting permissions on given paths. Change will be done on local or |
||||||
|
* remote host depending on the stage of the deployment. |
||||||
|
* |
||||||
|
* Usage : |
||||||
|
* pre-deploy: |
||||||
|
* - filesystem/permissions: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/cache, recursive: false, checkPathsExist: true, owner: www-data, group: www-data, rights: 775} |
||||||
|
* - filesystem/permissions: |
||||||
|
* paths: |
||||||
|
* - /var/www/myapp/app/cache |
||||||
|
* - /var/www/myapp/app/logs |
||||||
|
* recursive: false |
||||||
|
* checkPathsExist: true |
||||||
|
* owner: www-data:www-data |
||||||
|
* rights: 775 |
||||||
|
* on-deploy: |
||||||
|
* - filesystem/permissions: {paths: app/cache:app/logs, recursive: false, checkPathsExist: true, owner: www-data, group: www-data, rights: 775} |
||||||
|
* |
||||||
|
* @author Jérémy Huet <jeremy.huet@gmail.com> |
||||||
|
*/ |
||||||
|
class PermissionsTask extends AbstractTask |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Paths to change of permissions in an array or a string separated by |
||||||
|
* PATH_SEPARATOR. |
||||||
|
* |
||||||
|
* If the stage is on local host you should give full paths. If on remote |
||||||
|
* you may give full or relative to the current release directory paths. |
||||||
|
* |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
private $paths; |
||||||
|
|
||||||
|
/** |
||||||
|
* If set to true, will check existance of given paths on the host and |
||||||
|
* throw SkipException if at least one does not exist. |
||||||
|
* |
||||||
|
* @var boolean |
||||||
|
*/ |
||||||
|
private $checkPathsExist = true; |
||||||
|
|
||||||
|
/** |
||||||
|
* Owner to set for the given paths (ex : "www-data" or "www-data:www-data" |
||||||
|
* to set both owner and group at the same time) |
||||||
|
* |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
private $owner; |
||||||
|
|
||||||
|
/** |
||||||
|
* Group to set for the given paths (ex : "www-data") |
||||||
|
* |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
private $group; |
||||||
|
|
||||||
|
/** |
||||||
|
* Rights to set for the given paths (ex: "755" or "g+w") |
||||||
|
* |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
private $rights; |
||||||
|
|
||||||
|
/** |
||||||
|
* If set to true, will recursively change permissions on given paths. |
||||||
|
* |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
private $recursive = false; |
||||||
|
|
||||||
|
/** |
||||||
|
* Initialize parameters. |
||||||
|
* |
||||||
|
* @throws SkipException |
||||||
|
*/ |
||||||
|
public function init() |
||||||
|
{ |
||||||
|
parent::init(); |
||||||
|
|
||||||
|
if (! is_null($this->getParameter('checkPathsExist'))) { |
||||||
|
$this->setCheckPathsExist($this->getParameter('checkPathsExist')); |
||||||
|
} |
||||||
|
|
||||||
|
if (! $this->getParameter('paths')) { |
||||||
|
throw new SkipException('Param paths is mandatory'); |
||||||
|
} |
||||||
|
$this->setPaths(is_array($this->getParameter('paths')) ? $this->getParameter('paths') : explode(PATH_SEPARATOR, $this->getParameter('paths', ''))); |
||||||
|
|
||||||
|
if (! is_null($owner = $this->getParameter('owner'))) { |
||||||
|
if (strpos($owner, ':') !== false) { |
||||||
|
$this->setOwner(array_shift(explode(':', $owner))); |
||||||
|
$this->setGroup(array_pop(explode(':', $owner))); |
||||||
|
} else { |
||||||
|
$this->setOwner($owner); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (! is_null($group = $this->getParameter('group'))) { |
||||||
|
$this->setGroup($group); |
||||||
|
} |
||||||
|
|
||||||
|
if (! is_null($rights = $this->getParameter('rights'))) { |
||||||
|
$this->setRights($rights); |
||||||
|
} |
||||||
|
|
||||||
|
if (! is_null($recursive = $this->getParameter('recursive'))) { |
||||||
|
$this->setRecursive($recursive); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getName() |
||||||
|
{ |
||||||
|
return "Changing rights / owner / group for given paths [built-in]"; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return boolean |
||||||
|
*/ |
||||||
|
public function run() |
||||||
|
{ |
||||||
|
$commands = array(); |
||||||
|
|
||||||
|
if ($this->paths && $this->owner) { |
||||||
|
$commands []= 'chown '. $this->getOptionsForCmd() .' ' . $this->owner . ' ' . $this->getPathsForCmd(); |
||||||
|
} |
||||||
|
|
||||||
|
if ($this->paths && $this->group) { |
||||||
|
$commands []= 'chgrp '. $this->getOptionsForCmd() .' ' . $this->group . ' ' . $this->getPathsForCmd(); |
||||||
|
} |
||||||
|
|
||||||
|
if ($this->paths && $this->rights) { |
||||||
|
$commands []= 'chmod '. $this->getOptionsForCmd() .' ' . $this->rights . ' ' . $this->getPathsForCmd(); |
||||||
|
} |
||||||
|
|
||||||
|
$result = $this->runCommand(implode(' && ', $commands)); |
||||||
|
|
||||||
|
return $result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Returns the options for the commands to run. Only supports -R for now. |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
protected function getOptionsForCmd() |
||||||
|
{ |
||||||
|
$optionsForCmd = ''; |
||||||
|
$options = array( |
||||||
|
'R' => $this->recursive |
||||||
|
); |
||||||
|
|
||||||
|
foreach($options as $option => $apply) { |
||||||
|
if ($apply === true) { |
||||||
|
$optionsForCmd .= $option; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return $optionsForCmd ? '-' . $optionsForCmd : ''; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Transforms paths array to a string separated by 1 space in order to use |
||||||
|
* it in a command line. |
||||||
|
* |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
protected function getPathsForCmd($paths = null) |
||||||
|
{ |
||||||
|
if (is_null($paths)) { |
||||||
|
$paths = $this->paths; |
||||||
|
} |
||||||
|
|
||||||
|
return implode(' ', $paths); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set paths. Will check if they exist on the host depending on |
||||||
|
* checkPathsExist flag. |
||||||
|
* |
||||||
|
* @param array $paths |
||||||
|
* @return PermissionsTask |
||||||
|
* @throws SkipException |
||||||
|
*/ |
||||||
|
protected function setPaths(array $paths) |
||||||
|
{ |
||||||
|
if ($this->checkPathsExist === true) { |
||||||
|
$commands = array(); |
||||||
|
foreach ($paths as $path) { |
||||||
|
$commands[] = '(([ -f ' . $path . ' ]) || ([ -d ' . $path . ' ]))'; |
||||||
|
} |
||||||
|
|
||||||
|
$command = implode(' && ', $commands); |
||||||
|
if (! $this->runCommand($command)) { |
||||||
|
throw new SkipException('Make sure all paths given exist on the host : ' . $this->getPathsForCmd($paths)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
$this->paths = $paths; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
protected function getPaths() |
||||||
|
{ |
||||||
|
return $this->paths; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set checkPathsExist. |
||||||
|
* |
||||||
|
* @param boolean $checkPathsExist |
||||||
|
* @return PermissionsTask |
||||||
|
*/ |
||||||
|
protected function setCheckPathsExist($checkPathsExist) |
||||||
|
{ |
||||||
|
$this->checkPathsExist = (bool) $checkPathsExist; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return boolean |
||||||
|
*/ |
||||||
|
protected function getCheckPathsExist() |
||||||
|
{ |
||||||
|
return $this->checkPathsExist; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set owner. |
||||||
|
* |
||||||
|
* @param string $owner |
||||||
|
* @return PermissionsTask |
||||||
|
*/ |
||||||
|
protected function setOwner($owner) |
||||||
|
{ |
||||||
|
$this->owner = $owner; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
protected function getOwner() |
||||||
|
{ |
||||||
|
return $this->owner; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set group. |
||||||
|
* |
||||||
|
* @param string $group |
||||||
|
* @return PermissionsTask |
||||||
|
*/ |
||||||
|
protected function setGroup($group) |
||||||
|
{ |
||||||
|
$this->group = $group; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
protected function getGroup() |
||||||
|
{ |
||||||
|
return $this->group; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set rights. |
||||||
|
* |
||||||
|
* @param string $rights |
||||||
|
* @return PermissionsTask |
||||||
|
*/ |
||||||
|
protected function setRights($rights) |
||||||
|
{ |
||||||
|
$this->rights = $rights; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
protected function getRights() |
||||||
|
{ |
||||||
|
return $this->rights; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Set recursive. |
||||||
|
* |
||||||
|
* @param boolean $recursive |
||||||
|
* @return PermissionsTask |
||||||
|
*/ |
||||||
|
protected function setRecursive($recursive) |
||||||
|
{ |
||||||
|
$this->recursive = (bool) $recursive; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return boolean |
||||||
|
*/ |
||||||
|
protected function getRecursive() |
||||||
|
{ |
||||||
|
return $this->recursive; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,60 @@ |
|||||||
|
<?php |
||||||
|
namespace Mage\Task\BuiltIn\Filesystem; |
||||||
|
|
||||||
|
use Mage\Task\SkipException; |
||||||
|
|
||||||
|
/** |
||||||
|
* Task for giving web server write permissions on given paths. |
||||||
|
* |
||||||
|
* Usage : |
||||||
|
* pre-deploy: |
||||||
|
* - filesystem/permissions-writable-by-web-server: {paths: /var/www/myapp/app/cache:/var/www/myapp/app/logs, recursive: false, checkPathsExist: true} |
||||||
|
* - filesystem/permissions-writable-by-web-server: |
||||||
|
* paths: |
||||||
|
* - /var/www/myapp/app/cache |
||||||
|
* - /var/www/myapp/app/logs |
||||||
|
* recursive: false |
||||||
|
* checkPathsExist: true |
||||||
|
* on-deploy: |
||||||
|
* - filesystem/permissions-writable-by-web-server: {paths: app/cache:app/logs, recursive: false, checkPathsExist: true} |
||||||
|
* |
||||||
|
* @author Jérémy Huet <jeremy.huet@gmail.com> |
||||||
|
*/ |
||||||
|
class PermissionsWritableByWebServerTask extends PermissionsTask |
||||||
|
{ |
||||||
|
/** |
||||||
|
* Set group with web server user and give group write permissions. |
||||||
|
*/ |
||||||
|
public function init() |
||||||
|
{ |
||||||
|
parent::init(); |
||||||
|
|
||||||
|
$this->setGroup($this->getParameter('group') ? $this->getParameter('group') : $this->getWebServerUser()) |
||||||
|
->setRights('g+w'); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getName() |
||||||
|
{ |
||||||
|
return "Giving write permissions to web server user for given paths [built-in]"; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Tries to guess the web server user by going thru the running processes. |
||||||
|
* |
||||||
|
* @return string |
||||||
|
* @throws SkipException |
||||||
|
*/ |
||||||
|
protected function getWebServerUser() |
||||||
|
{ |
||||||
|
$this->runCommand("ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1", $webServerUser); |
||||||
|
|
||||||
|
if (empty($webServerUser)) { |
||||||
|
throw new SkipException("Can't guess web server user. Please check if it is running or force it by setting the group parameter"); |
||||||
|
} |
||||||
|
|
||||||
|
return $webServerUser; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,43 @@ |
|||||||
|
#production |
||||||
|
deployment: |
||||||
|
user: root |
||||||
|
from: ./ |
||||||
|
# source: |
||||||
|
# type: git |
||||||
|
# repository: git://github.com/andres-montanez/Magallanes.git |
||||||
|
# from: master |
||||||
|
# temporal: /tmp/myAppClone |
||||||
|
to: /var/www/vhosts/example.com/www |
||||||
|
excludes: |
||||||
|
- application/data/cache/twig/* |
||||||
|
releases: |
||||||
|
enabled: true |
||||||
|
max: 5 |
||||||
|
symlink: current |
||||||
|
directory: releases |
||||||
|
# This option allows to dump the symlink with the TarGz strategy and use the symlink on the deployment host. |
||||||
|
# This is useful, if the files the symlink point to only exist on the deployment host and not on the host who runs the mage command. |
||||||
|
# The default value is false to keep bc. |
||||||
|
# See : http://linux.die.net/man/1/tar -h, --dereference |
||||||
|
dump-symlinks: true |
||||||
|
hosts: |
||||||
|
- s01.example.com |
||||||
|
- s02.example.com |
||||||
|
# s02.example.com: |
||||||
|
# deployment: |
||||||
|
# user: toor |
||||||
|
# to: /home/web/public |
||||||
|
# releases: |
||||||
|
# max: 10 |
||||||
|
# tasks: |
||||||
|
# on-deploy: |
||||||
|
# - privileges |
||||||
|
tasks: |
||||||
|
pre-deploy: |
||||||
|
- scm/update |
||||||
|
on-deploy: |
||||||
|
- symfony2/cache-warmup: { env: prod } |
||||||
|
- privileges |
||||||
|
- sampleTask |
||||||
|
- sampleTaskRollbackAware |
||||||
|
#post-deploy: |
@ -1,23 +1,22 @@ |
|||||||
<?php |
<?php |
||||||
namespace Task; |
namespace Task; |
||||||
|
|
||||||
use Mage\Task\AbstractTask; |
use Mage\Task\AbstractTask; |
||||||
use Mage\Task\Releases\RollbackAware; |
use Mage\Task\Releases\RollbackAware; |
||||||
|
|
||||||
class SampleTaskRollbackAware extends AbstractTask implements RollbackAware |
class SampleTaskRollbackAware extends AbstractTask implements RollbackAware |
||||||
{ |
{ |
||||||
public function getName() |
public function getName() |
||||||
{ |
{ |
||||||
if ($this->inRollback()) { |
if ($this->inRollback()) { |
||||||
return 'A Sample Task aware of rollbacks [in rollback]'; |
return 'A Sample Task aware of rollbacks [in rollback]'; |
||||||
} else { |
} else { |
||||||
return 'A Sample Task aware of rollbacks [not in rollback]'; |
return 'A Sample Task aware of rollbacks [not in rollback]'; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
public function run() |
public function run() |
||||||
{ |
{ |
||||||
return true; |
return true; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
|
@ -0,0 +1,63 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace MageTest\Command; |
||||||
|
|
||||||
|
use Mage\Command\Factory; |
||||||
|
use PHPUnit_Framework_TestCase; |
||||||
|
|
||||||
|
/** |
||||||
|
* @group Mage_Command |
||||||
|
* @group Mage_Command_Factory |
||||||
|
* |
||||||
|
* @group issue-167 |
||||||
|
*/ |
||||||
|
class FactoryTest extends PHPUnit_Framework_TestCase |
||||||
|
{ |
||||||
|
private $config; |
||||||
|
|
||||||
|
protected function setUp() |
||||||
|
{ |
||||||
|
$this->config = $this->getMock('Mage\Config'); |
||||||
|
} |
||||||
|
|
||||||
|
public function testGet() |
||||||
|
{ |
||||||
|
$command = Factory::get('add', $this->config); |
||||||
|
$this->assertInstanceOf('Mage\\Command\\BuiltIn\\AddCommand', $command); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException \Exception |
||||||
|
*/ |
||||||
|
public function testGetClassNotFoundException() |
||||||
|
{ |
||||||
|
$command = Factory::get('commanddoesntexist', $this->config); |
||||||
|
} |
||||||
|
|
||||||
|
public function testGetCustomCommand() |
||||||
|
{ |
||||||
|
$this->getMockBuilder('Mage\\Command\\AbstractCommand') |
||||||
|
->setMockClassName('MyCommand') |
||||||
|
->getMock(); |
||||||
|
|
||||||
|
/** |
||||||
|
* current workaround |
||||||
|
* @link https://github.com/sebastianbergmann/phpunit-mock-objects/issues/134 |
||||||
|
*/ |
||||||
|
class_alias('MyCommand', 'Command\\MyCommand'); |
||||||
|
|
||||||
|
$command = Factory::get('my-command', $this->config); |
||||||
|
$this->assertInstanceOf('Command\\MyCommand', $command); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @expectedException \Exception |
||||||
|
* @expectedExceptionMessage The command MyInconsistentCommand must be an instance of Mage\Command\AbstractCommand. |
||||||
|
*/ |
||||||
|
public function testGetInconsistencyException() |
||||||
|
{ |
||||||
|
$this->getMock('Command\\MyInconsistentCommand'); |
||||||
|
|
||||||
|
$command = Factory::get('my-inconsistent-command', $this->config); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue