Altax 是一个可扩展的 PHP 部署工具。

v3.0.17 2017-11-21 03:31 UTC

README

Build Status Coverage Status Latest Stable Version License

Altax 是一个 PHP 部署工具。我将其设计为一个命令行工具,用于在远程服务器上运行任务,如 Capistrano、Fabric 和 Cinamon。它还包含一个插件机制,可以轻松管理和安装任务。

这是一个简单的 git 部署任务定义。您可以在 PHP 中编写任何任务。

// Register managed nodes to a role.
Server::node("web1.example.com", "web");
Server::node("web2.example.com", "web");
Server::node("db1.example.com",  "db");

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

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

    // Execute parallel processes for each nodes.
    $task->exec(function($process) 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");
        } else {
            $process->run(array(
                "cd $appDir",
                "git pull",
                ));
        }

    }, array("web"));

});

您可以使用以下方式运行它

$ 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/

您可以在 http://kohkimakimoto.github.io/altax/ 获取更多信息。

要求

PHP5.3 或更高版本。

安装

我建议您将 Altax 作为 phar(PHP 归档)安装,该归档编译为单个可执行文件。运行以下命令以获取 Altax 的最新版本。

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

您将在 /usr/local/bin 目录中获取 altax 命令文件。为了检查安装,只需执行 altax 命令。

$ 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
...

用法

我在本节中描述了基本用法。

运行 altax init 命令以生成第一个配置。

$ 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

在您的当前目录中创建的 .altax/config.php 文件是 altax 的主要配置文件。您可以修改此文件来定义要管理的任务和服务器。因此,现在在文件中添加以下代码。

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

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

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

这是一个简单的任务定义。定义的任务将按执行 altax 命令的方式列出。

$ 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 任务可以通过以下方式使用 altax 命令执行。

$ altax hello
Hello world!

您现在有了第一个 altax 任务了!

如果您想了解更多信息,请访问 文档 页面。

文档

查看 文档 页面。

插件

Altax 具有一个可扩展的插件机制。这使得添加功能变得简单。插件存储在 Packagist 上,并使用 composer 安装。由于 Altax 包含内置的 composer,您可以使用 altax 命令安装插件。

例如,如果您在产品中使用 PHP5.4 和 MySQL 数据库,您可以通过 Altax 插件使用 Adminer 数据库管理工具。按照以下方式编辑您的 .altax/composer.json 文件。

{
  "require": {
    "kohkimakimoto/altax-adminer": "dev-master"
  }
}

并运行 altax update 命令,该命令是 Altax 的 composer update 包装命令。

$ altax update

Adminer altax 插件将安装在您的 .altax/vendor 目录中。为了将插件注册到您的任务中,请向您的 .altax/config.php 文件中添加以下行。

Task::register('adminer', 'Altax\Contrib\Adminer\Command\AdminerCommand');

运行已注册的插件任务命令。

$ altax adminer

Altax 在内置的 web 服务器上运行 adminer。因此,您可以在 https://:3000/ 使用 adminer。

如果您对 Altax 插件感兴趣,请在 Packagist 上搜索插件

作者

Kohki Makimoto kohki.makimoto@gmail.com

许可

Apache License 2.0

查看许可协议

上一个版本

如果您使用Altax版本2,您可以查看2.x分支。Altax版本1不再维护。