Skip to content

Commit

Permalink
Fixes:
Browse files Browse the repository at this point in the history
Fix json formatting at /run/http_ports
Fix init order to avoid warnings
Use sensible listen/metrics ports
Rename Cloudflare links from Tunnel to Secured
Add git global (*) safe directory to avoid dubious ownership errors (chown workspace)
  • Loading branch information
robballantyne committed Oct 14, 2023
1 parent 009286e commit fe226c4
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
4 changes: 4 additions & 0 deletions build/COPY_ROOT/opt/ai-dock/bin/build/layer0/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ mkdir -p /run/sshd
mkdir -p /var/empty
mkdir -p /etc/rclone
touch /etc/rclone/rclone.conf

# Git config

git config --global --add safe.directory "*"
2 changes: 1 addition & 1 deletion build/COPY_ROOT/opt/ai-dock/bin/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ function init_main() {
init_set_envs "$@"
init_set_ssh_keys
init_set_web_credentials
init_set_workspace
init_count_gpus
init_count_quicktunnels
init_count_rclone_remotes
init_set_workspace
init_set_cf_tunnel_wanted
init_cloud_context
init_create_logfiles
Expand Down
14 changes: 8 additions & 6 deletions build/COPY_ROOT/opt/ai-dock/bin/supervisor-logtail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@

trap cleanup EXIT

LISTEN_PORT=1822
METRICS_PORT=1922
LISTEN_PORT=11122
METRICS_PORT=21122
PROXY_PORT=1122
PROXY_SECURE=true
SERVICE_NAME="Log Viewer"

function cleanup() {
kill $(jobs -p) > /dev/null 2>&1
rm /run/http_ports/$PORT > /dev/null 2>&1
rm /run/http_ports/$PROXY_PORT > /dev/null 2>&1
}

file_content=$(
file_content="$(
jq --null-input \
--arg listen_port "${LISTEN_PORT}" \
--arg metrics_port "${METRICS_PORT}" \
--arg proxy_port "${PROXY_PORT}" \
--arg proxy_secure "${PROXY_SECURE,,}" \
--arg service_name "${SERVICE_NAME}" \
'$ARGS.named'
)
)"

printf "%s" $file_content > /run/http_ports/$PROXY_PORT
printf "%s\n" "$file_content" > /run/http_ports/$PROXY_PORT

printf "Starting log service...\n"
kill -9 $(lsof -t -i:$LISTEN_PORT) > /dev/null 2>&1 &
wait -n
logtail.sh -s &
/usr/bin/python3 /opt/ai-dock/fastapi/logviewer/main.py \
-p $LISTEN_PORT \
Expand Down
15 changes: 9 additions & 6 deletions build/COPY_ROOT/opt/ai-dock/bin/supervisor-redirector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

trap cleanup EXIT

LISTEN_PORT=1811
METRICS_PORT=1911
LISTEN_PORT=11111
METRICS_PORT=21111
PROXY_PORT=1111
PROXY_SECURE=false
SERVICE_NAME="Port Redirector"
Expand All @@ -13,17 +13,20 @@ function cleanup() {
rm /run/http_ports/$PROXY_PORT > /dev/null 2>&1
}

file_content=$(
file_content="$(
jq --null-input \
--arg listen_port "${LISTEN_PORT}" \
--arg metrics_port "${METRICS_PORT}" \
--arg proxy_port "${PROXY_PORT}" \
--arg proxy_secure "${PROXY_SECURE,,}" \
--arg service_name "${SERVICE_NAME}" \
'$ARGS.named'
)
)"

printf "%s" $file_content > /run/http_ports/$PROXY_PORT
printf "%s\n" "$file_content" > /run/http_ports/$PROXY_PORT

printf "Starting redirector server...\n"
/usr/bin/python3 /opt/ai-dock/fastapi/redirector/main.py
kill -9 $(lsof -t -i:$LISTEN_PORT) > /dev/null 2>&1 &
wait -n
/usr/bin/python3 /opt/ai-dock/fastapi/redirector/main.py \
-p $LISTEN_PORT \
8 changes: 7 additions & 1 deletion build/COPY_ROOT/opt/ai-dock/fastapi/redirector/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
from fastapi.responses import RedirectResponse
from fastapi.templating import Jinja2Templates
import uvicorn
import argparse

parser = argparse.ArgumentParser(description="Require port and service name",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-p", "--port", action="store", help="listen port", required="True", type=int)
args = parser.parse_args()

base_dir = "/opt/ai-dock/fastapi/redirector/"

Expand Down Expand Up @@ -133,7 +139,7 @@ def get_services():
uvicorn.run(
"main:app",
host="127.0.0.1",
port=1811,
port=args.port,
log_level="info",
reload=False,
workers=1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ <h1 id="status">Service List</h1>
<div>
<ul>
{% if context.tunnels == "true" %}
<li><a href="/cloudflare/{{ service["proxy_port"] }}">Cloudflare Tunnel</a></li>
<li><a href="/cloudflare/{{ service["proxy_port"] }}">Cloudflare Secured</a></li>
{% endif %}
{% if context.cloud != "paperspace.com" %}
<li><a href="/direct/{{ service["proxy_port"] }}">Direct/Default</a></li>
Expand Down

0 comments on commit fe226c4

Please sign in to comment.