DotCloudのほんのさわり

Nagoya.pm #1 (2011-09-17)
岩田 享 / @issm

DotCloudのほんのさわり

Nagoya.pm #1 (2011-09-17)
岩田 享 / @issm

おまえだれよ?

アジェンダ

 

DotCloudって?

 

インストール

      % easy_install dotcloud
    

 

準備

APIキーを設定する

      % dotcloud
      Warning: /Users/issm/.dotcloud/dotcloud.conf does not exist.
      Enter your api key (You can find it at http://www.dotcloud.com/accounts/settings):
    

https://www.dotcloud.com/settings/

準備

~/.dotcloud/dotcloud.conf

{
    "url":    "https://api.dotcloud.com/",
    "apikey": "********"
}
    

準備

環境変数 $DOTCLOUD_CONFIG_FILE

      % DOTCLOUD_CONFIG_FILE=issm.conf dotcloud ...
      % DOTCLOUD_CONFIG_FILE=nagoyapm.conf dotcloud ...
    

 

Hello world

アプリケーションを作成する

      % dotcloud create helloapp
      Created application "helloapp"
    

Hello world

dotcloud.yml を作成する

      www:
          type: perl
    

Hello world

簡単なPSGIファイル app.psgi を作成する

use strict;
return sub {
    my $env = shift;

    return [
        200,
        [ 'Content-Type' => 'text/html; charset=utf-8' ],
        [ << '...' ],

Hello

Hello, DotCloud.

Hello, PSGI.

... ]; };

Hello world

デプロイ!

      % cd /path/to/helloapp
      % dotcloud push helloapp .
    

Hello world

何か始まる

% dotcloud push helloapp .
# upload /Users/issm/projects/dotcloud/issm.dc ssh://dotcloud@uploader.dotcloud.com:443/helloapp
# rsync
Pseudo-terminal will not be allocated because stdin is not a terminal.
building file list ... done
./
deleting Makefile.PL
app.psgi

sent 300 bytes  received 40 bytes  61.82 bytes/sec
total size is 246  speedup is 0.72
Deployment for "helloapp" triggered. Will be available in a few seconds.
2011-09-16 21:38:57 [api] Deploy helloapp scheduled for revision=latest
2011-09-16 21:38:57 [api] Waiting for the build. (It may take a few minutes)
2011-09-16 21:38:57 [api] All the services are ready. Beginning the build.
2011-09-16 21:38:58 [www.0] The build started
2011-09-16 21:38:58 [www.0] Fetched code revision rsync-1316209136.68
2011-09-16 21:39:00 [www.0] Reloading nginx configuration: nginx.
2011-09-16 21:39:05 [www.0] uwsgi: stopped
2011-09-16 21:39:05 [www.0] uwsgi: started
2011-09-16 21:39:05 [www.0] The build finished successfully
2011-09-16 21:39:05 [api] Deploy finished

Deployment finished. Your application is available at the following URLs
www: http://helloapp-issm.dotcloud.com/
    

Hello world

http://helloapp-issm.dotcloud.com/

 

非標準モジュールをインストールする

Makefile.PL を準備する

use inc::Module::Install;

name 'issm-helloapp';
version '0.01';

requires 'Text::Xslate';  # インストールするモジュール

WriteAll;
    

非標準モジュールをインストールする

Makefile.PL を実行する

% perl Makefile.PL
include /Users/issm/projects/dotcloud/issm.dc/inc/Module/Install.pm
include inc/Module/Install/Metadata.pm
include inc/Module/Install/Base.pm
include inc/Module/Install/WriteAll.pm
include inc/Module/Install/Makefile.pm
include inc/Module/Install/Win32.pm
include inc/Module/Install/Can.pm
include inc/Module/Install/Fetch.pm
Writing Makefile for issm::helloapp
Writing META.yml
No license specified, setting license = 'unknown'
    

非標準モジュールをインストールする

% dotcloud push helloapp .
    
...
2011-09-17 01:08:26 [www.0] --> Working on .
2011-09-17 01:08:26 [www.0] Configuring /home/dotcloud/git-610f933 ... OK
2011-09-17 01:08:26 [www.0] ==> Found dependencies: Text::Xslate
2011-09-17 01:08:27 [www.0] --> Working on Text::Xslate
2011-09-17 01:08:27 [www.0] Fetching http://search.cpan.org/CPAN/authors/id/G/GF/GFUJI/Text-Xslate-1.5002.tar.gz ... OK
2011-09-17 01:08:28 [www.0] Configuring Text-Xslate-1.5002 ... OK
2011-09-17 01:08:28 [www.0] ==> Found dependencies: Any::Moose, Mouse, Data::MessagePack
2011-09-17 01:08:28 [www.0] --> Working on Any::Moose
2011-09-17 01:08:28 [www.0] Fetching http://search.cpan.org/CPAN/authors/id/S/SA/SARTAK/Any-Moose-0.17.tar.gz ... OK
2011-09-17 01:08:29 [www.0] Configuring Any-Moose-0.17 ... OK
2011-09-17 01:08:29 [www.0] ==> Found dependencies: Mouse
2011-09-17 01:08:29 [www.0] --> Working on Mouse
2011-09-17 01:08:35 [www.0] Fetching http://search.cpan.org/CPAN/authors/id/G/GF/GFUJI/Mouse-0.93.tar.gz ... OK
2011-09-17 01:08:36 [www.0] Configuring Mouse-0.93 ... OK
2011-09-17 01:08:41 [www.0] Building Mouse-0.93 ... OK
2011-09-17 01:08:41 [www.0] Successfully installed Mouse-0.93
2011-09-17 01:08:41 [www.0] Building Any-Moose-0.17 ... OK
2011-09-17 01:08:41 [www.0] Successfully installed Any-Moose-0.17
2011-09-17 01:08:41 [www.0] --> Working on Data::MessagePack
2011-09-17 01:08:42 [www.0] Fetching http://search.cpan.org/CPAN/authors/id/G/GF/GFUJI/Data-MessagePack-0.36.tar.gz ... OK
2011-09-17 01:08:42 [www.0] Configuring Data-MessagePack-0.36 ... OK
2011-09-17 01:08:44 [www.0] Building Data-MessagePack-0.36 ... OK
2011-09-17 01:08:44 [www.0] Successfully installed Data-MessagePack-0.36
2011-09-17 01:08:47 [www.0] Building Text-Xslate-1.5002 ... OK
2011-09-17 01:08:47 [www.0] Successfully installed Text-Xslate-1.5002
...
    

非標準モジュールをインストールする

おめでとう! Text::Xslate は無事インストールされました!

 

with MySQL

Makefile.PL を修正する

use inc::Module::Install;

name 'issm-helloapp';
version '0.01';

requires 'Text::Xslate';
requires 'DBI';            # <--
requires 'DBD::mysql';     # <--

WriteAll;
    

with MySQL

dotcloud.yml を修正する

www:
    type: perl
db:               # <--
    type: mysql   # <--
    

ここで一度 push する

with MySQL

% dotcloud list
    
helloapp:
  - db  (type: mysql; instances: 1)
  - www (type: perl; instances: 1)
    

with MySQL

% dotcloud info helloapp.db
    
cluster: wolverine
config:
    mysql_password: {mysql_password}
created_at: 1316223755.761884
image_version: 57db01da2848 (latest)
ports:
-   name: ssh
    url: ssh://mysql@helloapp-issm.dotcloud.com:{ssh_port}
-   name: mysql
    url: mysql://root:{mysql_password}@helloapp-issm.dotcloud.com:{mysql_port}
state: running
type: mysql
    

with MySQL

use strict;
use Text::Xslate;
use DBI;
return sub {
    my $env = shift;
    my $dbh = DBI->connect(
        'dbi:mysql:mysql:helloapp-issm.dotcloud.com:{mysql_port}',
        'root',
        '{mysql_password}',
    );
    my $sel = $dbh->selectall_arrayref('SHOW DATABASES');
    my %vars = (
        sel => $sel,
    );
    my $tx = Text::Xslate->new;
    my $body = $tx->render_string( << '    ...', \%vars );
<h1>Hello</h1>
<p>Hello, DotCloud.</p>
<h2>databases</h2>
<ul>
: for $sel -> $i {
  <li><code><: $i[0] :></code></li>
: }
</ul>
    ...

    return [
        200,
        [ 'Content-Type' => 'text/html; charset=utf-8' ],
        [ $body ],
    ];
};
    

with MySQL

with MySQL

注意!

 

利用可能の上限

 

DotCloudコマンドいくつか

% dotcloud -h
    
error: usage: dotcloud [-h]

                {info,status,stats,run,logs,versions,url,setup,list,rollback,alias,ssh,push,destroy,create,restart,history}
                ...

Command line tool to interact with dotcloud

positional arguments:
  {info,status,stats,run,logs,versions,url,setup,list,rollback,alias,ssh,push,destroy,create,restart,history}
    setup               setup your api key
    history             display the last commands you ran
    create              create an application
    push                push your application
    list                list your applications
    versions            list the versions of your application
    run                 run a remote command
    logs                read logs
    alias               bind a custom domain name to a service
    destroy             destroy your application
    url                 display URL(s) of your application
    info                get information about your application or service
    status              check the status
    stats               display the HTTP stats of your service
    rollback            rollback your service to the previous pushed version
    ssh                 open an SSH session
    restart             restart your service

optional arguments:
  -h, --help            show this help message and exit
    

DotCloudコマンドいくつか

create / destroy

% dotcloud create hogeapp
Created application "hogeapp"
    
% dotcloud destroy hogeapp
Please confirm destruction [yn]: y
Destroy for "hogeapp" triggered.
    

DotCloudコマンドいくつか

list

% dotcloud list
    
helloapp:
  - www (type: perl; instances: 1)
    

DotCloudコマンドいくつか

url

      % dotcloud url helloapp
    
      www: http://helloapp-issm.dotcloud.com/
    

DotCloudコマンドいくつか

info

% dotcloud info helloapp.www
    
aliases:
- helloapp-issm.dotcloud.com
- dc.iss.ms
build_revision: git-03775a1
cluster: wolverine
config:
    path: /
    plack_env: deployment
    static: static
    uwsgi_processes: 4
created_at: 1316207648.519671
image_version: 87ce0731fd95 (latest)
ports:
-   name: ssh
    url: ssh://dotcloud@helloapp-issm.dotcloud.com:{ssh_port}
-   name: http
    url: http://helloapp-issm.dotcloud.com/
-   name: http
    url: http://dc.iss.ms/
state: running
type: perl
    

DotCloudコマンドいくつか

ssh

      % dotcloud ssh helloapp.www
    
# $SHELL
dotcloud@helloapp-default-www-0:~$ perl -v

This is perl 5, version 12, subversion 3 (v5.12.3) built for x86_64-linux-thread-multi

Copyright 1987-2010, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

dotcloud@helloapp-default-www-0:~$ 
    

DotCloudコマンドいくつか

alias

% dotcloud alias add helloapp.www dc.iss.ms
Ok. Now please add the following DNS record:
dc.iss.ms. IN CNAME gateway.dotcloud.com.
    
% dotcloud url helloapp
www: http://helloapp-issm.dotcloud.com/
www: http://dc.iss.ms/
    

DotCloudコマンドいくつか

DotCloudコマンドいくつか

logs

% dotcloud logs helloapp.www
    
#  tail -F /var/log/{supervisor,nginx}/*.log 
==> /var/log/supervisor/supervisord.log <==
...

==> /var/log/supervisor/uwsgi.log <==
...

==> /var/log/nginx/access.log <==
...

==> /var/log/nginx/error.log <==
...

==> /var/log/nginx/helloapp-default-www-0.access.log <==
...

==> /var/log/nginx/helloapp-default-www-0.error.log <==
...
    

 

まとめ

DotCloudについて簡単に紹介

Any Questions?