From 97084147f12481e21f76267862b6818f6eb36a56 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Tue, 27 Dec 2016 21:13:29 +0000 Subject: [PATCH 1/4] Add basic habitat plan to build and run api --- habitat/config/config.json | 9 ++++++ habitat/default.toml | 8 ++++++ habitat/hooks/init | 7 +++++ habitat/hooks/run | 4 +++ habitat/plan.sh | 57 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 85 insertions(+) create mode 100644 habitat/config/config.json create mode 100644 habitat/default.toml create mode 100644 habitat/hooks/init create mode 100644 habitat/hooks/run create mode 100644 habitat/plan.sh diff --git a/habitat/config/config.json b/habitat/config/config.json new file mode 100644 index 0000000..5634e73 --- /dev/null +++ b/habitat/config/config.json @@ -0,0 +1,9 @@ +{ + "listen": { + "address": "{{cfg.listen.address}}", + "port": {{cfg.listen.port}} + }, + "storage": { + "path": "{{cfg.storage.path}}" + } +} diff --git a/habitat/default.toml b/habitat/default.toml new file mode 100644 index 0000000..8c46897 --- /dev/null +++ b/habitat/default.toml @@ -0,0 +1,8 @@ +[listen] +address = "0.0.0.0" +port = 8228 + +[storage] +path = "/srv/leverage/leverage.sqlite" + +[services.core.nginx.leverage] diff --git a/habitat/hooks/init b/habitat/hooks/init new file mode 100644 index 0000000..5029c32 --- /dev/null +++ b/habitat/hooks/init @@ -0,0 +1,7 @@ +#!/bin/sh +ln -sf {{pkg.path}}/package.json {{pkg.svc_var_path}} +ln -sf {{pkg.path}}/app.js {{pkg.svc_var_path}} +ln -sf {{pkg.path}}/node_modules {{pkg.svc_var_path}} +ln -sf {{pkg.path}}/lib {{pkg.svc_var_path}} +ln -sf {{pkg.path}}/controllers {{pkg.svc_var_path}} +ln -sf {{pkg.svc_config_path}}/config.json {{pkg.svc_var_path}} diff --git a/habitat/hooks/run b/habitat/hooks/run new file mode 100644 index 0000000..a168558 --- /dev/null +++ b/habitat/hooks/run @@ -0,0 +1,4 @@ +#!/bin/sh + +cd {{pkg.svc_var_path}} +exec node app.js 2>&1 diff --git a/habitat/plan.sh b/habitat/plan.sh new file mode 100644 index 0000000..6195994 --- /dev/null +++ b/habitat/plan.sh @@ -0,0 +1,57 @@ +pkg_origin=leverage-api +pkg_name=leverage +pkg_version=0.1.0 +pkg_maintainer="Chris Alfano " +pkg_license=(MIT) +pkg_upstream_url=https://github.com/Lever-age/api +pkg_source=leverage-api.tar.gz +pkg_deps=(bochener/node) +pkg_expose=(8228) +pkg_build_deps=(core/coreutils) + +do_download() { + return 0 +} + +do_verify() { + return 0 +} + +do_unpack() { + return 0 +} + +do_prepare() { + # The `/usr/bin/env` path is hardcoded, so we'll add a symlink if needed. + # We can't do fix_interpreter here without adding a coreutils runtime dep. + if [[ ! -r /usr/bin/env ]]; then + ln -sv "$(pkg_path_for coreutils)/bin/env" /usr/bin/env + _clean_env=true + fi +} + +do_build() { + cp -vr $PLAN_CONTEXT/../* $HAB_CACHE_SRC_PATH/$pkg_dirname + + cd $HAB_CACHE_SRC_PATH/$pkg_dirname + npm install +} + +do_install() { + # Our source files were copied over to HAB_CACHE_SRC_PATH/$pkg_dirname in do_build(), + # and now they need to be copied from that directory into the root directory of our package + # through the use of the pkg_prefix variable. + + cp -v package.json ${pkg_prefix} + cp -v app.js ${pkg_prefix} + cp -vr controllers ${pkg_prefix} + cp -vr lib ${pkg_prefix} + cp -r node_modules ${pkg_prefix} +} + +do_end() { + # Clean up the `env` link, if we set it up. + if [[ -n "$_clean_env" ]]; then + rm -fv /usr/bin/env + fi +} From 04a273a02269817e128ed247679d811f06f75e8b Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Tue, 27 Dec 2016 21:21:02 +0000 Subject: [PATCH 2/4] Correct habitat pkg origin and name --- habitat/plan.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/habitat/plan.sh b/habitat/plan.sh index 6195994..cdd99c1 100644 --- a/habitat/plan.sh +++ b/habitat/plan.sh @@ -1,5 +1,5 @@ -pkg_origin=leverage-api -pkg_name=leverage +pkg_origin=leverage +pkg_name=leverage-api pkg_version=0.1.0 pkg_maintainer="Chris Alfano " pkg_license=(MIT) From 889df8d7f4c53b0dcbacaf4000914f4f030bdc02 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Wed, 28 Dec 2016 03:55:17 +0000 Subject: [PATCH 3/4] Remove erroneous service config --- habitat/default.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/habitat/default.toml b/habitat/default.toml index 8c46897..41738e8 100644 --- a/habitat/default.toml +++ b/habitat/default.toml @@ -4,5 +4,3 @@ port = 8228 [storage] path = "/srv/leverage/leverage.sqlite" - -[services.core.nginx.leverage] From 4883f0ac6b349c335d6edb35cee88cd82fde0001 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Wed, 28 Dec 2016 04:05:15 +0000 Subject: [PATCH 4/4] Improve comments describing plan steps --- habitat/plan.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/habitat/plan.sh b/habitat/plan.sh index cdd99c1..e6ac5c1 100644 --- a/habitat/plan.sh +++ b/habitat/plan.sh @@ -22,8 +22,16 @@ do_unpack() { } do_prepare() { - # The `/usr/bin/env` path is hardcoded, so we'll add a symlink if needed. - # We can't do fix_interpreter here without adding a coreutils runtime dep. + # This hack deals with some npm package build scripts having + # /usr/bin/env hardcoded instead of using env from PATH by + # temporarily creating a symlink at /usr/bin/env within + # the build environment that links to the env executable + # provided by the coreutils package + # + # Habitat provides a minimal environment for builds where every + # available package has its bin folder added to PATH rather than + # its contents copied to a global /usr/bin directory + if [[ ! -r /usr/bin/env ]]; then ln -sv "$(pkg_path_for coreutils)/bin/env" /usr/bin/env _clean_env=true @@ -31,17 +39,19 @@ do_prepare() { } do_build() { + # Copy files from wherever this plan is being run from to the + # temporary build space for this package cp -vr $PLAN_CONTEXT/../* $HAB_CACHE_SRC_PATH/$pkg_dirname + # cd into the temporary build space and populate node_modules/ cd $HAB_CACHE_SRC_PATH/$pkg_dirname npm install } do_install() { - # Our source files were copied over to HAB_CACHE_SRC_PATH/$pkg_dirname in do_build(), - # and now they need to be copied from that directory into the root directory of our package - # through the use of the pkg_prefix variable. - + # Copy the things we want to distribute from the current + # directory (this package's temporary build space) to the + # root for this package's build cp -v package.json ${pkg_prefix} cp -v app.js ${pkg_prefix} cp -vr controllers ${pkg_prefix}