Readouble

Laravel 5.0 Envoyタスクランナー

イントロダクションIntroduction

Laravel Envoy(使節)は、定義した共通タスクをリモートサーバーで実行するために、クリーンで最小限の記法を提供します。Bladeスタイルの記述法を使用し、デプロイやArtisanコマンドなどのタスクを簡単にセットアップできます。Laravel Envoy[https://github.com/laravel/envoy] provides a clean, minimal syntax for defining common tasks you run on your remote servers. Using a Blade style syntax, you can easily setup tasks for deployment, Artisan commands, and more.

注目: Envoyは、PHPバージョン5.4以上で、MacもしくはLinuxのオペレーティングシステム上で動作します。Note: Envoy requires PHP version 5.4 or greater, and only runs on Mac / Linux operating systems.

インストールInstallation

最初に、EnvoyをComposerのglobalコマンドでインストールします。First, install Envoy using the Composer global command:

composer global require "laravel/envoy=~1.0"

envoyコマンドを端末で実行するときには、envoyの実行ファイルが起動できるように、~/.composer/vendor/binディレクトリーに、実行パスを通しておくのを忘れないでください。Make sure to place the ~/.composer/vendor/bin directory in your PATH so the envoy executable is found when you run the envoy command in your terminal.

次に、Envoy.blade.phpファイルをプロジェクトのルートに作成します。最初のサンプル設定をどうぞ。Next, create an Envoy.blade.php file in the root of your project. Here's an example to get you started:

@servers(['web' => '192.168.1.1'])

@task('foo', ['on' => 'web'])
	ls -la
@endtask

見ての通り、最初に@serversで、配列を定義しています。これらのサーバーへは、タスク宣言のonオプションの中で、参照できます。@task宣言の中に、タスクを実行するサーバーで走らせる、Bashコードを記述します。As you can see, an array of @servers is defined at the top of the file. You can reference these servers in the on option of your task declarations. Within your @task declarations you should place the Bash code that will be run on your server when the task is executed.

initコマンドを使用し、Envoyファイルのスタブを簡単に作成できます。The init command may be used to easily create a stub Envoy file:

envoy init user@192.168.1.1

タスク実行Running Tasks

タスクを実行するには、インストールしたEnvoyで、runコマンドを実行してください。To run a task, use the run command of your Envoy installation:

envoy run foo

必要であれば、コマンドラインスイッチを使用し、Envoyファイルへ変数を渡すことができます。If needed, you may pass variables into the Envoy file using command line switches:

envoy run deploy --branch=master

指定したオプションをBlade記法で使用できます。You may use the options via the Blade syntax you are used to:

@servers(['web' => '192.168.1.1'])

@task('deploy', ['on' => 'web'])
	cd site
	git pull origin {{ $branch }}
	php artisan migrate
@endtask

準備コードBootstrapping

@setupディレクティブを使えば、Envoyファイルの中で変数宣言をしたり、一般的なPHPコードを動作させたりできます。You may use the @setup directive to declare variables and do general PHP work inside the Envoy file:

@setup
	$now = new DateTime();

	$environment = isset($env) ? $env : "testing";
@endsetup

また、@includeを使用し、PHPファイルを読み込むことも可能です。You may also use @include to include any PHP files:

@include('vendor/autoload.php');

タスク実行前の確認Confirming Tasks Before Running

サーバーで指定したタスクを実行する前に確認のプロンプトを表示したい場合は、confirmディレクティブを使ってください。If you would like to be prompted for confirmation before running a given task on your servers, you may use the confirm directive:

@task('deploy', ['on' => 'web', 'confirm' => true])
	cd site
	git pull origin {{ $branch }}
	php artisan migrate
@endtask

複数サーバーMultiple Servers

複数のサーバーに渡り、簡単にタスクを実行できます。タスク宣言で、サーバーのリストを指定するだけです。You may easily run a task across multiple servers. Simply list the servers in the task declaration:

@servers(['web-1' => '192.168.1.1', 'web-2' => '192.168.1.2'])

@task('deploy', ['on' => ['web-1', 'web-2']])
	cd site
	git pull origin {{ $branch }}
	php artisan migrate
@endtask

デフォルトでは、タスクは各サーバーで、順番に実行します。つまり、最初のサーバーで実行が終わったら、次のサーバーの実行へと進みます。By default, the task will be executed on each server serially. Meaning, the task will finish running on the first server before proceeding to execute on the next server.

並列実行Parallel Execution

複数のサーバー間で、同時にタスクを実行したい場合は、ただparallelオプションをタスク宣言で指定してください。If you would like to run a task across multiple servers in parallel, simply add the parallel option to your task declaration:

@servers(['web-1' => '192.168.1.1', 'web-2' => '192.168.1.2'])

@task('deploy', ['on' => ['web-1', 'web-2'], 'parallel' => true])
	cd site
	git pull origin {{ $branch }}
	php artisan migrate
@endtask

タスクマクロTask Macros

マクロでは、一つのコマンドで順番に実行する、一連のタスクを定義します。例えば:Macros allow you to define a set of tasks to be run in sequence using a single command. For instance:

@servers(['web' => '192.168.1.1'])

@macro('deploy')
	foo
	bar
@endmacro

@task('foo')
	echo "HELLO"
@endtask

@task('bar')
	echo "WORLD"
@endtask

これで、deployマクロは、ひとつのシンプルなコマンドにより、実行されます。The deploy macro can now be run via a single, simple command:

envoy run deploy

通知Notifications

HipChatHipChat

タスクを実行後、あなたのチームのHipChatルームへ、シンプルな@hipchatディレクティブを使用し、通知を送ることができます。After running a task, you may send a notification to your team's HipChat room using the simple @hipchat directive:

@servers(['web' => '192.168.1.1'])

@task('foo', ['on' => 'web'])
	ls -la
@endtask

@after
	@hipchat('token', 'room', 'Envoy')
@endafter

また、カスタムメッセージをHipChatルームに指定することもできます。@setupで変数を直接宣言できますし、@includeでファイルを読み込むこともできます。そうして宣言した変数をメッセージの中で使用できます。You can also specify a custom message to the hipchat room. Any variables declared in @setup or included with @include will be available for use in the message:

@after
	@hipchat('token', 'room', 'Envoy', "$task ran on [$environment]")
@endafter

これは、サーバーでタスクが実行されたことをチームへ必ず通知できる、とてもシンプルな方法です。This is an amazingly simple way to keep your team notified of the tasks being run on the server.

SlackSlack

Slackへ通知を送るには、以下の記述法が使用できます。The following syntax may be used to send a notification to Slack[https://slack.com]:

@after
	@slack('hook', 'channel', 'message')
@endafter

SlackのWebサイトのIncoming WebHooksインテグレーションを作成し、WebフックURLを取得してください。hook引数はIncoming Webhooksインテグレーションにより提供される完全なWebフックURLを指定します。例えば:You may retrieve your webhook URL by creating an Incoming WebHooks integration on Slack's website. The hook argument should be the entire webhook URL provided by the Incoming Webhooks Slack Integration. For example:

https://hooks.slack.com/services/ZZZZZZZZZ/YYYYYYYYY/XXXXXXXXXXXXXXX

channel引数には、以下の形式の一つを指定します。You may provide one of the following for the channel argument:

  • チャンネルに通知する場合:#channelTo send the notification to a channel: #channel
  • ユーザーに通知する場合:@userTo send the notification to a user: @user

channel引数が指定されない場合は、デフォルトのチャンネルが使用されるでしょう。If no channel argument is provided the default channel will be used.

注意: Slackへの通知は、全タスクが失敗なく完了した場合のみ行われます。Note: Slack notifications will only be sent if all tasks complete successfully.

EnvoyのアップデートUpdating Envoy

Envoyを更新するには、通常通りComposerを使ってください。To update Envoy, simply use Composer:

composer global update

章選択

Artisan CLI

設定

明暗テーマ
light_mode
dark_mode
brightness_auto システム設定に合わせる
テーマ選択
photo_size_select_actual デフォルト
photo_size_select_actual モノクローム(白黒)
photo_size_select_actual Solarized風
photo_size_select_actual GitHub風(青ベース)
photo_size_select_actual Viva(黄緑ベース)
photo_size_select_actual Happy(紫ベース)
photo_size_select_actual Mint(緑ベース)
コードハイライトテーマ選択

明暗テーマごとに、コードハイライトのテーマを指定できます。

テーマ配色確認
スクリーン表示幅
640px
80%
90%
100%

768px以上の幅があるときのドキュメント部分表示幅です。

インデント
無し
1rem
2rem
3rem
原文確認
原文を全行表示
原文を一行ずつ表示
使用しない

※ 段落末のEボタンへカーソルオンで原文をPopupします。

Diff表示形式
色分けのみで区別
行頭の±で区別
削除線と追記で区別

※ [tl!…]形式の挿入削除行の表示形式です。

テストコード表示
両コード表示
Pestのみ表示
PHPUnitのみ表示
和文変換

対象文字列と置換文字列を半角スペースで区切ってください。(最大5組各10文字まで)

本文フォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

コードフォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

保存内容リセット

localStrageに保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作