Skip to content

Commit

Permalink
Updates...
Browse files Browse the repository at this point in the history
Fix logging
UI improvements
Improve workspace sync logic
Add SERVERLESS env for slim startup
Add build-essential package
  • Loading branch information
robballantyne committed Oct 23, 2023
1 parent fe226c4 commit 33d8ec2
Show file tree
Hide file tree
Showing 29 changed files with 652 additions and 263 deletions.
10 changes: 5 additions & 5 deletions build/COPY_ROOT/etc/supervisor/supervisord/conf.d/caddy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ command=supervisor-caddy.sh
process_name=%(program_name)s
numprocs=1
directory=%(ENV_WORKSPACE)s
priority=50000
priority=1000
autostart=true
startsecs=3
startsecs=0
startretries=3
autorestart=unexpected
stopsignal=TERM
Expand All @@ -15,7 +15,7 @@ killasgroup=true
stdout_logfile=/var/log/supervisor/caddy.log
stdout_logfile_maxbytes=20MB
stdout_logfile_backups=1
stderr_logfile=/var/log/supervisor/caddy.error.log
stderr_logfile_maxbytes=20MB
stderr_logfile_backups=1
stderr_logfile=/dev/null
stderr_logfile_maxbytes=0
stderr_logfile_backups=0
environment=PROC_NAME="%(program_name)s"
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ numprocs=%(ENV_SUPERVISOR_START_CLOUDFLARED)s
directory=/root
priority=100
autostart=true
startsecs=3
startsecs=0
startretries=3
autorestart=unexpected
stopsignal=TERM
Expand All @@ -15,7 +15,7 @@ killasgroup=true
stdout_logfile=/var/log/supervisor/cloudflared.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=1
stderr_logfile=/var/log/supervisor/cloudflared.error.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=1
stderr_logfile=/dev/null
stderr_logfile_maxbytes=0
stderr_logfile_backups=0
environment=PROC_NAME="%(program_name)s"
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ command=supervisor-logtail.sh
process_name=%(program_name)s
numprocs=1
directory=/var/log/supervisor
; All other programs should be up first
priority=100000
priority=100
autostart=true
startsecs=0
startretries=3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ command=supervisor-quicktunnel.sh
process_name=="%(program_name)s_%(process_num)s"
numprocs=%(ENV_CF_QUICK_TUNNELS_COUNT)s
directory=%(ENV_WORKSPACE)s
priority=50000
priority=100
autostart=true
startsecs=3
startsecs=0
startretries=3
autorestart=unexpected
stopsignal=TERM
Expand All @@ -15,7 +15,7 @@ killasgroup=true
stdout_logfile=/var/log/supervisor/quicktunnel-%(process_num)s.log
stdout_logfile_maxbytes=20MB
stdout_logfile_backups=1
stderr_logfile=/var/log/supervisor/quicktunnel-%(process_num)s.error.log
stderr_logfile_maxbytes=20MB
stderr_logfile_backups=1
stderr_logfile=/dev/null
stderr_logfile_maxbytes=0
stderr_logfile_backups=0
environment=PROC_NAME="%(program_name)s",PROC_NUM=%(process_num)d
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ command=supervisor-rclone.sh
process_name=="%(program_name)s_%(process_num)s"
numprocs=%(ENV_RCLONE_MOUNT_COUNT)s
directory=%(ENV_WORKSPACE)s
priority=300
priority=100
autostart=true
startsecs=3
startsecs=0
startretries=3
autorestart=unexpected
stopsignal=TERM
Expand All @@ -15,7 +15,7 @@ killasgroup=true
stdout_logfile=/var/log/supervisor/rclone-mount-%(process_num)s.log
stdout_logfile_maxbytes=20MB
stdout_logfile_backups=1
stderr_logfile=/var/log/supervisor/rclone-mount-%(process_num)s.error.log
stderr_logfile_maxbytes=20MB
stderr_logfile_backups=1
stderr_logfile=/dev/null
stderr_logfile_maxbytes=0
stderr_logfile_backups=0
environment=PROC_NAME="%(program_name)s",PROC_NUM=%(process_num)d
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ command=supervisor-redirector.sh
process_name=%(program_name)s
numprocs=1
directory=/opt/ai-dock/fastapi/redirector
priority=51000
priority=100
autostart=true
startsecs=3
startsecs=0
startretries=3
autorestart=unexpected
stopsignal=TERM
Expand All @@ -15,6 +15,6 @@ killasgroup=true
stdout_logfile=/var/log/supervisor/redirector.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=1
stderr_logfile=/var/log/supervisor/redirector.error.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=1
stderr_logfile=/dev/null
stderr_logfile_maxbytes=0
stderr_logfile_backups=0
21 changes: 21 additions & 0 deletions build/COPY_ROOT/etc/supervisor/supervisord/conf.d/serverless.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[program:serverless]
command=/opt/ai-dock/bin/supervisor-serverless.sh
process_name=%(program_name)s
numprocs=1
directory=/root
priority=100
autostart=true
startsecs=0
startretries=3
autorestart=unexpected
stopsignal=TERM
stopwaitsecs=10
stopasgroup=true
killasgroup=true
stdout_logfile=/var/log/supervisor/serverless.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=1
stderr_logfile=/dev/null
stderr_logfile_maxbytes=0
stderr_logfile_backups=0
environment=PROC_NAME="%(program_name)s"
10 changes: 5 additions & 5 deletions build/COPY_ROOT/etc/supervisor/supervisord/conf.d/sshd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ command=supervisor-sshd.sh
process_name=%(program_name)s
numprocs=1
directory=/root
priority=200
priority=100
autostart=true
startsecs=3
startsecs=0
startretries=3
autorestart=unexpected
stopsignal=TERM
Expand All @@ -15,7 +15,7 @@ killasgroup=true
stdout_logfile=/var/log/supervisor/sshd.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=1
stderr_logfile=/var/log/supervisor/sshd.error.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=1
stderr_logfile=/dev/null
stderr_logfile_maxbytes=0
stderr_logfile_backups=0
environment=PROC_NAME="%(program_name)s"
22 changes: 20 additions & 2 deletions build/COPY_ROOT/opt/ai-dock/bin/build/layer0/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ set -eo pipefail
apt-get update
apt-get upgrade -y --no-install-recommends

