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..a6041ea --- /dev/null +++ b/habitat/default.toml @@ -0,0 +1,7 @@ +[listen] +address = "0.0.0.0" +port = 8228 + +[storage] +path = "/srv/leverage/leverage.sqlite" + 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 diff --git a/habitat/plan.sh b/habitat/plan.sh new file mode 100644 index 0000000..3bb6cf9 --- /dev/null +++ b/habitat/plan.sh @@ -0,0 +1,65 @@ +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=(8228) +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 + + 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 +}