OSDN Git Service

【更新内容】
[ring-lang-081/ring.git] / docs / en / source / deployincloud.txt
1 .. index:: 
2         single: Deploying Web Applications in the Cloud; Introduction
3
4 =======================================
5 Deploying Web Applications in the Cloud
6 =======================================
7
8 In this chapter we will learn about deploying Ring Web Applications in the Cloud using Heroku
9
10 .. index:: 
11         pair: Deploying Web Applications in the Cloud; Introduction
12
13 Introduction
14 ============
15
16 We created a new project and tutorial to explain how to deploy Ring web applications in the Cloud using Heroku
17
18 Demo : http://testring.herokuapp.com/
19
20 Project : https://github.com/ring-lang/RingWebAppOnHeroku
21
22 Heroku Website : https://www.heroku.com/
23
24 .. image:: ringincloud.png
25         :alt: Ring Web Application in the Cloud
26
27 .. index:: 
28         pair: Deploying Web Applications in the Cloud; Usage
29
30 Usage
31 =====
32
33 To use this project and deploy it on Heroku
34
35 (1) Create Heroku account
36
37 (2) Open your Heroku account and create new application
38
39 Example : testring
40
41 Note (You have to select a unique name for your application)
42
43 (3) Open the command prompt, Create new folder : MyApp
44
45 .. code-block:: none
46
47         md MyApp
48
49 (4) Open the application folder
50
51 .. code-block:: none
52
53         cd MyApp        
54
55 (5) Clone this projet using Git (Don't forget the dot in the end to clone in the current directory)
56
57 .. code-block:: none
58
59         git clone https://github.com/ring-lang/RingWebAppOnHeroku .
60
61 (6) Login to Heroku (Enter your Email and Password)
62
63 .. code-block:: none
64
65         heroku login
66
67 (7) Add heroku (remote) to your Git project
68
69 change testring to your application name
70
71 .. code-block:: none
72
73         heroku git:remote -a testring
74
75 (8) Set the buildpacks (So Heroku can know how to support your project)
76
77 .. code-block:: none
78
79         heroku buildpacks:add --index 1 https://github.com/ring-lang/heroku-buildpack-apt
80         heroku buildpacks:add --index 2 https://github.com/ring-lang/heroku-buildpack-ring
81
82 (9) Now build your project and deploy it
83
84 .. code-block:: none
85
86         git push heroku master
87
88 (10) Test your project (In the browser)
89
90 .. code-block:: none
91
92         heroku open
93
94 .. index:: 
95         pair: Deploying Web Applications in the Cloud; Ring source code files and permissions
96
97 Ring source code files and permissions
98 ======================================
99
100 To be able to run your new Ring scripts, Set the permission of the file to be executable using Git
101
102 For example, if you created a file : myscript.ring
103
104 .. code-block:: none
105
106         git update-index --chmod=+x myscript.ring 
107         git commit -m "Update file permission"  
108
109 If you are using TortoiseGit, From windows explorer, select the file
110
111 Right click ---> Properties ---> Git ---> Executable (+x)
112
113 Then commit and deploy!
114
115 .. index:: 
116         pair: Deploying Web Applications in the Cloud; Hello World program
117
118 Hello World program
119 ===================
120
121 file : ringapp/helloworld.ring
122
123 To run it : http://testring.herokuapp.com/ringapp/helloworld.ring
124
125 .. code-block:: ring
126
127         #!/app/runring.sh -cgi
128
129         see "content-type: text/html" +nl+nl    
130         see "Hello, World!" + nl
131
132 file : ringapp/helloworld2.ring
133
134 To run it : http://testring.herokuapp.com/ringapp/helloworld2.ring
135
136 .. code-block:: ring
137
138         #!/app/runring.sh -cgi
139         load "weblib.ring"
140         import System.Web
141         new page {
142                 text("Hello, World!")
143         }
144
145 .. index:: 
146         pair: Deploying Web Applications in the Cloud; Application Database
147
148 Application Database
149 ====================
150
151 When you depoly the application, Everything will works directly!
152
153 No change is required, but in practice, You will need to update the next files to use your database
154
155 There are two scripts to interact with the database (We are using PostgreSQL in the cloud)
156
157 You will need to update the connection string in these files if you will use another database
158
159 * file: ringapp/database/newdb.ring (We run it using the browser for one time to create the tables)
160 * file: ringapp/datalib.ring (Class: Database)
161
162 In your practical projects, You can write better code (To be able to change the database)
163
164 Also you can create configuration file (To write the connection string in one place)
165
166 Database service : https://www.heroku.com/postgres
167
168 .. index:: 
169         pair: Deploying Web Applications in the Cloud; Deploying after updates
170
171 Deploying after updates
172 =======================
173
174 Just use Git and commit then push to heroku
175
176 file: build.bat contains the next commands for quick tests
177
178 .. code-block:: none
179
180         git add .
181         git commit -m "Update RingWebAppOnHeroku"
182         git push heroku master
183         heroku open
184
185 .. index:: 
186         pair: Deploying Web Applications in the Cloud; Local Tests
187
188 Local Tests
189 ===========
190
191 Local tests using Ring Notepad on Windows (Using local Apache Web Server)
192
193 Replace the first line in the file : ringapp/index.ring with
194
195 .. code-block:: ring
196
197         #!ring -cgi 
198         
199 Then run it from Ring Notepad (Ctrl+F6)