GithubHelp home page GithubHelp logo

sample-node-app's Introduction

Habitat Sample Node App

This simple Express 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.

Follow the Demos!

For the full experience, we recommend following the demos on the Habitat website. They walk you through getting set up with Habitat, Builder, automated builds and publishing to Docker Hub.

Alternatively, you can follow the instructions below if you simply want to build and run the app locally.

habitat-sample-node-app

Prerequisites

To package and run this application with Habitat, you'll need to:

Setup for First-time Users

Before you can build the app, you'll need to create an origin and accompanying keys. The quickest way to do this is by running hab setup as described in the Habitat docs and following the prompts:

$ hab setup

Note: The origin name you use during setup will need to be specified in the plan.sh file mentioned in the next section.

Building the Package

From the habitat directory in this repository, open the plan.sh file. It should look like this:

pkg_origin=your_origin
pkg_name=sample-node-app
pkg_version="1.1.0"
pkg_deps=(core/node)
...

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, use the origin you created in Habitat Builder.

Next, let's change the version number:

...
pkg_version="1.1.1"
...

Save and close the file, then enter the Habitat Studio:

$ hab studio enter

And run a build:

[1][default:/src:0]# build

Habitat will produce a package (a .hart file) and place it in the results directory.

Running the Package with Docker

Still in the Studio, right after the build, export that package as a Docker image:

[2][default:/src:0]# source results/last_build.env
[3][default:/src:0]# hab pkg export docker results/$pkg_artifact

Then exit the Studio:

[4][default:/src:0]# exit

And start a Docker container with your newly created image:

$ docker run -it -p 8000:8000 <YOUR_ORIGIN>/sample-node-app

Now head to http://localhost:8000 and see your running app!

sample-node-app's People

Contributors

cnunciato avatar mgamini avatar nellshamrell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sample-node-app's Issues

Plan file not found when running from Windows

Does this need to be run from a linux workstation?

When running through the tutorial on Windows 10, PowerShell v5.1. Unable to build, looking for plan.ps1 and finding plan.sh.

โžœ  hab studio enter
   hab-studio: Creating Studio at C:\
? Importing origin key from standard input
? Imported public origin key capgemini-20180912132012.
? Importing origin key from standard input
? Imported secret origin key capgemini-20180912132012.
   hab-studio: Entering Studio at C:\
** The Habitat Supervisor has been started in the background.
** Use 'hab svc start' and 'hab svc stop' to start and stop services.
** Use the 'Get-SupervisorLog' command to stream the Supervisor log.
** Use the 'Stop-Supervisor' to terminate the Supervisor.

[HAB-STUDIO] Habitat:\src> build
_Exit-With : Plan file not found at C:\src\plan.ps1 or C:\src\habitat\plan.ps1
At C:\hab\pkgs\core\hab-studio\0.62.1\20180904173651\bin\hab-plan-build.ps1:2123 char:5
+     _Exit-With "Plan file not found at $places" 42
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,_Exit-With

[HAB-STUDIO] Habitat:\src> ls .\habitat\


    Directory: C:\src\habitat


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        9/12/2018   9:21 AM                config
d-----        9/12/2018   9:21 AM                hooks
-a----        9/12/2018   9:21 AM            358 default.toml
-a----        9/12/2018   9:23 AM           2066 plan.sh

plan.sh includes pkg_version="1.0.1" in repo

In the README pkg_version="1.0.1" is part of the workflow of getting setup, but it's already included. I didn't submit a PR as I'm not sure if the goal is to have folks add the line (so the line should be removed from the sample app) or if the README should be updated to include.

Add image to README

Add a screenshot of the running app to the README.
We'll link to the image from this closed issue.

habitat-sample-node-app

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.