|
1 | 1 | # Habitat Sample Node App
|
2 | 2 |
|
3 |
| -Welcome to the Habitat Sample Node App! |
| 3 | +This simple [Express](https://expressjs.com/) app is an example of how to package a Node.js application with Habitat. It's intended to accompany the walkthroughs on the Habitat website, but it can also be run locally on its own. |
4 | 4 |
|
5 |
| -### Follow the demo instructions |
| 5 | +### Follow the Demos! |
6 | 6 |
|
7 |
| -For the full experience, check out the [Habitat Demo instructions](https://www.habitat.sh/demo/) on the habitat.sh website. This will walk you through getting setup on the Habitat Builder web app and publishing this sample app to Docker Hub. |
| 7 | +For the full experience, we recommend [following the demos](https://www.habitat.sh/learn/) on the Habitat website. They walk you through getting set up with Habitat, [Builder](https://bldr.habitat.sh/), automated builds and publishing to Docker Hub. |
8 | 8 |
|
9 |
| -Alternatively, you can use the instructions below if you simply want to build and run the app locally. |
| 9 | +Alternatively, you can follow the instructions below if you simply want to build and run the app locally. |
10 | 10 |
|
11 | 11 | 
|
12 | 12 |
|
| 13 | +### Prerequisites |
13 | 14 |
|
14 |
| -## Instructions |
| 15 | +To package and run this application with Habitat, you'll need to: |
15 | 16 |
|
16 |
| -To practice packaging/running this app with Habitat |
| 17 | +* [Install and configure Habitat](https://www.habitat.sh/docs/install-habitat/) |
| 18 | +* [Install Docker](https://www.docker.com/community-edition) (if you're on Mac or Windows) |
| 19 | +* Clone this repository: |
| 20 | + |
| 21 | + $ git clone https://github.com/habitat-sh/sample-node-app.git |
| 22 | + $ cd sample-node-app |
17 | 23 |
|
18 |
| -### Workstation Prerequisites |
19 |
| -* Install and set up Habitat [(Instructions here)](https://www.habitat.sh/tutorials/download/) |
20 |
| -* Install Docker [(Instructions here)](https://www.docker.com/community-edition) |
21 |
| -* Clone this repository |
22 |
| -```bash |
23 |
| -$ git clone https://github.com/habitat-sh/sample-node-app.git |
24 |
| -``` |
25 |
| -* Change directories |
26 |
| -```bash |
27 |
| -$ cd sample-node-app |
28 |
| -``` |
29 | 24 |
|
30 | 25 | ### Setup for First-time Users
|
| 26 | + |
31 | 27 | Before you can build the app, you'll need to create an origin and accompanying keys.
|
32 |
| -The quickest way to do this is by running `hab setup` and following the prompts. |
| 28 | +The quickest way to do this is by running `hab setup` [as described in the Habitat docs](https://www.habitat.sh/docs/install-habitat/#configure-workstation) and following the prompts: |
33 | 29 |
|
34 |
| -```bash |
| 30 | +``` |
35 | 31 | $ hab setup
|
36 | 32 | ```
|
37 | 33 |
|
38 |
| -**Note** - the origin name you enter during setup will need to be added to the plan.sh file mentioned in the next section. |
| 34 | +**Note**: The origin name you use during setup will need to be specified in the plan.sh file mentioned in the next section. |
39 | 35 |
|
40 | 36 | ### Building the Package
|
41 |
| -From the `/habitat` directory in this repo, open the habitat/plan.sh file: |
42 |
| - |
43 |
| -Your habitat/plan.sh should look like this: |
44 |
| -```sh |
45 |
| -pkg_name=sample-node-app |
46 |
| -pkg_origin=your_origin |
47 |
| -pkg_scaffolding="core/scaffolding-node" |
48 |
| -``` |
49 |
| -First, change the value of `your_origin` to the origin name your created in the previous section. |
50 | 37 |
|
51 |
| -If you're following the [demo instructions](https://www.habitat.sh/demo/), then use the origin name you created in the Builder web app. |
| 38 | +From the `habitat` directory in this repository, open the `plan.sh` file. It should look like this: |
52 | 39 |
|
53 |
| -Next, let's add in a version number |
54 |
| -```sh |
55 |
| -pkg_name=sample-node-app |
| 40 | +``` |
56 | 41 | pkg_origin=your_origin
|
57 |
| -pkg_scaffolding="core/scaffolding-node" |
58 |
| -pkg_version="1.0.1" |
| 42 | +pkg_name=sample-node-app |
| 43 | +pkg_version="1.1.0" |
| 44 | +pkg_deps=(core/node) |
| 45 | +... |
59 | 46 | ```
|
| 47 | +First, change the value of `pkg_origin` from `your_origin` to the origin you created in the previous section. If you're following the [demo](https://www.habitat.sh/learn/), use the origin you created in [Habitat Builder](http://bldr.habitat.sh/). |
60 | 48 |
|
61 |
| -Now save and close the file. |
| 49 | +Next, let's change the version number: |
| 50 | +``` |
| 51 | +... |
| 52 | +pkg_version="1.1.1" |
| 53 | +... |
| 54 | +``` |
62 | 55 |
|
63 |
| -Enter the Habitat Studio |
| 56 | +Save and close the file, then enter the Habitat Studio: |
64 | 57 |
|
65 |
| -```bash |
| 58 | +``` |
66 | 59 | $ hab studio enter
|
67 | 60 | ```
|
68 | 61 |
|
69 |
| -And run build |
| 62 | +And run a build: |
70 | 63 |
|
71 |
| -```bash |
72 |
| -(studio) $ build |
73 | 64 | ```
|
| 65 | +[1][default:/src:0]# build |
| 66 | +``` |
| 67 | + |
| 68 | +Habitat will produce a package (a `.hart` file) and place it in the `results` directory. |
74 | 69 |
|
75 | 70 | ### Running the Package with Docker
|
76 | 71 |
|
77 |
| -Still in your studio, right after the build, export that package to a docker image |
78 |
| -```bash |
79 |
| -(studio) $ hab pkg export docker ./results/<habitat artifact>.hart |
80 |
| -``` |
| 72 | +Still in the Studio, right after the build, export that package as a Docker image: |
81 | 73 |
|
82 |
| -Then exit out of the studio: |
83 |
| -```bash |
84 |
| -(studio) $ exit |
| 74 | +``` |
| 75 | +[2][default:/src:0]# source results/last_build.env |
| 76 | +[3][default:/src:0]# hab pkg export docker results/$pkg_artifact |
85 | 77 | ```
|
86 | 78 |
|
87 |
| -Now start a Docker container from that image. |
| 79 | +Then exit the Studio: |
88 | 80 |
|
89 |
| -```bash |
90 |
| -$ docker run -it -p 8000:8000 your_origin/sample-node-app |
| 81 | +``` |
| 82 | +[4][default:/src:0]# exit |
| 83 | +``` |
| 84 | +And start a Docker container with your newly created image: |
| 85 | + |
| 86 | +``` |
| 87 | +$ docker run -it -p 3000:3000 <YOUR_ORIGIN>/sample-node-app |
91 | 88 | ```
|
92 | 89 |
|
93 |
| -Now head to http://localhost:8000 and see your running app! |
| 90 | +Now head to http://localhost:3000 and see your running app! |
0 commit comments