20. Synopsis
use Cinnamon::DSL;
set user => 'johndoe'; # required
set application => 'My-App'; # custom value
role production
=> 'production.host'; # declare server
task update => sub {
my ($host, @args) = @_;
my $deploy_to = get('deploy_to');
remote {
run "cd $deploy_to && git pull";
} $host;
};
21. use Cinnamon::DSL;
• config/deploy.pl
set user => 'johndoe'; # required
set application => 'My-App'; # custom value
• useしてDSLを書けるように
role production
=> 'production.host'; # declare server
task update => sub {
my ($host, @args) = @_;
my $deploy_to = get('deploy_to');
remote {
run "cd $deploy_to && git pull";
} $host;
};
22. use Cinnamon::DSL;
set user => 'johndoe'; # required
set application => 'My-App'; # custom value
• ログインユーザ名をset
role production
=> 'production.host'; # declare server
task update => sub {
my ($host, @args) = @_;
my $deploy_to = get('deploy_to');
remote {
run "cd $deploy_to && git pull";
} $host;
};
23. use Cinnamon::DSL;
set user => 'johndoe'; # required
set application => 'My-App'; # custom value
role production
=> 'production.host'; # declare server
• roleでサーバ群を定義
task update => sub {
my ($host, @args) = @_;
my $deploy_to = get('deploy_to');
• 配列で複数サーバ渡せる
remote {
run "cd $deploy_to && git pull";
} $host;
};
24. • taskで実行コマンドを定義
use Cinnamon::DSL;
set user => 'johndoe'; # required
• remote + runでサーバに実行
set application => 'My-App'; # custom value
role production
• runの代わりにsudo
=> 'production.host'; # declare server
task update => sub {
my ($host, @args) = @_;
my $deploy_to = get('deploy_to');
remote {
run "cd $deploy_to && git pull";
} $host;
};
25. use Cinnamon::DSL;
set user => 'johndoe'; # required
set application => 'My-App'; # custom value
role production
=> 'production.host'; # declare server
task update => sub {
my ($host, @args) = @_;
my $deploy_to = get('deploy_to');
remote {
•
run "cd $deploy_to && git pull";
set/getを使ってユーザ定義値
} $host;
};
• 遅延評価することも可能
30. サーバ群を
別の管理ツールから決めたい
role production => sub {
my $res = LWP::UserAgent->get(
'http://servers.example.com/api/hosts',
);
my $hosts = decode_json $res->content;
$hosts;
};
callbackで動的にサーバを決める
遅延ロードする
45. DSLの応用的な実装
sub enable { $_add->(@_) }
sub builder(&) {
my $block = shift;
my $self = __PACKAGE__->new;
# ...
local $_add = sub {
$self->add_middleware(@_);
};
# ...
}