-
Notifications
You must be signed in to change notification settings - Fork 1
/
build
executable file
·86 lines (68 loc) · 2.29 KB
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
set -eu
layers_dir="$1"
env_dir="$2/env"
plan_path="$3"
if compgen -G "${env_dir}/*" > /dev/null; then
for var in ${env_dir}/*; do
declare "$(basename ${var})=$(<${var})"
done
fi
echo "[wetty]"
wetty_layer=$layers_dir/wetty
wetty_version="2.0.2"
if [ -f ${wetty_layer}.toml ] && [ "$(cat "${wetty_layer}.toml" | yj -t | jq .metadata.version -r)" == "${wetty_version}" ]; then
echo "Using cached version: ${wetty_version}"
touch ${wetty_layer}.toml
else
echo "Installing version: ${wetty_version}"
mkdir -p $wetty_layer/env
npm install --prefix $wetty_layer wetty@${wetty_version}
echo -n "$wetty_layer/node_modules" > $wetty_layer/env/NODE_PATH
echo "Generate OpenSSL certificates"
mkdir -p $wetty_layer/.ssl
openssl req -x509 -nodes -days 1095 -newkey ec:<(openssl ecparam -name secp384r1) -subj "/C=GB/ST=None/L=None/O=None/OU=None/CN=None" -out $wetty_layer/.ssl/wetty.crt -keyout $wetty_layer/.ssl/wetty.key
chmod 700 $wetty_layer/.ssl
chmod 644 $wetty_layer/.ssl/wetty.crt
chmod 600 $wetty_layer/.ssl/wetty.key
echo "Generate the ssh key file"
mkdir -p $wetty_layer/.ssh
ssh-keygen -q -C "wetty-keyfile" -t ed25519 -N '' -f $wetty_layer/.ssh/wetty 2>/dev/null <<< y >/dev/null
cat $wetty_layer/.ssh/wetty.pub >> $wetty_layer/.ssh/authorized_keys
chmod 700 $wetty_layer/.ssh
chmod 644 $wetty_layer/.ssh/authorized_keys
chmod 600 $wetty_layer/.ssh/wetty
fi
force_command="${WEB_TTY_CMD:-"bash"}"
cat << EOF > $wetty_layer/.ssh/sshd_config
HostKey $wetty_layer/.ssh/wetty
AuthorizedKeysFile $wetty_layer/.ssh/authorized_keys
ForceCommand bash -c "HOME=/workspace /cnb/lifecycle/launcher $force_command"
EOF
npm install "$wetty_layer/node_modules/wetty"
cat <<BASH > wetty.sh
#!/bin/bash
/usr/sbin/sshd -f $wetty_layer/.ssh/sshd_config -o "Port 2222"
port=\${WEB_TTY_PORT:-\$PORT}
npx wetty --host 0.0.0.0 -port \${port:-3000} --title wetty -base / \
--ssh-key $wetty_layer/.ssh/wetty \
--ssh-host localhost \
--ssh-user \$(whoami) \
--ssh-port 2222 \
--ssh-auth publickey
BASH
chmod +x wetty.sh
cat <<TOML > ${wetty_layer}.toml
launch = true
cache = true
[metadata]
version = "${wetty_version}"
TOML
cat <<TOML > ${layers_dir}/launch.toml
[[processes]]
type = "web"
command = "./wetty.sh"
[[processes]]
type = "bash"
command = "/bin/bash"
TOML