Skip to content

Commit

Permalink
Merge 1a7c1f9 into b03b54a
Browse files Browse the repository at this point in the history
  • Loading branch information
kohkimakimoto committed Oct 13, 2014
2 parents b03b54a + 1a7c1f9 commit 0bd017a
Show file tree
Hide file tree
Showing 151 changed files with 4,466 additions and 4,226 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
/.altax
/build
/tests/tmp/*
/altax.phar
.DS_Store
Thumbs.db
.tags
.tags_sorted_by_file
._*
5 changes: 5 additions & 0 deletions .snippets
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
altax
* [altax] sudo ln -s `pwd`/bin/altax /usr/local/bin/altax
* [altax] php vendor/bin/phpunit
* [altax] php vendor/bin/php-cs-fixer fix src
* [altax] php vendor/bin/phpunit tests/e2e/E2eTest.php
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6

before_script:
- composer install --dev --no-interaction
Expand Down
156 changes: 16 additions & 140 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
Altax is a deployment tool for PHP.
I designed it as a command-line tool for running tasks to remote servers
like the [Capistrano](https://github.com/capistrano/capistrano), [Fabric](http://fabric.readthedocs.org/) and [Cinamon](https://github.com/kentaro/cinnamon).
It also has a plugin mechanism for managing and installing tasks easily.

This is a simple git deploy task definition. You can write any tasks in PHP.
The following code is a simple git deploy task definition. You can write any tasks in PHP.

```php
// Register managed nodes to a role.
Expand All @@ -21,169 +20,51 @@ Server::node("web2.example.com", "web");
Server::node("db1.example.com", "db");

// Register a task.
Task::register("deploy", function($task){
Task::register("deploy", function(){

$appDir = "/path/to/app";

// Execute parallel processes for each nodes.
$task->exec(function($process) use ($appDir){
Process::exec(["web", "db"], function() use ($appDir){

// Run a command remotely and get a return code.
if ($process->run("test -d $appDir")->isFailed()) {
$process->run("git clone git@github.com:path/to/app.git $appDir");
if (Command::run("test -d $appDir")->isFailed()) {
Command::run("git clone git@github.com:path/to/app.git $appDir");
} else {
$process->run(array(
Command::run(array(
"cd $appDir",
"git pull",
));
}

}, array("web"));
});

});

```

You can run it like below

```Shell
```
$ altax deploy
[web1.example.com:8550] Run: test -d /var/tmp/altax
[web1.example.com:8550] Run: git clone git@github.com:kpath/to/app.git /path/to/app
Initialized empty Git repository in /path/to/app/.git/
[web2.example.com:8551] Run: test -d /var/tmp/altax
[web3.example.com:8551] Run: git clone git@github.com:kpath/to/app.git /path/to/app
Initialized empty Git repository in /path/to/app/.git/
Run command: test -d /path/to/app on web1.example.com
Run command: git clone git@github.com:path/to/app.git /path/to/app on web1.example.com
Run command: test -d /path/to/app on web2.example.com
Run command: git clone git@github.com:path/to/app.git /path/to/app on web2.example.comInitialized empty Git repository in /path/to/app/.git/
Run command: test -d /path/to/app on db1.example.com
Run command: git clone git@github.com:path/to/app.git /path/to/app on db1.example.com
```

You can get more information at [http://kohkimakimoto.github.io/altax/](http://kohkimakimoto.github.io/altax/).

## Requirement

PHP5.3 or later.
PHP5.4 or later.

## Installation

I recommend you to install Altax as a phar (PHP Archive) which compiled to single executable file.
Run the below command to get latest version of Altax.

```Shell
$ curl -L https://raw.githubusercontent.com/kohkimakimoto/altax/master/installer.sh | bash -s system
```

You will get `altax` command file to `/usr/local/bin` directory. In order to check installation,
execute just `altax` command.

```Shell
$ altax
Altax version 3.0.0

Altax is a extensible deployment tool for PHP.
Copyright (c) Kohki Makimoto <kohki.makimoto@gmail.com>
Apache License 2.0
...

```

## Usage

I describe basic usage in this section.

Run `altax init` command to generate first configuration.

```Shell
$ altax init
Created file: /path/to/your/directory/.altax/config.php
Created file: /path/to/your/directory/.altax/composer.json
Created file: /path/to/your/directory/.altax/.gitignore
```

Created `.altax/config.php` file in your current directory is a main configuration file for altax.
You can modify this file to define tasks and servers you managed.
So now, add the following code in the file.

```php
Task::register("hello", function($task){

$task->writeln("Hello world!");

})->description("This is a first sample task.");
```

This is a simple task definition. Defined task is listed by executing just `altax` command.

```Shell
$ altax
Altax version 3.0.0

Altax is a deployment tool for PHP.
it's designed as a command-line tool for running tasks to remote servers.
Copyright (c) Kohki Makimoto <kohki.makimoto@gmail.com>
Apache License 2.0
...
Available commands:
hello This is a first sample task.
...
```
`hello` task you defined can be executed by `altax` command with task name like the followiing.
```Shell
$ altax hello
Hello world!
```
You got a first altax task now!
If you want to see more information, visit a [documentation](http://kohkimakimoto.github.io/altax/) page.
## Documentation
See [documentation](http://kohkimakimoto.github.io/altax/) page.
## Plugins
Altax has a extensible plugin mechanism. It makes adding functionality easy.
Plugins are stored at [Packagist](https://packagist.org/) and installed using [composer](https://getcomposer.org/).
As Altax includes embedded composer, you can install plugins by altax command.
For instance, if you use PHP5.4 and MySQL database in your product, you can use [Adminer](http://www.adminer.org/) database management tool via Altax plugin.
Edit your `.altax/composer.json` file like the following.
```json
{
"require": {
"kohkimakimoto/altax-adminer": "dev-master"
}
}
```
And run altax update command which is a wrapper command of `composer update` for Altax.
```Shell
$ altax update
```
Adminer altax plugin will be installed in your `.altax/vendor` directory.
In order to register the plugin to your task, add the following line your `.altax/config.php` file.
```php
Task::register('adminer', 'Altax\Contrib\Adminer\Command\AdminerCommand');
```
Run the registered plugin task commnad.
```Shell
$ altax adminer
```
Altax runs adminer on built-in web server. So you can use adminer at `http://localhost:3000/`.
If you are interested in Altax plugins, [Search plugins at packagist](https://packagist.org/search/?q=altax)!
## Author
## Author

Kohki Makimoto <kohki.makimoto@gmail.com>

Expand All @@ -193,8 +74,3 @@ Apache License 2.0

See [LICENSE](./LICENSE)

## Previous version
If you use Altax version 2. You can see **[2.x branch](https://github.com/kohkimakimoto/altax/tree/2.x)**.
Altax version 1 is no longer maintained.
Binary file removed altax.phar
Binary file not shown.
63 changes: 8 additions & 55 deletions bin/altax
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,58 +1,11 @@
#!/usr/bin/env php
<?php


if (PHP_SAPI !== 'cli') {
echo 'Warning: Altax should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL;
}

error_reporting(-1);

// This code references Composer.
if (function_exists('ini_set')) {
@ini_set('display_errors', 1);

$memoryInBytes = function ($value) {
$unit = strtolower(substr($value, -1, 1));
$value = (int) $value;
switch($unit) {
case 'g':
$value *= 1024;
// no break (cumulative multiplier)
case 'm':
$value *= 1024;
// no break (cumulative multiplier)
case 'k':
$value *= 1024;
}

return $value;
};

$memoryLimit = trim(ini_get('memory_limit'));
// Increase memory_limit if it is lower than 512M
if ($memoryLimit != -1 && $memoryInBytes($memoryLimit) < 512 * 1024 * 1024) {
@ini_set('memory_limit', '512M');
}
unset($memoryInBytes, $memoryLimit);
}


if (is_file(__DIR__ . '/../vendor/autoload.php')) {

require_once __DIR__ . '/../vendor/autoload.php';

} else if (is_file(__DIR__ . '/../../../autoload.php')) {

require_once __DIR__ . '/../../../autoload.php';

} else if (is_file(__DIR__ . '/../autoload.php')) {

require_once __DIR__ . '/../autoload.php';

}

$container = require_once __DIR__.'/../src/Altax/Foundation/boot.php';

$app = new \Altax\Console\Application($container);
$app->run();
require_once __DIR__.'/../vendor/autoload.php';

$app = bootAltaxApplication(array(
getenv("HOME")."/.altax/bootstrap.php",
getcwd()."/.altax/bootstrap.php",
));
$cli = new \Altax\Console\Application($app);
$cli->run();
11 changes: 7 additions & 4 deletions compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<?php

// Embed commit hash to altax source.
$containerSourcePath = __DIR__."/src/Altax/Foundation/Container.php";
$containerSourceBackupPath = __DIR__."/Container.bak.php";
$containerSourcePath = __DIR__."/src/Altax/Foundation/Application.php";
$containerSourceBackupPath = __DIR__."/Application.bak.php";
copy($containerSourcePath, $containerSourceBackupPath);
$contents = file_get_contents($containerSourcePath);
$hash = exec("git log --pretty=format:'%H' -n 1");
Expand All @@ -18,12 +18,16 @@

use Symfony\Component\Finder\Finder;

$pharFile = __DIR__."/altax.phar";
$pharFile = __DIR__."/build/altax.phar";

if (file_exists($pharFile)) {
unlink($pharFile);
}

if (!is_dir(dirname($pharFile))) {
mkdir(dirname($pharFile));
}

echo "Starting compiling $pharFile\n";

$phar = new \Phar($pharFile, 0);
Expand Down Expand Up @@ -64,4 +68,3 @@
// Revert to altax source.
copy($containerSourceBackupPath, $containerSourcePath);
unlink($containerSourceBackupPath);

27 changes: 18 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,42 @@
}
],
"require": {
"php": ">=5.3.0",
"php": ">=5.4.0",
"composer/composer": "1.0.*@dev",
"symfony/process": "2.5.*",
"symfony/console": "2.5.*",
"symfony/filesystem": "2.5.*",
"symfony/yaml": "2.5.*",
"symfony/finder": "2.5.*",
"symfony/process": "2.5.*",
"illuminate/container": "4.*",
"illuminate/support": "4.*",
"illuminate/config": "4.*",
"illuminate/events": "4.*",
"phpseclib/phpseclib": "0.3.*"
},
"require-dev": {
"phpunit/phpunit": "4.*",
"mockery/mockery": "~0.9",
"fabpot/php-cs-fixer": "@stable",
"satooshi/php-coveralls": "dev-master"
},
"scripts": {
"post-install-cmd": [
"Altax\\Script\\ScriptHandler::removeAutoloadFiles"
"Altax\\ComposerScript\\ScriptHandler::removeAutoloadFiles"
],
"post-update-cmd": [
"Altax\\Script\\ScriptHandler::removeAutoloadFiles"
"Altax\\ComposerScript\\ScriptHandler::removeAutoloadFiles"
]
},
"require-dev": {
"phpunit/phpunit": "3.*",
"satooshi/php-coveralls": "dev-master"
},
"autoload": {
"files": [
"src/Altax/Foundation/functions.php"
],
"psr-0": { "Altax\\": "src/"}
},
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev"
"dev-master": "3.1.x-dev"
}
},
"bin": ["bin/altax"]
Expand Down

0 comments on commit 0bd017a

Please sign in to comment.