OpenShift Perl Dancer.pm 筆記


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 顯示可選用的服務類型
rhc cartridge list

# 建立一個應用
rhc app create [APP_NAME] -t [類型]
rch app create [APP_NAME] -t perl-5.10

# 先打開瀏覽器測試一下
http://[APP_NAME]-$yournamespace.rhcloud.com

# 進入已 Clone 的目錄
cd [APP_NAME]

# 修改 deplist.txt, 加入依賴套件
Dancer
Plack::Runner
YAML
Template::Toolkit
Dancer::Plugin::FlashMessage
Dancer::Plugin::DBIC
DBIx::Class::Schema::Loader
Dancer::Plugin::EscapeHTML
Text::Trim Email::Valid
Plack::Middleware::Session
Plack::Middleware::CSRFBlock
Plack::Handler::Starman
Plack::Middleware::ReverseProxy
Plack::Middleware::Debug
JavaScript::Minifier::XS
CSS::Minifier::XS
Image::Resize Image::Size

# 將原先的 Dancer 專案複製到根目錄
# 以 SimpleAlbum 為例
cp ../git/Perl-SimpleAlbum .

# 建立 lib 的連接
ln -s SimpleAlbum/public perl

cd libs
ln -s ../SimpleAlbum/lib/SimpleAlbum.pm .

cd ..

# 刪除 Perl 目錄
git rm -r perl

# 複制出 index.pl
cd perl
cp dispatch.cgi index.pl

# 修改 index.pl
#!/usr/bin/env perl
use Dancer ':syntax';
use Plack::Runner;

# For some reason Apache SetEnv directives dont propagate
# correctly to the dispatchers, so forcing PSGI and env here
# is safer.
set apphandler => 'PSGI';
set environment => 'production';

my $psgi = path($ENV{'DOCUMENT_ROOT'}, '..', 'myapp', 'bin', 'app.pl');
die "Unable to read startup script: $psgi" unless -r $psgi;

Plack::Runner->run($psgi);

# 提交
git add -A
git commit -m 'lets dance'
git push