Skip to content

Commit

Permalink
feat: add UI to Nomad inference endpoints (#76)
Browse files Browse the repository at this point in the history
* feat: add UI to deploy

* feat: add support for user-defined `custom` endpoint
  • Loading branch information
IgnacioHeredia authored Nov 25, 2024
1 parent a3cf0aa commit 429c726
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
12 changes: 12 additions & 0 deletions ai4papi/routers/v1/deployments/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,20 @@ def create_deployment(
# Always exclude initial 'dataset_download' task, as it is used as template
exclude_tasks = ['dataset_download']

# If DEEPaaS was not launched, do not launch UI because it will fail
if user_conf['general']['service'] != 'deepaas':
exclude_tasks.append('ui')

tasks[:] = [t for t in tasks if t['Name'] not in exclude_tasks]

# Remove appropriate Traefik domains in each case (no need to remove the ports)
services = nomad_conf['TaskGroups'][0]['Services']
if user_conf['general']['service'] == 'deepaas':
exclude_services = ['ide']
else:
exclude_services = ['ui']
services[:] = [s for s in services if s['PortLabel'] not in exclude_services]

# Submit job
r = nomad.create_deployment(nomad_conf)

Expand Down
65 changes: 64 additions & 1 deletion etc/modules/nomad.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ job "module-${JOB_UUID}" {
port "ide" {
to = 8888
}
port "ui" {
to = 80
}
port "custom" {
to = 80
}
}

service {
Expand Down Expand Up @@ -124,6 +130,26 @@ job "module-${JOB_UUID}" {
]
}

service {
name = "${JOB_UUID}-ui"
port = "ui"
tags = [
"traefik.enable=true",
"traefik.http.routers.${JOB_UUID}-ui.tls=true",
"traefik.http.routers.${JOB_UUID}-ui.rule=Host(`ui-${HOSTNAME}.${meta.domain}-${BASE_DOMAIN}`, `www.ui-${HOSTNAME}.${meta.domain}-${BASE_DOMAIN}`)",
]
}

service {
name = "${JOB_UUID}-custom"
port = "custom"
tags = [
"traefik.enable=true",
"traefik.http.routers.${JOB_UUID}-custom.tls=true",
"traefik.http.routers.${JOB_UUID}-custom.rule=Host(`custom-${HOSTNAME}.${meta.domain}-${BASE_DOMAIN}`, `www.custom-${HOSTNAME}.${meta.domain}-${BASE_DOMAIN}`)",
]
}

ephemeral_disk {
size = ${DISK}
}
Expand Down Expand Up @@ -236,7 +262,7 @@ job "module-${JOB_UUID}" {
image = "${DOCKER_IMAGE}:${DOCKER_TAG}"
command = "deep-start"
args = ["--${SERVICE}"]
ports = ["api", "monitor", "ide"]
ports = ["api", "monitor", "ide", "custom"]
shm_size = ${SHARED_MEMORY}
memory_hard_limit = ${RAM}
volumes = [
Expand Down Expand Up @@ -276,6 +302,43 @@ job "module-${JOB_UUID}" {
}
}

task "ui" { # DEEPaaS UI (Gradio)

# Run as post-start to make sure DEEPaaS up before launching the UI
lifecycle {
hook = "poststart"
sidecar = true
}

driver = "docker"

config {
force_pull = true
image = "registry.services.ai4os.eu/ai4os/deepaas_ui:latest"
ports = ["ui"]
shm_size = 250000000 # 250MB
memory_hard_limit = 500 # MB
}

env {
DURATION = "10m" # kill job after 10 mins
UI_PORT = 80
}

resources {
cpu = 500 # MHz
memory = 500 # MB
memory_max = 500 # MB
}

# Do not try to restart a try-me job if it raises error (module incompatible with Gradio UI)
restart {
attempts = 0
mode = "fail"
}

}

task "storage_cleanup" {
// Unmount empty storage folder and delete it from host

Expand Down
2 changes: 1 addition & 1 deletion etc/try_me/nomad.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ job "try-${JOB_UUID}" {
to = 80 # -1 will assign random port
}
port "api" {
to = 5000 # -1 will assign random port
to = 5000
}
}

Expand Down

0 comments on commit 429c726

Please sign in to comment.