function download() {
set +e
while ! wget -c -O $1 $2
do echo "will retry in 2 seconds"; sleep 2; done
set -e
}

# System packages
$APT_INSTALL \
acl \
bc \
build-essential \
bzip2 \
ca-certificates \
curl \
Expand Down Expand Up @@ -48,11 +56,13 @@ $APT_INSTALL \

# Get caddy server
mkdir -p /opt/caddy/bin
curl -Ls https://github.com/caddyserver/caddy/releases/download/v2.7.4/caddy_2.7.4_linux_amd64.tar.gz | tar -xz -C /opt/caddy
download caddy.tar.gz https://github.com/caddyserver/caddy/releases/download/v2.7.5/caddy_2.7.5_linux_amd64.tar.gz
tar -xf caddy.tar.gz -C /opt/caddy
rm caddy.tar.gz
mv /opt/caddy/caddy /opt/caddy/bin

# Get Cloudflare daemon
curl -Lso cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
download cloudflared.deb https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
dpkg -i cloudflared.deb
rm cloudflared.deb

Expand All @@ -73,6 +83,14 @@ cd /opt/micromamba
curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba
micromamba shell init --shell bash --root-prefix=/opt/micromamba

# Cloud helpers - Serverless support
$MAMBA_CREATE -n vast -c conda-forge python=3.10

$MAMBA_CREATE -n runpod -c conda-forge python=3.10
micromamba run -n runpod $PIP_INSTALL \
runpod


# Ensure critical paths/files are present
mkdir -p --mode=0755 /etc/apt/keyrings
mkdir -p /var/log/supervisor
Expand Down
38 changes: 38 additions & 0 deletions build/COPY_ROOT/opt/ai-dock/bin/cfnt-url.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

trap cleanup EXIT

function cleanup() {
kill $(jobs -p) >/dev/null 2>&1
}

unset -v port
metrics=""
while getopts p: flag
do
case "${flag}" in
p) port="${OPTARG}";;
esac
done

if [[ -z $port ]]; then
printf "port (-p) is required\n"
exit 1
fi

listen_port=$(cat /run/http_ports/${port} | jq -r '.listen_port' 2>/dev/null)
ingress_json=$(curl -s http://localhost:2999/config | jq -r .config.ingress 2>/dev/null)
ingress_count=$(printf "%s" "$ingress_json" | jq length 2>/dev/null)

for ((i=0;i<ingress_count;i++)); do
ingress=$(printf "%s" "$ingress_json" | jq -r ".[${i}]" 2>/dev/null)
service_port=$(printf "%s" "$ingress" | jq -r .service | cut -d ":" -f 3 2>/dev/null)

if [[ $service_port = $port ]]; then
printf "https://%s\n" $(echo "$ingress" | jq -r .hostname 2>/dev/null)
exit 0
fi
done

printf "No cloudflare tunnel running for localhost:%s\n" $port
exit 1
Loading

0 comments on commit 33d8ec2

Please sign in to comment.