Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: src/site/codelabs/deploy/index.markdown

Issue 138823002: Draft of new codelab for review (Closed) Base URL: https://github.com/dart-lang/dartlang.org.git@master
Patch Set: adding DevTools section and other changes from Kathy Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/site/codelabs/deploy/images/wee-arrow.png ('k') | src/site/css/dart-style.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 ---
2 layout: tutorial
3 title: "Code Lab: Deploy the Pirates"
4 description: "Deploy your Dart app to the internet."
5 has-permalinks: true
6 tutorial:
7 id: buildanddeploy
8 js:
9 - url: /js/os-switcher.js
10 defer: true
11 - url: /js/editor-downloads-analytics.js
12 defer: true
13 - url: /js/editor-version.js
14 defer: true
15 header:
16 css: ["/codelabs/darrrt/darrrt.css"]
17 ---
18
19 # {{ page.title }}
20
21
22 After you write a web app,
23 you need to put it on the internet so that people can use it.
sethladd 2014/01/17 00:07:23 s/internet/web
mem 2014/01/17 21:33:59 Done.
24
25 In this code lab,
26 you learn to deploy an app to the internet using the
sethladd 2014/01/17 00:07:23 how about, "You will learn how to build a Dart app
mem 2014/01/17 21:33:59 Done.
27 <a href="https://devcenter.heroku.com/">Heroku</a>
28 hosting service.
29 Heroku is just one of many options
30 you could choose for deploying an app.
31 Other options include
32 Google App Engine and Amazon Web Services.
33
34 In this code lab, you deploy the Pirate Badge app from the
sethladd 2014/01/17 00:07:23 In this code lab leads two paragraphs
mem 2014/01/17 21:33:59 Done.
35 [Pirate Convention](/codelabs/darrrt/) code lab.
36 By doing so, you learn how to build the app for deployment,
37 how to write a basic static file server,
38 how to inspect, test, and debug your app on a mobile device using DevTools,
39 and finally, how to deploy to Heroku.
40
41 ![The process for deploying a Web app](images/process.png)
42
43 This code lab assumes that you have written and run
44 a Dart web app before.
45 If you have not, consider doing the
46 [Pirate Convention](/codelabs/darrrt/) code lab.
47
48 <hr>
49
50 <div markdown="1">
51
52 ## Table of Contents
53
54 * [Step 0: Set up](#step-zero)
55 * [Step 1: Run the app in Dart Editor](#step-one)
56 * [Step 2: Build the app and run as JavaScript](#step-two)
57 * [Step 3: Build a static server](#step-three)
58 * [Step 4: Inspect your app on a mobile device](#step-four)
59 * [Step 5: Deploy to Heroku](#step-five)
60 * [Step 6: Run the app online and mobile](#step-six)
61 * [Resources](#resources)
62 * [What next?](#what-next)
63
64 </div>
65
66 <hr>
67
68 ##Step 0: Set up {#step-zero}
69
70 In this step, you download Dart and get the code for the app that you will be de ploying.
71 This code lab uses Dart Editor.
72
73 ### <i class="fa fa-anchor"> </i> Get Dart.
74
75 <div class="trydart-step-details" markdown="1">
76 If you haven't already done so,
77 get the Dart download.
78 Unzip the ZIP file, which creates a directory called `dart`.
79
80 <!--style here is a hack to remove the arrow, which was only partially showing. -->
81 <div style="padding-left: 10px">
82 {% include downloads/_dart-editor.html buttonclass="btn btn-primary btn-lg" %}
83 </div>
84
85 <p class="os-choices" markdown="1">
86 The Dart tools
87 work in recent versions of
88 {% include os-choices.html %}
89 </p>
90 </div>
91
92 ### <i class="fa fa-anchor"> </i> Start Dart Editor.
93
94 <div class="trydart-step-details" markdown="1">
95 Go to the `dart` directory and double-click **DartEditor**.
96
97 **Got questions? Having trouble?** Go to the
98 [Troubleshooting Dart Editor](/tools/editor/troubleshoot.html) page.
99
100 </div>
101
102 ### <i class="fa fa-anchor"> </i> Get the code.
103
104 <div class="trydart-step-details" markdown="1">
105 <a href="https://github.com/marycampione/deploy-codelab/archive/master.zip">Down load</a>
106 the code for the app that you will deploy.
107 Unzip the ZIP file,
108 which creates a directory called `deploy-codelab-master`.
109 </div>
110
111 ### <i class="fa fa-anchor"> </i> Open deploy-codelab-master.
112
113 <div class="trydart-step-details" markdown="1">
114 In Dart Editor,
115 use **File > Open Existing Folder...**
116 to open the `deploy-codelab-master` directory.
117 </div>
118
119 <div class="row"> <div class="col-md-7" markdown="1">
120
121 ![The files and directories in the deploy-codelab-master directory](images/files anddirs.png)
122
123 </div> <div class="col-md-5" markdown="1">
124
125 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
126
127 * The `packages` directory, as well as the `pubspec.yaml` and `pubspec.lock` fil es are
128 related to package dependencies.
129 This project has all the dependencies set up for you.
130 Dart Editor automatically installs the necessary packages.
131
132 * The `web` directory contains the Pirate Badge app to deploy.
133
134 * The `bin` directory contains the code for a static file server.
135 You can use the server for testing and debugging your app
136 on your local machine and on mobile.
137 Also Heroku requires a server with your project.
138
139 &nbsp; {% comment %} non-breaking space required for bootstrap/markdown bogosity {% endcomment %}
140
141 </div> </div>
142
143 <hr>
144
145 ##Step 1: Run the app in Dart Editor {#step-one}
sethladd 2014/01/17 00:07:23 Is it running in Dart Editor or Dartium?
mem 2014/01/17 21:33:59 Done.
146
147 Open the code for the Pirate Badge web app and run it locally.
148
149 ### <i class="fa fa-anchor"> </i> Expand the `web` directory.
150
151 <div class="trydart-step-details" markdown="1">
152 In Dart Editor, expand the `web` directory
153 by clicking the little arrow
154 ![wee arrow](images/wee-arrow.png) to the left of its name.
155 The directory contains four files:
156
157 ![Files for the app to deploy](images/appfiles.png)
158
159 </div>
160
161 ### <i class="fa fa-anchor"> </i> Look at `piratebadge.html`.
162
163 <div class="row"> <div class="col-md-7">
164
165 <div class="trydart-step-details" markdown="1">
166
167 Double-click `piratebadge.html` to open it.
168
169 {% prettify html %}
170 ...
171 <head>
172 <meta charset="utf-8">
173 <title>Pirate badge</title>
174 [[highlight]]<meta name="viewport" content="width=device-width, initial-scale= 1.0">[[/highlight]]
175 <link rel="stylesheet" href="piratebadge.css">
176 </head>
177 <body>
178 ...
179 [[highlight]]<script src="packages/browser/dart.js"></script>[[/highlight]]
180 ...
181 </body>
182 ...
183 {% endprettify %}
184
185 </div>
186
187 <div class="trydart-filename">piratedbadge.dart</div>
188
189 </div> <div class="col-md-5" markdown="1">
190
191 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
192
193 * The <code>&lt;meta&gt;</code> tag sets attributes to
194 make the app scale correctly on mobile devices.
195
196 * `dart.js` is a script that determines if the browser supports Dart,
197 and if it does, runs the app natively.
198 If it does not, the script loads the JavaScript version of the app.
199
200 * `dart.js` is part of the `browser` pub package.
201
202 </div></div>
203
204 ### <i class="fa fa-anchor"> </i> Run the app.
205
206
207 <div class="row"> <div class="col-md-7">
208
209 <div class="trydart-step-details" markdown="1">
210
211 Select `piratebadge.html`
212 and click the Run button
213 <img src="images/run.png" width="16" height="16"
214 alt="Run button">.
215
216 ![Click the run button](images/runtheapp.png)
Shams 2014/01/17 17:23:09 It failed to run. I had to manually do a "pub get"
mem 2014/01/17 21:33:59 Done.
217
218 </div>
219
220 </div> <div class="col-md-5" markdown="1">
221
222 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
223
224 * Dart Editor launches *Dartium*, a special build of Chromium
225 that has the Dart Virtual Machine built in, and loads the app.
226
227 </div></div>
228
229 <div class="row"> <div class="col-md-7">
230
231
232 The Pirage Badge app should appear, looking like this:
233
234 <iframe class="running-app-frame"
235 style="height:220px;width:550px;"
236 src="/codelabs/darrrt/examples/6-piratebadge_json/piratebadge.html">
237 </iframe>
238
239
240 </div> <div class="col-md-5" markdown="1">
241
242 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
243
244 * At this time, Dartium is the only browser that has the Dart VM built in.
245 To run a Dart app in other browsers you need to convert it to JavaScript,
246 which you do in the next step.
247
248 &nbsp; {% comment %} non-breaking space required for bootstrap/markdown bogosity {% endcomment %}
249
250 </div></div>
251
252 <hr>
253
254 ##Step 2: Build the app and run as JavaScript {#step-two}
255
256 In this step, you use `pub build` to
257 generate the assets for the app
258 and put them into a new directory named `build`.
259 In addition to other tasks,
260 this process generates minimized JavaScript that
Shams 2014/01/17 17:23:09 minimized JavaScript -> minified JavaScript
mem 2014/01/17 21:33:59 Done.
261 can be run by any modern browser.
262
263 ### <i class="fa fa-anchor"> </i> Check out pubspec.yaml
264
265 <div class="row"> <div class="col-md-7">
266
267 <div class="trydart-step-details" markdown="1">
268
269 Double-click the `pubspec.yaml` file to open it.
270
271 {% prettify dart %}
272 name: deploy_codelab
273 description: A sample deployment
274 dependencies:
275 [[highlight]]browser: any[[/highlight]]
276 [[highlight]]http_server: any[[/highlight]]
277 [[highlight]]path: any[[/highlight]]
278 {% endprettify %}
279
280 </div>
281
282 <div class="trydart-filename">pubspec.yaml</div>
283
284 </div> <div class="col-md-5" markdown="1">
285
286 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
287
288 * A `pubspec.yaml` file in a directory identifies the directory
289 and its contents as an application.
290
291 * `pubspec.yaml` configures the application
292 and lists the libraries on which the app depends.
293 The three libraries needed by this app are all hosted on
294 [pub.dartlang.org](https://pub.dartlang.org/))
295
296 * `any` selects the latest package that matches your SDK.
297
298 </div></div>
299
300 ### <i class="fa fa-anchor"> </i> Look at the packages directory
301
302 <div class="row"> <div class="col-md-7">
303
304 <div class="trydart-step-details" markdown="1">
305
306 In Dart Editor, expand the `packages` directory.
307
308 ![Packages contains the code for the package dependencies](images/packagesfiles. png)
309
310 </div>
311
312 </div> <div class="col-md-5" markdown="1">
313
314 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
315
316 * The `packages` directory contains the code for all of the dependencies
317 listed in the `pubspec.yaml` file.
318 These are installed automatically by Dart Editor.
319
320 * The `browser` package contains the `dart.js` script
321 that checks for native Dart support.
322
323 * The `http_server` package implements high-level HTTP server
324 functionality making it easier to provide content through HTTP servers.
325
326 * The `path` package provides common path manipulation operations,
327 such as joining, splitting, and normalizing.
328
329 * The `mime` package is included because `http_server` depends on it.
330
331 </div></div>
332
333 ### <i class="fa fa-anchor"> </i> Run pub build
334
335 <div class="row"> <div class="col-md-7">
336
337 <div class="trydart-step-details" markdown="1">
338
339 Bring up a terminal window,
340 change into the `deploy-codelab-master` directory,
341 and run `pub build`.
342
343 {% prettify bash %}
344 $ pub build
345 Building deploy_codelab.....
346 [Info in Dart2JS]:
347 Generated deploy_codelab|web/piratebadge.dart.js (98287 characters) in 0:00:06.2 35360
348 Built 8 files!
Shams 2014/01/17 17:23:09 Minor nit. For me it said it built 10 files.
mem 2014/01/17 21:33:59 Done.
349 $
350 {% endprettify %}
351
352 </div>
353
354 <div class="trydart-filename">terminal</div>
355
356 </div> <div class="col-md-5" markdown="1">
357
358 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
359
360 * The `pub build` command creates a `build` directory that contains
361 everything your app needs to be deployed, including a minimized
362 JavaScript file and the required packages.
363
364 </div></div>
365
366 ### <i class="fa fa-anchor"> </i> Look at the `build` directory
367
368 <div class="row"> <div class="col-md-7">
369
370 <div class="trydart-step-details" markdown="1">
371
372 The `pub build` command creates a `build` directory
373 under `deploy-codelab-master`.
374
375 ![The build directory contains everything you need to deploy.](images/builddir.p ng)
376 </div>
377
378 </div> <div class="col-md-5" markdown="1">
379
380 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
381
382 * The `piratebadge.dart.js` file is a JavaScript file that has been minimized.
383 When deployed, this file runs in the browser.
384
385 * The `packages` directory contains the package dependencies.
386
387 * Note that the `build` directory contains no `piratebadge.dart` file.
388 It is not needed to deploy the app to JavaScript.
389
390 </div></div>
391
392
393 ### <i class="fa fa-anchor"> </i> Run the app as JavaScript
394
395 <div class="row"> <div class="col-md-7">
396
397 <div class="trydart-step-details" markdown="1">
398
399 Open the app.
400 Select **File > Open File...**
401 in a browser such a Firefix or Safari
402 and select the
403 `deploy-codelab-master/build/piratebadge.html` file.
404
405 </div>
406
407 </div> <div class="col-md-5" markdown="1">
408
409 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
410
411 * The app is running on the local machine using the `file` protocol.
412 To share your app with others, you need to deploy the app to a hosting service ,
413 such as Heroku.
414
415 </div></div>
416
417 <hr>
418
419
420 ##Step 3: Build a static server {#step-three}
Shams 2014/01/17 17:23:09 This step confused me. You actually provide the st
mem 2014/01/17 21:33:59 Done.
421
422 Heroku requires that you provide a static file server with your project.
sethladd 2014/01/17 00:07:23 Can we lead with describing what a static file ser
mem 2014/01/17 21:33:59 Done.
423 Other hosting services do not, so you do not need to do this step
424 if you're deploying to a different service.
425 However, since you've come this far, why not learn how to
426 run Dart code on a server?
427
428 A server is provided with the sample code for this code lab.
429 This step walks through the code for the server,
430 which uses some interesting Dart APIs and
431 two helpful pub packages.
432
433 ### <i class="fa fa-anchor"> </i> Setting the path to the app.
434
435 <div class="row"> <div class="col-md-7" markdown="1">
436
437 <div class="trydart-step-details" markdown="1">
438
439 {% prettify dart %}
440 import 'dart:io' show File, HttpServer, [[highlight]]Platform[[/highlight]];
441 import 'dart:async' show runZoned;
442 import 'package:http_server/http_server.dart' show VirtualDirectory;
443 import 'package:path/path.dart' show [[highlight]]join, dirname;[[/highlight]]
444
445 void main() {
446 [[highlight]]// Assumes the server lives in bin/ and that `pub build` ran[[/hi ghlight]]
447 [[highlight]]var pathToBuild = join(dirname(Platform.script.toFilePath()),[[/h ighlight]]
448 [[highlight]]'..', 'build');[[/highlight]]
449
450 ...
451 }
452 {% endprettify %}
453 </div>
454
455 <div class="trydart-filename">basic_http_server.dart</div>
456
457 </div> <div class="col-md-5" markdown="1">
458
459 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
460
461 * This code assumes that `pub build` has run.
462
463 * In the next step, you will configure a Heroku buildpack
464 that runs `pub build` when you upload your app.
465
466 * This code uses `join` along with `dirname` to
467 build a path to the `build` directory
468 based on the path of the running script.
469
470 &nbsp; {% comment %} non-breaking space required for bootstrap/markdown bogosity {% endcomment %}
471
472 </div> </div>
473
474 ### <i class="fa fa-anchor"> </i> Serving `piratebadge.html`.
475
476 <div class="row"> <div class="col-md-7" markdown="1">
477
478 <div class="trydart-step-details" markdown="1">
479
480 {% prettify dart %}
481 import 'dart:io' show [[highlight]]File[[/highlight]], HttpServer, Platform;
482 import 'dart:async' show runZoned;
483 import 'package:http_server/http_server.dart' show [[highlight]]VirtualDirectory ;[[/highlight]]
484 import 'package:path/path.dart' show join, dirname;
485
486 void main() {
487 ...
488 [[highlight]]var staticFiles = new VirtualDirectory(pathToBuild);[[/highlight] ]
489 [[highlight]]staticFiles.allowDirectoryListing = true;[[/highlight]]
490 [[highlight]]staticFiles.directoryHandler = (dir, request) {[[/highlight]]
491 [[highlight]]// Redirect directory-requests to piratebadge.html file.[[/high light]]
492 [[highlight]]var indexUri = new Uri.file(dir.path).resolve('piratebadge.html ');[[/highlight]]
493 [[highlight]]staticFiles.serveFile(new File(indexUri.toFilePath()), request) ;[[/highlight]]
494 [[highlight]]};[[/highlight]]
495 ...
496 }
497 {% endprettify %}
498 </div>
499
500 <div class="trydart-filename">basic_http_server.dart</div>
501
502 </div> <div class="col-md-5" markdown="1">
503
504 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
505
506 * The `VirtualDirectory` class from the `http_server` package
507 provides a high-level interface for serving static files and directory listing s to HttpRequests.
508
509 * The code sets `allowDirectoryListing` to `true` so that all files
510 from the app can be served [xx I made that up].
511
512 * This code redirects directory requests to `piratebadge.html`,
513 which is the main HTML file for this app.
514 This works because there is only one directory.
515
516 * The `serveFile` method serves the requested static file
517 to the given HttpRequest object.
518
519 * Without the `http_server` class, this code would be longer and more complex,
520 because you would have to use the lower-level `HttpServer`, `HttpRequest`,
521 and `HttpResponse` APIs.
522
523 &nbsp; {% comment %} non-breaking space required for bootstrap/markdown bogosity {% endcomment %}
524
525 </div> </div>
526
527 ### <i class="fa fa-anchor"> </i> Using variable port numbers.
528
529 <div class="row"> <div class="col-md-7" markdown="1">
530
531 <div class="trydart-step-details" markdown="1">
532
533 {% prettify %}
534 import 'dart:io' show File, HttpServer, [[highlight]]Platform[[/highlight]];
535 import 'dart:async' show runZoned;
536 import 'package:http_server/http_server.dart' show VirtualDirectory;
537 import 'package:path/path.dart' show join, dirname;
538
539 void main() {
540 ...
541 [[highlight]]var portEnv = Platform.environment['PORT'];[[/highlight]]
542 [[highlight]]var port = portEnv == null ? 9999 : int.parse(portEnv);[[/highlig ht]]
543 ...
544 }
545 {% endprettify %}
546 </div>
547
548 <div class="trydart-filename">basic_http_server.dart</div>
549
550 </div> <div class="col-md-5" markdown="1">
551
552 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
553
554 * Heroku uses variable ports. Heroku sets the `$PORT` environment variable
555 with the port number that your app should listen to.
556
557 * This code uses the port specified in the `$PORT` environment variable,
558 if present. Otherwise, it uses port 9999.
559
560 * The `$PORT` environment variable might not be present if the server is running
561 in a non-Heroku environment.
562
563 &nbsp; {% comment %} non-breaking space required for bootstrap/markdown bogosity {% endcomment %}
564
565 </div> </div>
566
567
568 ### <i class="fa fa-anchor"> </i> Using `runZoned()`.
569
570 <div class="row"> <div class="col-md-7" markdown="1">
571
572 <div class="trydart-step-details" markdown="1">
573
574
575 {% prettify dart %}
576 import 'dart:io' show File, HttpServer, Platform;
577 import 'dart:async' show [[highlight]]runZoned[[/highlight]];
578 import 'package:http_server/http_server.dart' show VirtualDirectory;
579 import 'package:path/path.dart' show join, dirname;
580
581 void main() {
582 ...
583 [[highlight]]runZoned(() {[[/highlight]]
584 ...
585 [[highlight]]},[[/highlight]]
586 [[highlight]]onError: (e, stackTrace) => print('Oh noes! $e $stackTrace'));[[/ highlight]]
587 }
588 {% endprettify %}
589 </div>
590
591 <div class="trydart-filename">basic_http_server.dart</div>
592
593 </div> <div class="col-md-5" markdown="1">
594
595 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
596
597 * `runZoned` helps provide stability to your program.
598 It catches exceptions from all call stacks within its bounds,
599 allowing your program to continue running in spite of errors.
600
601 &nbsp; {% comment %} non-breaking space required for bootstrap/markdown bogosity {% endcomment %}
602
603 </div> </div>
604
605 ### <i class="fa fa-anchor"> </i> About HTTP requests.
606
607 <div class="row"> <div class="col-md-7" markdown="1">
608
609 <div class="trydart-step-details" markdown="1">
610
611
612 {% prettify dart %}
613 import 'dart:io' show File, [[highlight]]HttpServer[[/highlight]], Platform;
614 import 'dart:async' show runZoned;
615 import 'package:http_server/http_server.dart' show VirtualDirectory;
616 import 'package:path/path.dart' show join, dirname;
617
618 void main() {
619 ...
620 runZoned(() {
621 [[highlight]]HttpServer.bind('0.0.0.0', port).then((server) {[[/highlight]]
622 [[highlight]]server.listen(staticFiles.serveRequest);[[/highlight]]
623 [[highlight]]});[[/highlight]]
624 },
625 onError: (e, stackTrace) => print('Oh noes! $e $stackTrace'));
626 }
627 {% endprettify %}
628 </div>
629
630 <div class="trydart-filename">basic_http_server.dart</div>
631
632 </div> <div class="col-md-5" markdown="1">
633
634 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
635
636 * `HttpServer.bind()` creates an HTTP server, which responds to HTTP requests
637 for this app.
638
639 * The server binds to a host `0.0.0.0`.
640 which is is a special address that is guaranteed to receive from any network s ocket.
641 If you don't know what specific IP to listen to, you can use 0.0.0.0.
642
643 * The server listens for requests and uses the `VirtualDirectory` object
644 named `staticFiles` to handle them.
645
646 &nbsp; {% comment %} non-breaking space required for bootstrap/markdown bogosity {% endcomment %}
647
648 </div> </div>
649
650 <hr>
651
652 ##Step 4: Inspect your app on a mobile device {#step-four}
Shams 2014/01/17 17:23:09 As you know, this step didn't succeed for me using
mem 2014/01/17 21:33:59 Done.
653
654 Before deploying your app,
655 you can use the Chrome DevTools to check, debug, and modify
656 your app on a mobile device.
657 DevTools can debug Android devices natively
658 and other devices using
659 [Mobile Emulation](https://developers.google.com/chrome-developer-tools/docs/mob ile-emulation).
660
661 ### <i class="fa fa-anchor"> </i> Set up your computer and device
662
663 <div class="trydart-step-details" markdown="1">
664
665 Follow the instructions at
666 [Remote Debugging Chrome on Android](https://developers.google.com/chrome-develo per-tools/docs/remote-debugging)
667 to set up your device, Chrome, and your computer.
668
669 </div>
670
671 ### <i class="fa fa-anchor"> </i> Run the server
672
673 <div class="trydart-step-details" markdown="1">
674
675 Run the server you wrote in [Step 3](#step-three).
676 In Dart Editor, select `bin/basic_http_server.dart` and
677 and click the Run button
678 <img src="images/run.png" width="16" height="16"
679 alt="Run button">.
680
681 </div>
682
683 ### <i class="fa fa-anchor"> </i> Run the app
684
685 <div class="trydart-step-details" markdown="1">
686
687 On your computer, bring up a new window or tab in Chrome and type `0.0.0.0:9999`
688 in the URL text field. Your app displays on the page.
689
690 On your mobile device, bring up Chrome and find the
691 app's page in the list of windows and tabs.
692 Select it.
693
694 ![Your tab appears under the Chrome heading](images/tabslist.png)
sethladd 2014/01/17 00:07:23 this screenshot is too small, I can't see what you
mem 2014/01/17 21:33:59 Done.
695
696 Your app appears on the screen.
697
698 <img src="images/calebthebrave.png" height="400">
699
700 </div>
701
702 ### <i class="fa fa-anchor"> </i> Bring up Devices page
703
704 <div class="trydart-step-details" markdown="1">
705
706 In Chrome on your compouter,
sethladd 2014/01/17 00:07:23 spelling
mem 2014/01/17 21:33:59 Done.
707 click the Android icon at the right side of the window
Shams 2014/01/17 17:23:09 Maybe mention that the Android only appears if you
mem 2014/01/17 21:33:59 Done.
708 and select **View Inspection Targets**.
709
710 ![Click the Android icon](images/androidicon.png)
711
712 Your tab appears under the **Chrome** heading.
713
714 ![Your tab appears under the Chrome heading](images/tabappears.png)
715
716 </div>
717
718 ### <i class="fa fa-anchor"> </i> Bring up DevTools for the app
719
720 <div class="trydart-step-details" markdown="1">
721
722 On your computer, click `inspect` under the tab for your app.
723 A DevTools window appears that is attached to your app running
724 on the mobile device.
725
726
727 ![Your tab appears under the Chrome heading](images/devtoolsforphone.png)
728
729 </div>
730
731 ### <i class="fa fa-anchor"> </i> Experiment with changing the app
732
733 <div class="trydart-step-details" markdown="1">
734
735 Experiment by modifying the font size or color.
736 The change happens instantly on your mobile device.
737
738 </div>
739
740 ### <i class="fa fa-anchor"> </i> Save your changes
741
742 <div class="trydart-step-details" markdown="1">
743
744 If you want to, make any permanent changes to your source code and build the app again.
745
746 </div>
747
748
749 ##Step 5: Deploy to Heroku {#step-five}
750
751 In this step, you deploy your server and app to Heroku.
752
753 ### <i class="fa fa-anchor"> </i> Create a `Procfile`
754
755 <div class="row"> <div class="col-md-7" markdown="1">
756
757 <div class="trydart-step-details" markdown="1">
758
759 In the `deploy-codelab-master` directory, create a file
760 named `Procfile` and add the following line to it.
761
762 {% prettify bash %}
763 web: ./dart-sdk/bin/dart bin/basic_http_server.dart
764 {% endprettify %}
765
766 </div>
767
768 <div class="trydart-filename">Procfile</div>
769
770 </div> <div class="col-md-5" markdown="1">
771
772 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
773
774 * A `Procfile` tells Heroku what part of your app can be executed.
775
776 * The `Procfile` for this example defines a web process type
777 in which the dart VM runs the static file server.
778
779 &nbsp; {% comment %} non-breaking space required for bootstrap/markdown bogosity {% endcomment %}
780
781 </div> </div>
782
783
784 ### <i class="fa fa-anchor"> </i> Commit your changes to your local `deploy-code lab-master` git repo
Shams 2014/01/17 17:23:09 This step surprised me. I didn't know I would have
mem 2014/01/17 21:33:59 Done.
785
786 <div class="row"> <div class="col-md-7" markdown="1">
787
788 <div class="trydart-step-details" markdown="1">
789
790 {% prettify bash %}
791 $ cd deploy-codelab-master
792 $ git init
793 $ git add -A .
794 $ git commit -am "make it so"
795 $
796 {% endprettify %}
797
798 </div>
799
800 <div class="trydart-filename">terminal</div>
801
802 </div> <div class="col-md-5" markdown="1">
803
804 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
805
806 * First, create a local repo with `git init`.
807
808 * Next, add all of the files in `deploy-codelab-master` to it.
809
810 * Finally, commit the new files in the `build` directory to your local
811 git repo.
812
813 &nbsp; {% comment %} non-breaking space required for bootstrap/markdown bogosity {% endcomment %}
814
815 </div> </div>
816
817 ### <i class="fa fa-anchor"> </i> Create a Heroku app and configure it.
818
819 <div class="row"> <div class="col-md-7" markdown="1">
820
821 <div class="trydart-step-details" markdown="1">
822
823 <strong>Important:</strong> Replace
824 `myfirstdartappforheroku` with something unique.
825
826 {% prettify bash %}
827 $ heroku create [[highlight]]myfirstdartappforheroku[[/highlight]] -s cedar
Shams 2014/01/17 17:23:09 Having never used Heroku before, this didn't work.
mem 2014/01/17 21:33:59 Done.
828 $ heroku labs:enable user-env-compile
829 $ heroku config:set DART_SDK_URL=https://github.com/selkhateeb/heroku-vagrant-da rt-build/releases/download/latest/dart-sdk.tar
830 $ heroku config:add BUILDPACK_URL=https://github.com/igrigorik/heroku-buildpack- dart.git
831 $
832 {% endprettify %}
833
834 </div>
835
836 <div class="trydart-filename">terminal</div>
837
838 </div> <div class="col-md-5" markdown="1">
839
840 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
841
842 * First, create a Heroku app.
843 Provide it with a unique name (NOT `myfirstdartappforheroku`).
844
845 * Next, enable `user-env-compile` so that environment variables
846 can be passed to the build script during deploy.
847
848 * Official builds of Dart do not support Heroku due to mismatched glibc
849 versions. In this code lab,
850 you'll use the (unsupported) [Vagrant Dart Build](https://github.com/selkhatee b/heroku-vagrant-dart-build),
851 which is a special build of the SDK that is compatible with Heroku.
852
853 * A buildpack extends Heroku. The buildpack used here extends Heroku
854 to support Dart apps. The location of the buildpack
855 is specified with the `BUILDPACK_URL`.
856
857 &nbsp; {% comment %} non-breaking space required for bootstrap/markdown bogosity {% endcomment %}
858
859 </div> </div>
860
861 ### <i class="fa fa-anchor"> </i> Push your app to Heroku
862
863 <div class="row"> <div class="col-md-7" markdown="1">
864
865 <div class="trydart-step-details" markdown="1">
866
867
868 {% prettify bash %}
869 $ [[highlight]]git push heroku master[[/highlight]]
870 Initializing repository, done.
871
872 ...
873 -----> Fetching custom git buildpack... done
874 -----> Dart app detected
875 ...
876 Dart VM version: 1.0.0.5_r30248_vagrant (Thu Nov 14 13:43:29 2013) on "linux_x64 "
877 ...
878 *** Running pub build
879 Building with "pub build"
880 Building deploy_codelab....................
881 [Info in Dart2JS]:
882 Generated deploy_codelab|web/piratebadge.dart.js (97701 characters) in 0:01:19.6 85114
883 Built 6 files!
884 ...
885 -----> Launching... done, v6
886 http://thawing-shore-4708.herokuapp.com deployed to Heroku
887
888 To git@heroku.com:thawing-shore-4708.git
889 * [new branch] master -> master
890 $
891 {% endprettify %}
892
893
894 </div>
895
896 <div class="trydart-filename">terminal</div>
897
898 </div> <div class="col-md-5" markdown="1">
899
900 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
901
902
903 * Heroku uses git for deploying applications.
904
905 * Your local git repository is associated with a remote Heroku repository,
906 usually named `heroku`.
907
908 * When you push, Heroku runs the buildpack that you specified.
909
910 * In addition to other tasks, this buildpack runs `pub build`.
911
912 * When the push is finished, the process displays a URL for your app.
913
914 &nbsp; {% comment %} non-breaking space required for bootstrap/markdown bogosity {% endcomment %}
915
916 </div> </div>
917
918 ### <i class="fa fa-anchor"> </i> Specify the scale
919
920 <div class="row"> <div class="col-md-7" markdown="1">
921
922 <div class="trydart-step-details" markdown="1">
923
924 {% prettify bash %}
925 $ heroku ps:scale web=1
926 $
927 {% endprettify %}
928
929 </div>
930
931 <div class="trydart-filename">terminal</div>
932
933 </div> <div class="col-md-5" markdown="1">
934
935 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
936
937 * Scale to one _dyno_, which is a Heroku lightweight container
938 that runs a single user-specified command.
939
940 &nbsp; {% comment %} non-breaking space required for bootstrap/markdown bogosity {% endcomment %}
941
942 </div> </div>
943
944 <hr>
945
946 ##Step 6: Run the app online and on mobile {#step-six}
sethladd 2014/01/17 00:07:23 what does "online and on mobile" mean?
mem 2014/01/17 21:33:59 Done.
947
948 Now that your app is deployed, you can run it on the internet
949 and on a mobile device.
950
951 ### <i class="fa fa-anchor"> </i> Test your app
952
953 <div class="row"> <div class="col-md-7" markdown="1">
954
955 <div class="trydart-step-details" markdown="1">
956
957 <iframe class="running-app-frame"
958 style="height:220px;width:550px;"
959 src="/codelabs/darrrt/examples/6-piratebadge_json/piratebadge.html">
960 </iframe>
961
962
963 </div>
964
965 </div> <div class="col-md-5" markdown="1">
966 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
967
968 * Use the URL displayed by the previous step to visit your app:
969 `http://myfirstdartappforheroku.herokuapp.com`
970
971 </div> </div>
972
973
974 ### <i class="fa fa-anchor"> </i> Enter the URL in a browser
975
976 <div class="row"> <div class="col-md-7" markdown="1">
977
978 <div class="trydart-step-details" markdown="1">
979
980 <img src="images/calebthebrave.png" height="400">
981
982 </div>
983
984 </div> <div class="col-md-5" markdown="1">
985
986 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
987
988 * Use the URL from the previous step to load the app
989 into a browser on your mobile device.
990 `http://myfirstdartappforheroku.herokuapp.com`
991
992 &nbsp; {% comment %} non-breaking space required for bootstrap/markdown bogosity {% endcomment %}
993
994 </div> </div>
995
996
997
998 <div class="trydart-step-details" markdown="1">
999 </div>
1000
1001
1002 ##Resources {#resources}
1003
1004 For more information about the tools and libraries used
1005 in this code lab, check out these resources.
1006
1007 <div class="trydart-step-details" markdown="1">
1008
1009 #### SDK libraries, classes, and functions
1010
1011 * The API docs for the
1012 <a href="https://api.dartlang.org/dart_io/File.html" target="_blank">File</a>,
1013 <a href="https://api.dartlang.org/dart_io/HttpServer.html" target="_blank">HttpS erver</a>, and
1014 <a href="https://api.dartlang.org/dart_io/Platform.html" target="_blank">Platfor m</a>
1015 classes from the
1016 <a href="https://api.dartlang.org/dart_io.html" target="_blank">dart:io</a>
1017 library.
1018 * The API docs for the
1019 <a href="https://api.dartlang.org/dart_async.html#runZoned" target="_blank">runZ oned()</a>
1020 function from the
1021 <a href="https://api.dartlang.org/dart_async.html" target="_blank">dart:async</a > library.
1022
1023 #### Classes and functions from pub packages
1024
1025 * The code for the
1026 <a href="https://pub.dartlang.org/packages/http_server">http_server pub package< /a>,
1027 in particular
1028 <a href="https://api.dartlang.org/http_server/VirtualDirectory.html" target="_bl ank">VirtualDirectory</a>
1029 class.
1030 * The code for the
1031 <a href="http://pub.dartlang.org/packages/path">path pub package</a>,
1032 in particular the
1033 <a href="https://api.dartlang.org/path.html#join" target="_blank">join()</a>
1034 and
1035 <a href="https://api.dartlang.org/path.html#dirname" target="_blank">dirname()</ a>
1036 functions.
1037
1038 #### Heroku tools
1039
1040 * The <a href="https://devcenter.heroku.com/">Heroku Dev Center</a>
1041 * The Heroku-compatible build of the Dart SDK:
1042 [heroku-vagrant-dart-build](https://github.com/selkhateeb/heroku-vagrant-dart-bu ild)
1043 * The Heroku buildpack for Dart:
1044 [heroku-buildpack-dart](https://github.com/igrigorik/heroku-buildpack-dart)
1045
1046 #### The example code
1047
1048 * The [deploy-codelab-master](https://github.com/marycampione/deploy-codelab)
1049 example code
1050
1051 </div>
1052
1053 ##What next? {#what-next}
1054
1055 Now that your app is deployed for the world to use,
1056 what do you do now?
1057 Here are some suggestions.
1058
1059 ### <i class="fa fa-anchor"> </i> Share your app with the world!
1060
1061 <div class="trydart-step-details" markdown="1">
1062
1063 Share your Heroku URL with your followers and circles.
1064
1065 * <a href="https://twitter.com/share" class="twitter-share-button" data-text="Ar rr! I've deployed me app. http://dartlang.org/codelab/deploy/" data-count="none" data-hashtags="dartlang">Tweet</a>
1066 <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.tes t(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js. id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore( js,fjs);}}(document, 'script', 'twitter-wjs');</script>
1067
1068 {% comment %}
1069 * <p class="share-button twitter">
1070 <a href="https://twitter.com/share"
1071 class="twitter-share-button external-link"
1072 data-count="none"
1073 data-text="Arrr! I've deployed me app. http://dartlang.org/codelab/deploy/"
1074 data-hashtags="dartlang">Tweet</a> </p>
1075 {% endcomment %}
1076
1077 * <p>
1078 <script src="https://apis.google.com/js/plusone.js"></script>
1079 <g:plus action="share"></g:plus> </p>
1080
1081 </div>
1082
1083 ### <i class="fa fa-anchor"> </i> Jump to another ship.
1084
1085 <div class="trydart-step-details" markdown="1">
1086
1087 * If you never went through the [Pirate Convention](/codelabs/darrrt/) code lab, do it now.
1088 * For more code related to command-line apps, such as servers,
1089 visit [Dart by Example](/dart-by-example/).
1090 * Play with some [samples](/samples/).
1091 * Try the [tutorials](/docs/tutorials/).
1092 * Go write some awesome code.
1093
1094 </div>
1095
1096 {% comment %}
1097 ### <i class="fa fa-anchor"> </i> Run the app on a mobile device
1098
1099 <div class="row"> <div class="col-md-7">
1100
1101 <div class="trydart-step-details" markdown="1">
1102 Open `build/piratebadge.html` using **File > Open File...**.
1103
1104 <img src="images/mobile_better.png" height="400">
1105 </div>
1106
1107 </div> <div class="col-md-5" markdown="1">
1108
1109 <i class="fa fa-key key-header"> </i> <strong> Key Information </strong>
1110
1111 * The &lt;head&gt; section of the HTML file contains this line,
1112 `&;lt;<meta name="viewport" content="width=device-width, initial-scale=1.0, us er-scalable=no">&gt;',
1113 which controls the size and scalable of the app helping it to fill the screen
1114 of different sized mobile devices.
1115
1116 * The CSS code contains a small adjustment to the pirate badge's padding
1117 to align it to the left when it floats under the widgets.
1118
1119 * Use the URL from the previous step to load the app
1120 into a browser on your mobile device.
1121 `http://myfirstdartappforheroku.herokuapp.com`
1122
1123 * The `dart.js` script included in `piratebadge.html` determines that the browse r
1124 does not support Dart and runs the JavaScript file instead.
1125
1126 * You now know that the `pub build` process is working and that your app
1127 runs successfully as JavaScript.
1128
1129 </div></div>
1130
1131
1132 {% endcomment %}
OLDNEW
« no previous file with comments | « src/site/codelabs/deploy/images/wee-arrow.png ('k') | src/site/css/dart-style.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698