From b482a1796e92bd3548df8eca7f5b396a66349183 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sun, 25 Dec 2016 02:38:33 +0000 Subject: [PATCH 1/4] Add initial buildable version of habitat plan --- habitat/plan.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 habitat/plan.sh diff --git a/habitat/plan.sh b/habitat/plan.sh new file mode 100644 index 0000000..942dadd --- /dev/null +++ b/habitat/plan.sh @@ -0,0 +1,66 @@ +pkg_origin=leverage +pkg_name=leverage +pkg_version=0.1.0 +pkg_maintainer="Chris Alfano " +pkg_license=(MIT) +pkg_upstream_url=https://github.com/Lever-age/leverage +pkg_source=leverage.tar.gz +pkg_deps=(bochener/node) +pkg_expose=(80) +pkg_build_deps=(core/coreutils core/git) +pkg_interpreters=(bin/env) + +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() { + git clone --depth 1 --branch develop https://github.com/Lever-age/api.git $HAB_CACHE_SRC_PATH/$pkg_dirname/api + git clone --depth 1 --branch develop https://github.com/Lever-age/frontend.git $HAB_CACHE_SRC_PATH/$pkg_dirname/frontend + + cd $HAB_CACHE_SRC_PATH/$pkg_dirname/api + 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. + + mkdir -p ${pkg_prefix}/api + cp -v api/package.json ${pkg_prefix}/api + cp -v api/app.js ${pkg_prefix}/api + cp -vr api/controllers ${pkg_prefix}/api + cp -vr api/lib ${pkg_prefix}/api + cp -r api/node_modules ${pkg_prefix}/api + cp -v $PLAN_CONTEXT/../etc/api/config.json ${pkg_prefix}/api + + mkdir -p ${pkg_prefix}/frontend + cp -v frontend/*.html ${pkg_prefix}/frontend + cp -vr frontend/assets ${pkg_prefix}/assets + ln -vs discover.html ${pkg_prefix}/frontend/index.html +} + +do_end() { + # Clean up the `env` link, if we set it up. + if [[ -n "$_clean_env" ]]; then + rm -fv /usr/bin/env + fi +} From 586ddd15e61e627b1ca5ef8f5a5d404409f3463a Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sun, 25 Dec 2016 03:08:13 +0000 Subject: [PATCH 2/4] Use habitat config system to generate config.json --- habitat/config/config.json | 9 +++++++++ habitat/default.toml | 7 +++++++ habitat/plan.sh | 1 - 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 habitat/config/config.json create mode 100644 habitat/default.toml 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..1e8d82c --- /dev/null +++ b/habitat/default.toml @@ -0,0 +1,7 @@ +[listen] +address = "127.0.0.1" +port = 8228 + +[storage] +path = "/srv/leverage/leverage.sqlite" + diff --git a/habitat/plan.sh b/habitat/plan.sh index 942dadd..6edb7c0 100644 --- a/habitat/plan.sh +++ b/habitat/plan.sh @@ -50,7 +50,6 @@ do_install() { cp -vr api/controllers ${pkg_prefix}/api cp -vr api/lib ${pkg_prefix}/api cp -r api/node_modules ${pkg_prefix}/api - cp -v $PLAN_CONTEXT/../etc/api/config.json ${pkg_prefix}/api mkdir -p ${pkg_prefix}/frontend cp -v frontend/*.html ${pkg_prefix}/frontend From 5c70d33203b2fe558f46201e127df6fecb528270 Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sun, 25 Dec 2016 03:08:43 +0000 Subject: [PATCH 3/4] Add init and run hooks to enable starting api --- habitat/hooks/init | 7 +++++++ habitat/hooks/run | 4 ++++ 2 files changed, 11 insertions(+) create mode 100644 habitat/hooks/init create mode 100644 habitat/hooks/run diff --git a/habitat/hooks/init b/habitat/hooks/init new file mode 100644 index 0000000..34b7e04 --- /dev/null +++ b/habitat/hooks/init @@ -0,0 +1,7 @@ +#!/bin/sh +ln -sf {{pkg.path}}/api/package.json {{pkg.svc_var_path}} +ln -sf {{pkg.path}}/api/app.js {{pkg.svc_var_path}} +ln -sf {{pkg.path}}/api/node_modules {{pkg.svc_var_path}} +ln -sf {{pkg.path}}/api/lib {{pkg.svc_var_path}} +ln -sf {{pkg.path}}/api/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 From 44d0200ce922f6f2aa72ba8efa77803233ee6dcc Mon Sep 17 00:00:00 2001 From: Chris Alfano Date: Sun, 25 Dec 2016 03:17:00 +0000 Subject: [PATCH 4/4] Expose API port --- habitat/default.toml | 2 +- habitat/plan.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/habitat/default.toml b/habitat/default.toml index 1e8d82c..a6041ea 100644 --- a/habitat/default.toml +++ b/habitat/default.toml @@ -1,5 +1,5 @@ [listen] -address = "127.0.0.1" +address = "0.0.0.0" port = 8228 [storage] diff --git a/habitat/plan.sh b/habitat/plan.sh index 6edb7c0..3bb6cf9 100644 --- a/habitat/plan.sh +++ b/habitat/plan.sh @@ -6,7 +6,7 @@ pkg_license=(MIT) pkg_upstream_url=https://github.com/Lever-age/leverage pkg_source=leverage.tar.gz pkg_deps=(bochener/node) -pkg_expose=(80) +pkg_expose=(8228) pkg_build_deps=(core/coreutils core/git) pkg_interpreters=(bin/env)