Skip to content

Commit c9e5c7e

Browse files
Merge pull request #262 from bixu/feature/habitat_service_support
WIP: support running CHIME under Habitat
2 parents 74defe5 + a06188a commit c9e5c7e

File tree

8 files changed

+129
-1
lines changed

8 files changed

+129
-1
lines changed

.bldr.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[chime]
2+
plan_path = "habitat"
3+
paths = [
4+
"habitat/*",
5+
".bldr.toml",
6+
"src/*",
7+
]

.envrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export HAB_DOCKER_OPTS="-p 8000:8000"
2+
export HAB_STUDIO_SUP="false"

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ venv.bak/
1818
.mypy_cache/
1919
__pycache__/
2020

21-
2221
# Module trash
2322
*.egg-info
2423

2524
# Notebooks
2625
devel.ipynb
2726
.ipynb_checkpoints
2827

28+
# build artifacts
29+
results/

.studiorc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export HAB_HART_COMPRESSION_LEVEL=0 # disables compression to speed up local dev

habitat/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## Habitat Service Package for CHIME
2+
This package can be used to run CHIME as a fully self-contained application.
3+
See https://habitat.sh for more details.
4+
5+
### Examples
6+
Quickstart With Docker "Shim" Container:
7+
```
8+
docker run -it -p 8000:8000 bixu/hab hab sup run "bixu/chime" --channel="unstable"
9+
```
10+
11+
Local Prototyping Example:
12+
```
13+
set -e
14+
curl --silent "https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.sh" | sudo bash -s
15+
hab cli setup
16+
direnv allow
17+
hab studio enter
18+
build
19+
hab sup run $HAB_ORIGIN/chime --channel="unstable"
20+
```
21+
22+
Complete `systemd` Bootstrap Example:
23+
```
24+
echo 'HAB_AUTH_TOKEN="<enter your token from https://bldr.habitat.sh/#/profile>"
25+
HAB_LICENSE="accept"
26+
HAB_NONINTERACTIVE="true"
27+
' > supervisor.env
28+
29+
echo '[Unit]
30+
Description=Habitat Supervisor
31+
[Service]
32+
EnvironmentFile=/etc/systemd/supervisor.env
33+
ExecStartPre=/bin/bash -c "/bin/systemctl set-environment SSL_CERT_FILE=$(hab pkg path core/cacerts)/ssl/cert.pem"
34+
ExecStart=/bin/hab sup run --no-color
35+
ExecStop=/bin/hab sup term
36+
KillMode=process
37+
Restart=on-failure
38+
[Install]
39+
WantedBy=default.target
40+
' > supervisor.service
41+
42+
curl --silent "https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.sh" | sudo bash -s
43+
sudo cp "supervisor.env" "/etc/systemd/supervisor.env"
44+
sudo chown root "/etc/systemd/supervisor.env"
45+
sudo chmod 400 "/etc/systemd/supervisor.env"
46+
sudo mv supervisor.service "/etc/systemd/system/supervisor.service"
47+
sudo --preserve-env hab pkg install "core/hab-sup"
48+
sudo systemctl enable supervisor
49+
sudo systemctl restart supervisor
50+
sudo groupadd hab || true
51+
sudo useradd --system --gid hab hab || true
52+
53+
sudo hab svc load "bixu/chime" --channel="unstable"
54+
```

habitat/config/.streamlit/config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[server]
2+
enableCORS = false
3+
headless = true
4+
port = 8000

habitat/hooks/run

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
export HOME="/hab/svc/chime/config"
3+
cd "/hab/svc/chime"
4+
5+
if [ "$(whoami)" = "root" ]; then
6+
exec chpst \
7+
-U root:hab \
8+
-u root:hab \
9+
streamlit run "{{pkg.path}}/app.py" 2>&1
10+
else
11+
exec streamlit run "{{pkg.path}}/app.py" 2>&1
12+
fi

habitat/plan.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
pkg_origin="bixu"
2+
pkg_name="chime"
3+
pkg_version="0.1.0"
4+
pkg_maintainer="Blake Irvin <[email protected]>"
5+
pkg_license=('MIT')
6+
pkg_deps=(
7+
"core/python"
8+
"core/sudo"
9+
"core/dbus"
10+
)
11+
pkg_build_deps=(
12+
"core/make"
13+
"core/git"
14+
)
15+
pkg_bin_dirs=(
16+
"bin"
17+
)
18+
pkg_svc_user="root"
19+
20+
do_prepare() {
21+
if ! ls "/etc/sudoers" &> "/dev/null"
22+
then
23+
echo "root ALL=(ALL) ALL" >> "/etc/sudoers"
24+
fi
25+
python -m venv "${pkg_prefix}"
26+
source "${pkg_prefix}/bin/activate"
27+
pip install --upgrade --force-reinstall "pip" "wheel"
28+
return $?
29+
}
30+
31+
do_build() {
32+
pip install -r ${PLAN_CONTEXT}/../requirements.txt
33+
return $?
34+
}
35+
36+
do_install() {
37+
cp -pr ${PLAN_CONTEXT}/../src/* "${pkg_prefix}/"
38+
return $?
39+
}
40+
41+
do_check() {
42+
return 0
43+
}
44+
45+
do_strip() {
46+
return 0
47+
}

0 commit comments

Comments
 (0)