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

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

Powered by Google App Engine
This is Rietveld 408576698