-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2dd41fa
Showing
5 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/vendor | ||
/tmp | ||
/composer.phar | ||
/composer.lock | ||
/.project | ||
/.altax | ||
/build | ||
.DS_Store | ||
Thumbs.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Altax chef plugin | ||
|
||
Runs chef-solo via [altax](https://github.com/kohkimakimoto/altax) and Git. | ||
|
||
> NOTE: This product is in development stag, So I sometimes break code. | ||
## Requirement | ||
|
||
Depends on my personal environment. | ||
|
||
* CentOS6 | ||
* PHP5.4 | ||
|
||
## Installation | ||
|
||
Edit your `.altax/composer.json` file like the following. | ||
|
||
{ | ||
"require": { | ||
"kohkimakimoto/altax-chef": "dev-master" | ||
} | ||
} | ||
|
||
Run altax update. | ||
|
||
$ altax update | ||
|
||
Add the following code your `.altax/config.php` file. | ||
|
||
Task::register("chef", 'Altax\Contrib\Chef\Command\ChefCommand') | ||
->config(array( | ||
"repo" => "git repository path to store chef repository" | ||
)) | ||
; | ||
|
||
## Usage | ||
|
||
See | ||
|
||
altax chef -h | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "kohkimakimoto/altax-chef", | ||
"description": "Runs chef-solo via altax.", | ||
"keywords": ["altax", "plugin", "chef"], | ||
"homepage": "https://github.com/kohkimakimoto/altax-chef", | ||
"license": "Apache License 2.0", | ||
"authors": [ | ||
{ | ||
"name": "Kohki Makimoto", | ||
"email": "kohki.makimoto@gmail.com" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0" | ||
}, | ||
"require-dev": { | ||
"kohkimakimoto/altax": "3.*", | ||
"phpunit/phpunit": "3.*" | ||
}, | ||
"minimum-stability": "alpha", | ||
"autoload": { | ||
"psr-0": { "Altax\\Contrib\\Chef\\": "src/"} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit colors="true"> | ||
<testsuites> | ||
<testsuite name="Unit tests"> | ||
<directory suffix="Test.php">tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
namespace Altax\Contrib\Chef\Command; | ||
|
||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Finder\Finder; | ||
|
||
class ChefCommand extends \Altax\Command\Command | ||
{ | ||
public $chefRpm = "https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-11.8.2-1.el6.x86_64.rpm"; | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setDescription("Runs chef-solo via altax.") | ||
->addArgument( | ||
'target', | ||
InputArgument::IS_ARRAY | InputArgument::REQUIRED, | ||
'Target nodes or roles to run chef-solo.' | ||
) | ||
->addOption( | ||
'berks', | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Runs berkself even if exists cookbooks.' | ||
) | ||
->addOption( | ||
'no-solo', | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Do not run chef-solo.' | ||
) | ||
->addOption( | ||
'prepare', | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Prepare chef-solo (installing chef and something).' | ||
) | ||
; | ||
} | ||
|
||
protected function fire($task) | ||
{ | ||
$input = $task->getInput(); | ||
$output = $task->getOutput(); | ||
|
||
$config = $this->getTaskConfig(); | ||
if (!isset($config["repo"])) { | ||
throw new \RuntimeException("You must set config key 'repo'."); | ||
} | ||
|
||
$repo = $config["repo"]; | ||
$dir = isset($config["dir"]) ? $config["dir"] : "/var/chef"; | ||
$berks = isset($config["berks"]) ? $config["berks"] : "/opt/chef/embedded/bin/berks"; | ||
|
||
$target = $input->getArgument("target"); | ||
$runBerks = $input->getOption("berks"); | ||
$noSolo = $input->getOption("no-solo"); | ||
$prepare = $input->getOption("prepare"); | ||
|
||
if ($prepare) { | ||
// Prepare | ||
$chefRpm = $this->chefRpm; | ||
|
||
$task->exec(function($process) use ($chefRpm, $dir, $repo, $berks, $runBerks, $noSolo) { | ||
|
||
// Install git | ||
$process->run("yum install -y git", arary("user" => "root")); | ||
// Install chef | ||
$process->run("rpm -ivh $chefRpm", arary("user" => "root")); | ||
// Install berkself gem | ||
$process->run("/opt/chef/embedded/bin/gem install berkshelf --no-rdoc --no-ri", arary("user" => "root")); | ||
|
||
}, $target); | ||
|
||
} else { | ||
// Run chef-solo | ||
|
||
$task->exec(function($process) use ($dir, $repo, $berks, $runBerks, $noSolo) { | ||
|
||
$node = $process->getNode(); | ||
|
||
// Get chef repository | ||
$ret = null; | ||
if ($process->run("test -d $dir")->isFailed()) { | ||
$ret = $process->run("git clone $repo $dir"); | ||
} else { | ||
$ret = $process->run("git pull", array("cwd" => $dir)); | ||
} | ||
|
||
if ($ret->isFailed()) { | ||
throw new \RuntimeException("Got a error."); | ||
} | ||
|
||
// Check existing the cookbooks directory | ||
if ($process->run("test -d $dir/cookbooks")->isFailed()) { | ||
$runBerks = true; | ||
} | ||
|
||
if ($runBerks) { | ||
// Run berkself | ||
// "unset" Prevent to load system wide ruby and gems. | ||
$process->run(array( | ||
"unset GEM_HOME && unset GEM_PATH", | ||
"cd $dir", | ||
"$berks --path cookbooks" | ||
), array("user" => "root")); | ||
|
||
} | ||
|
||
if (!$noSolo) { | ||
// Run chef-solo | ||
$nodeName = $node->getName(); | ||
$process->run(array( | ||
"unset GEM_HOME && unset GEM_PATH", | ||
"cd $dir", | ||
"chef-solo -c $dir/config/solo.rb -j $dir/nodes/${nodeName}.json" | ||
), array("user" => "root")); | ||
} | ||
|
||
}, $target); | ||
|
||
} | ||
|
||
|
||
} | ||
} |