Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Plack + Carton: deployment made simple and awesome
Search
Tatsuhiko Miyagawa
May 12, 2012
Technology
4
1.4k
Plack + Carton: deployment made simple and awesome
at PerlMova and YAPC::Russia 2012
Tatsuhiko Miyagawa
May 12, 2012
Tweet
Share
More Decks by Tatsuhiko Miyagawa
See All by Tatsuhiko Miyagawa
Carmel at YAPC::EU 2015
miyagawa
0
490
Carton at London Perl Workshop 2013
miyagawa
0
250
Managing CPAN dependencies with Carton
miyagawa
0
270
What's new in Carton and cpanm at YAPC::Asia 2013
miyagawa
6
1.2k
Carton 1.0 at OSCON 2013
miyagawa
11
2.2k
cpanm 1.6 at OSDC.TW
miyagawa
6
1.3k
10 more things to be ripped off
miyagawa
7
1.3k
Ruby; Exported
miyagawa
1
940
10 Years: LL, you and me
miyagawa
2
180
Other Decks in Technology
See All in Technology
国土交通省 データコンペ参加者向け勉強会
takehikohashimoto
0
120
新卒1年目が向き合う生成AI事業の開発を加速させる技術選定 / ai-web-launcher
cyberagentdevelopers
PRO
7
1.5k
顧客が本当に必要だったもの - パフォーマンス改善編 / Make what is needed
soudai
24
6.8k
プロダクトエンジニアが活躍する環境を作りたくて 事業責任者になった話 ~プロダクトエンジニアの行き着く先~
gimupop
1
480
[AWS JAPAN 生成AIハッカソン] Dialog の紹介
yoshimi0227
0
150
現地でMeet Upをやる場合の注意点〜反省点を添えて〜
shotashiratori
0
530
ABEMA のコンテンツ制作を最適化!生成 AI x クラウド映像編集システム / abema-ai-editor
cyberagentdevelopers
PRO
1
180
Figma Dev Modeで進化するデザインとエンジニアリングの協働 / figma-with-engineering
cyberagentdevelopers
PRO
1
430
プロダクト成長に対応するプラットフォーム戦略:Authleteによる共通認証基盤の移行事例 / Building an authentication platform using Authlete and AWS
kakehashi
1
150
グローバル展開を見据えたサービスにおける機械翻訳プラクティス / dp-ai-translating
cyberagentdevelopers
PRO
1
150
WINTICKETアプリで実現した高可用性と高速リリースを支えるエコシステム / winticket-eco-system
cyberagentdevelopers
PRO
1
190
VPC間の接続方法を整理してみた #自治体クラウド勉強会
non97
1
860
Featured
See All Featured
Designing for Performance
lara
604
68k
Designing on Purpose - Digital PM Summit 2013
jponch
115
6.9k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.6k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
92
16k
Visualization
eitanlees
144
15k
The Cost Of JavaScript in 2023
addyosmani
45
6.6k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
328
21k
What's in a price? How to price your products and services
michaelherold
243
12k
Side Projects
sachag
452
42k
Unsuck your backbone
ammeep
668
57k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Agile that works and the tools we love
rasmusluckow
327
21k
Transcript
Plack + Carton deployment simple & awesome Tatsuhiko Miyagawa Perl
Mova / YAPC::Russia 2012 Saturday, May 12, 12
привет Saturday, May 12, 12
Me • Tatsuhiko Miyagawa • CPAN: MIYAGAWA • github.com/miyagawa •
Twitter @miyagawa • Lives in San Francisco, CA Saturday, May 12, 12
Saturday, May 12, 12
Saturday, May 12, 12
Saturday, May 12, 12
Saturday, May 12, 12
Saturday, May 12, 12
Saturday, May 12, 12
Saturday, May 12, 12
Saturday, May 12, 12
Saturday, May 12, 12
My Software Saturday, May 12, 12
Saturday, May 12, 12
Saturday, May 12, 12
• PSGI • Plack • cpanminus • carton Saturday, May
12, 12
PSGI Saturday, May 12, 12
Perl Server Gateway Interface Saturday, May 12, 12
Inspired by WSGI, Rack Saturday, May 12, 12
WSGI (PEP-333) Saturday, May 12, 12
Saturday, May 12, 12
# WSGI def hello(environ, start_response): start_response(“200 OK”, [
(‘Content-‐Type’, ‘text/plain’) ]) return [“Hello World”] Saturday, May 12, 12
WSGI • Django • Bottle • CherryPy • Tornado •
Pylons • Flask • mod_wsgi • Paste • gunicorn • uWSGI • wsgiref • Google AppEngine Saturday, May 12, 12
WSGI WSGI middleware Django Bottle Flask Tornado Apache lighttpd nginx
mod_wsgi wsgi handlers GAE Saturday, May 12, 12
Rack Saturday, May 12, 12
Saturday, May 12, 12
# Rack class Hello def call(env)
return [ 200, { “Content-‐Type” => ”text/plain” }, [“Hello World”] ] end end Saturday, May 12, 12
Rack • Rails • Merb • Sinatra • Camping •
Ramaze • etc. • Unicorn • Thin • Mongrel • Rainbows! • Phusion Passenger • Heroku Saturday, May 12, 12
Rack Rack middleware Rails Merb Sinatra Ramaze Apache lighttpd Thin
Unicorn Rack handlers Mongrel Saturday, May 12, 12
PSGI Perl Web Server Gateway Interface Saturday, May 12, 12
Interface Saturday, May 12, 12
# WSGI def hello(environ, start_response): start_response(“200 OK”, [
(‘Content-‐Type’, ‘text/plain’) ]) return [“Hello World”] Saturday, May 12, 12
# Rack class Hello def call(env)
return [ 200, { “Content-‐Type” => ”text/plain” }, [“Hello World”] ] end end Saturday, May 12, 12
# PSGI my $app = sub {
my $env = shift; return [ 200, [ ‘Content-‐Type’, ‘text/plain’ ], [ ‘Hello World’ ], ]; }; Saturday, May 12, 12
That’s it. Saturday, May 12, 12
# PSGI my $app = sub {
my $env = shift; return [ 200, [ ‘Content-‐Type’, ‘text/plain’ ], [ ‘Hello World’ ], ]; }; Saturday, May 12, 12
Now you’ve got a PSGI application. Saturday, May 12, 12
PSGI makes it so simple to: Saturday, May 12, 12
Write a new Perl web app & framework Saturday, May
12, 12
Write a new Perl web server Saturday, May 12, 12
CGI::Application Apache IIS lighttpd CGI.pm CGI fastcgi mod_perl Jifty Mason
Catalyst Mason::CGIHandler Catalyst::Engine nginx HTTP::Server ::Simple Saturday, May 12, 12
PSGI Plack::Middleware Catalyst CGI::App Jifty Dancer Apache lighttpd HTTP::Server::PSGI Twiggy
Starman Plack::Handler::* (CGI, FCGI, Apache) Saturday, May 12, 12
# Catalyst use MyApp; MyApp-‐>setup_engine(‘PSGI’); my $app = sub {
MyApp-‐>run(@_) }; # $app is a PSGI app! Saturday, May 12, 12
# Jifty use MyPonyApp; my $app = MyPonyApp-‐>psgi_app; # $app
is a PSGI app! Saturday, May 12, 12
# Dancer use Dancer; get ‘/’ => sub {
“Hello World”; }; dance; # returns a PSGI app! Saturday, May 12, 12
# Mojolicious::Lite use Mojolicious::Lite; get ‘/:name’ => sub {
my $self = shift; $self-‐>render_text(‘Hello!’); }; app-‐>start; # returns PSGI app Saturday, May 12, 12
# Web::Simple use Web::Simple ‘MyApp’; package MyApp; dispatch {
sub(GET) { [ 200, [...], [ ‘Hello’ ] ]; } }; my $app = MyApp-‐>as_psgi; # $app is a PSGI app! Saturday, May 12, 12
Saturday, May 12, 12
Recap: PSGI • Inspired by Python, Ruby • Very simple
• Code ref, hash ref, array ref • adapted by many frameworks and businesses Saturday, May 12, 12
cpanminus Saturday, May 12, 12
Saturday, May 12, 12
Dead easy to install Sane defaults Ultra-lightweight Saturday, May 12,
12
> curl -‐L cpanmin.us |\ perl -‐ App::cpanminus Saturday,
May 12, 12
Saturday, May 12, 12
-‐-‐installdeps Saturday, May 12, 12
PSGI/Plack convention for writing apps Saturday, May 12, 12
cpanm --installdeps convention for installing deps Saturday, May 12, 12
PSGI/Plack + cpanminus = ? Saturday, May 12, 12
Saturday, May 12, 12
Step 1: Write your app in PSGI (with PSGI-compatible framework)
Saturday, May 12, 12
Step 2: Maintain dependencies in git with Makefile.PL/Build.PL Saturday, May
12, 12
Step 3: Run your code on the cloud via git
push! Saturday, May 12, 12
Saturday, May 12, 12
http://showmetheco.de/articles/2011/8/three-perl-cloud-hosting-platforms.html Saturday, May 12, 12
Heroku buildpacks • judofyr/perloku • miyagawa/heroku-buildpack-perl • lstoll/heroku-buildpack-perl Saturday, May
12, 12
Saturday, May 12, 12
Saturday, May 12, 12
Saturday, May 12, 12
DIY https://github.com/dagolden/perl-chef Saturday, May 12, 12
Recap • PSGI: web app standard • cpanm: dependencies installation
• PSGI + cpanm => Deploy to the cloud! Saturday, May 12, 12
Problems Saturday, May 12, 12
Step 2: Maintain dependencies in git with Makefile.PL/Build.PL Saturday, May
12, 12
Makefile.PL Saturday, May 12, 12
use ExtUtils::MakeMaker; WriteMakefile( NAME => ‘MyModule’, VERSION =>
‘1.22’, PREREQ_PM => { ‘JSON’ => 0, ‘Hash::MultiValue’ => ‘0.11’, }, ); Saturday, May 12, 12
use Module::Build; my $build = Module::Build-‐>new( module_name => ‘MyModule’,
requires => { ‘JSON’ => ‘2.00’, ‘Hash::MultiValie’ => ‘0.20’, }, ); $build-‐>create_build_script; Saturday, May 12, 12
use inc::Module::Install; name ‘MyApp’; all_from ‘lib/MyApp.pm’; requires ‘JSON’, ‘2.00’; requires
‘Hash::MultiValue’ => 0.10; WriteAll; Saturday, May 12, 12
Problem 1) Lots of boilerplate Saturday, May 12, 12
use ExtUtils::MakeMaker; WriteMakefile( NAME => ‘MyModule’, VERSION =>
‘1.22’, PREREQ_PM => { ‘JSON’ => 0, ‘Hash::MultiValue’ => ‘0.11’, }, ); Saturday, May 12, 12
use Module::Build; my $build = Module::Build-‐>new( module_name => ‘MyModule’,
requires => { ‘JSON’ => ‘2.00’, ‘Hash::MultiValie’ => ‘0.20’, }, ); $build-‐>create_build_script; Saturday, May 12, 12
use inc::Module::Install; name ‘MyApp’; all_from ‘lib/MyApp.pm’; requires ‘JSON’, ‘2.00’; requires
‘Hash::MultiValue’ => 0.10; WriteAll; Saturday, May 12, 12
Bootstrapping inc/Module/Install.pm in git configure_requires META.yml Saturday, May 12, 12
Problem 2) No way to freeze dep versions Saturday, May
12, 12
‘MooseX::Foo’ => 1.0 means MooseX::Foo with 1.0 or newer Saturday,
May 12, 12
cpanm -‐-‐installdeps Installs the latest version of modules that satisfies
the requirements Saturday, May 12, 12
What if ... Saturday, May 12, 12
• Jul 2nd: Started working on project • using Web::Framework
1.1 • Jul 9th: Finished version 1.0 • Jul 10-15th: internal beta, QA • Jul 16th: Deploy to the cloud/production Saturday, May 12, 12
• Jul 2nd: Started working on project • using Web::Framework
1.1 • Jul 9th: Finished version 1.0 • Jul 10-15th: internal beta, QA • Jul 16th: Web::Framework 1.2 is released • Jul 16th: Deploy to the cloud/production Saturday, May 12, 12
Web::Framework 1.2 broke my code! Saturday, May 12, 12
Saturday, May 12, 12
Makefile.PL Recap • Not so easy to write • Could
have deps, bootstrapping issue • No way to freeze versions Saturday, May 12, 12
A solution Saturday, May 12, 12
cpanfile + Carton Saturday, May 12, 12
requires ‘Plack’, 0.9980; requires ‘Catalyst’, ‘>= 5.8, < 5.9’; conflicts
‘MooseX::Foo’, ‘< 0.10’; on ‘test’ => sub { requires ‘Test::More’, 0.80; }; on ‘develop’ => sub { requires ‘Devel::NYTProf’; }; Saturday, May 12, 12
inspired by: gemfile(5) Saturday, May 12, 12
Backward compatible to: Module::Install(::DSL) Saturday, May 12, 12
Converted to to: CPAN::Meta::Prereqs Saturday, May 12, 12
Toolset Module::CPANfile Module::Install::CPANfile Saturday, May 12, 12
Supported by Dist::Zilla & Carton Saturday, May 12, 12
Carton https://github.com/miyagawa/carton Saturday, May 12, 12
Manages CPAN deps Saturday, May 12, 12
Inspired by... Saturday, May 12, 12
Saturday, May 12, 12
• App-specific local environment • Fast and safe install •
Dep-tree analysis, including versions • Locking module versions • Easy Redeployment • Single-file, VCS friendly • Safe and easy rollback Saturday, May 12, 12
Local perl environment Using local::lib and cpanm -L Each app
has an isolated local library path Saturday, May 12, 12
Fast and safe install cpanm 1.5 Saves MYMETA.json and install
meta info Saturday, May 12, 12
Dep tree analysis Rebuild the dependency tree from meta info
Checks if anything is missing/superfluous Saturday, May 12, 12
Locking versions Versions are saved in carton.lock including dependencies Saturday,
May 12, 12
Easy Redeployment Reinstall exactly the same set of modules on
another prod/development machines. Saturday, May 12, 12
Single-file, VCS friendly You can add carton.lock to git update
whenever you update modules Saturday, May 12, 12
Safe and easy rollback revert the lock file and redeploy
Saturday, May 12, 12
DEMO Saturday, May 12, 12
> cpanm Carton Saturday, May 12, 12
WARNING It is pre-1.0 beta software, some features are missing
or not working correctly (yet). Saturday, May 12, 12
TODO / Roadmap • Update specific modules • Make install
and bundle faster • Inject old versions / patched versions • Install from git SHA Saturday, May 12, 12
Recap • Write app in PSGI/Plack • Specify CPAN dependencies
with cpanfile • Manage them and deploy with carton • Inspired by Ruby :) Saturday, May 12, 12
github.com/miyagawa/carton irc.perl.org #carton Saturday, May 12, 12
Saturday, May 12, 12
Questions? Saturday, May 12, 12
спасибо! speakerdeck.com/u/miyagawa Saturday, May 12, 12