Aller au contenu

Déployer Tabby Copilot auto-hébergé sur Ubuntu 22.04 (prêt pour la production)

Monter un serveur Tabby durci sur Ubuntu 22.04 avec NVIDIA + CUDA, modèles GGUF, systemd, indexation de dépôts, nginx + Let's Encrypt, jetons d'API.

On vous demande de monter une solution Copilot auto-hébergée pour que l’équipe arrête d’envoyer des corps de fonctions à un SaaS tiers. Le quickstart de Tabby fonctionne sur votre poste, le greffon IDE se connecte, les complétions reviennent en moins d’une seconde, vous remettez ça à l’équipe. Six mois plus tard, le GPU est en OOM sur une invite à long contexte parce que personne n’a borné la taille du modèle à la VRAM, le endpoint /v1/completions est ouvert sur l’internet public parce que l’exemple du README bindait 0.0.0.0:8080 et nginx a été un après-coup, un dépôt avec des fichiers .env a été indexé parce que l’indexeur ignorait votre .gitignore, et un scraper non authentifié siphonne les journaux de complétion qui contiennent du code propriétaire depuis l’endpoint de trace.

Ce qui se passe

Un déploiement Tabby réellement prêt pour la production demande plus que tabby serve. Le modèle doit tenir dans la VRAM avec la fenêtre de contexte choisie — un GGUF Q4 de 7B tient dans ~5 Go mais un Q4 de 13B à 8K de contexte en demande ~10 Go, et un OOM en plein milieu d’une complétion fait tomber le worker entier. L’écouteur HTTP doit bind 127.0.0.1 derrière nginx qui termine le TLS sur un vrai certificat Let’s Encrypt ; le jeton Authorization: Bearer doit être exigé sur chaque requête, y compris l’endpoint de métriques. L’indexeur de dépôt doit respecter .gitignore plus un .tabbyignore dédié pour que .env, *.pem, id_rsa*, les secrets dans les fixtures et les vidanges de données client ne deviennent jamais du contexte de récupération. La version du toolkit CUDA doit correspondre au pilote, sinon le démon bascule sur CPU à plus de 30 s par complétion et a l’air cassé pour chaque IDE du bureau. Aucune de ces étapes n’est individuellement critique — sautez-les et le service de complétion soit fuite des secrets, soit se fait scraper, soit ne fonctionne tout simplement pas sous charge.

Comment vérifier

Après installation, présence GPU et visibilité CUDA :

nvidia-smi
# Driver Version: 535.xx  CUDA Version: 12.2
# 0  NVIDIA L4   ...  14000MiB / 23034MiB

L’écouteur HTTP doit être sur 127.0.0.1, jamais 0.0.0.0 :

ss -lntp | grep -E ':(8080|443)\b'
# 127.0.0.1:8080  tabby
# 0.0.0.0:443     nginx

Aller-retour d’une vraie complétion à travers nginx avec le jeton d’API :

curl -fsS -X POST https://tabby.example.com/v1/completions \
  -H "Authorization: Bearer ${TABBY_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{"language":"python","segments":{"prefix":"def fib(n):\n    "}}' \
  | jq -r '.choices[0].text' | head -5

Si cet aller-retour expire, qu’une requête sans jeton retourne 200 au lieu de 401, ou que nvidia-smi montre le worker sur CPU, vous avez un problème avant même que le premier greffon IDE ne se connecte.

Le correctif

Enregistrez le script ci-dessous sous /root/setup-tabby-ubuntu22.sh, puis exécutez-le. Il déroule l’installation sur une VM Ubuntu 22.04 fraîche : mise à jour de base, ajustement noyau, limites de fichiers, UFW (SSH + HTTP + HTTPS seulement), durcissement SSH, mises à jour automatiques, pilote NVIDIA + toolkit CUDA (seulement si un GPU est détecté), binaire Tabby avec la fonctionnalité cuda, utilisateur système tabby dédié, répertoire de modèles à /var/lib/tabby avec le GGUF StarCoder2-3B pour la complétion et un GGUF Qwen2.5-Coder-1.5B pour le chat, gabarit .tabbyignore qui exclut les chemins à risque de secrets, unité systemd avec LimitNOFILE=64000 et le jeton d’API dans un fichier d’environnement (mode 600), nginx avec terminaison TLS et passage de l’en-tête Authorization, Let’s Encrypt via certbot, et une boucle d’attente qui vérifie que :8080 est prêt avant de déclarer le succès.

#!/usr/bin/env bash
set -euo pipefail

### Ubuntu 22.04 Tabby clean VM installer
### Keeps root SSH key login enabled
### Disables SSH password login
### Enables automatic security updates
### Installs NVIDIA driver + CUDA (if GPU present), Tabby, nginx, Let's Encrypt
### No local backups; assumes VM-level backup. Model weights re-downloadable from upstream.
### Reboot remains manual

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

: "${TABBY_DOMAIN:?Set TABBY_DOMAIN=tabby.example.com}"
: "${TABBY_EMAIL:?Set TABBY_EMAIL=ops@example.com for Let's Encrypt}"
TABBY_VERSION="${TABBY_VERSION:-0.18.0}"
TABBY_TOKEN="${TABBY_TOKEN:-$(openssl rand -hex 32)}"
TABBY_MODEL="${TABBY_MODEL:-StarCoder2-3B}"
TABBY_CHAT_MODEL="${TABBY_CHAT_MODEL:-Qwen2.5-Coder-1.5B-Instruct}"

echo
echo "========================================"
echo "Tabby Ubuntu 22.04 Setup"
echo "========================================"
echo

echo "==> Updating base OS"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade

echo "==> Installing base packages"
apt-get -y install \
  vim curl wget ca-certificates gnupg2 \
  chrony fail2ban unattended-upgrades \
  ufw lsof tcpdump dnsutils tar gzip \
  iproute2 net-tools openssl jq \
  build-essential pkg-config libssl-dev \
  git software-properties-common

echo "==> Enabling time sync"
systemctl enable --now chrony
timedatectl set-ntp true

echo "==> Applying kernel/network tuning"
cat > /etc/sysctl.d/99-tabby.conf <<'SYSCTL'
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr

net.core.somaxconn = 4096
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.ip_local_port_range = 10240 65535

net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0

kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
fs.file-max = 2097152
SYSCTL

modprobe tcp_bbr || true
echo tcp_bbr > /etc/modules-load.d/bbr.conf
sysctl --system

echo "==> Setting file limits"
cat > /etc/security/limits.d/99-tabby.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
root soft nofile 64000
root hard nofile 64000
LIMITS

echo "==> Configuring UFW"
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable

echo "==> Hardening SSH while keeping root SSH key login enabled"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)

set_sshd_option() {
  local key="$1"
  local value="$2"
  if grep -qE "^[#[:space:]]*${key}[[:space:]]+" /etc/ssh/sshd_config; then
    sed -i "s|^[#[:space:]]*${key}[[:space:]].*|${key} ${value}|" /etc/ssh/sshd_config
  else
    echo "${key} ${value}" >> /etc/ssh/sshd_config
  fi
}

set_sshd_option PermitRootLogin prohibit-password
set_sshd_option PasswordAuthentication no
set_sshd_option PubkeyAuthentication yes
set_sshd_option KbdInteractiveAuthentication no
set_sshd_option ChallengeResponseAuthentication no
set_sshd_option X11Forwarding no
set_sshd_option ClientAliveInterval 300
set_sshd_option ClientAliveCountMax 2
set_sshd_option MaxAuthTries 4

sshd -t
systemctl restart ssh

echo "==> Configuring fail2ban"
mkdir -p /etc/fail2ban/jail.d
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN

systemctl enable --now fail2ban

echo "==> Configuring unattended-upgrades for security"
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTOUPG'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
AUTOUPG

echo "==> Detecting GPU"
GPU_PRESENT=0
if command -v lspci >/dev/null 2>&1; then
  if lspci | grep -i nvidia >/dev/null 2>&1; then
    GPU_PRESENT=1
  fi
else
  apt-get -y install pciutils
  if lspci | grep -i nvidia >/dev/null 2>&1; then
    GPU_PRESENT=1
  fi
fi

if [[ "$GPU_PRESENT" -eq 1 ]]; then
  echo "==> NVIDIA GPU detected — installing driver + CUDA 12.2"
  apt-get -y install linux-headers-$(uname -r)
  wget -qO /tmp/cuda-keyring.deb \
    https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
  dpkg -i /tmp/cuda-keyring.deb
  apt-get update
  apt-get -y install cuda-toolkit-12-2 nvidia-driver-535
  cat > /etc/profile.d/cuda.sh <<'CUDAENV'
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
CUDAENV
  ldconfig
else
  echo "==> No NVIDIA GPU detected — Tabby will run on CPU (not recommended for production)."
fi

echo "==> Creating tabby system user and directories"
if ! id tabby >/dev/null 2>&1; then
  useradd --system --home /var/lib/tabby --shell /usr/sbin/nologin tabby
fi
mkdir -p /var/lib/tabby /var/log/tabby /etc/tabby
chown -R tabby:tabby /var/lib/tabby /var/log/tabby
chmod 750 /var/lib/tabby /var/log/tabby

echo "==> Downloading Tabby ${TABBY_VERSION} (cuda build)"
TABBY_TARBALL="tabby_x86_64-manylinux2014-cuda122.zip"
if [[ "$GPU_PRESENT" -eq 0 ]]; then
  TABBY_TARBALL="tabby_x86_64-manylinux2014.zip"
fi

cd /tmp
wget -qO tabby.zip \
  "https://github.com/TabbyML/tabby/releases/download/v${TABBY_VERSION}/${TABBY_TARBALL}"
apt-get -y install unzip
unzip -o tabby.zip -d /tmp/tabby-bin
install -m 0755 /tmp/tabby-bin/tabby /usr/local/bin/tabby

echo "==> Writing .tabbyignore template (keep secrets out of the index)"
cat > /var/lib/tabby/.tabbyignore <<'TABBYIGNORE'
# Tabby repo indexer ignore list — keep secrets out of completion context
.env
.env.*
*.pem
*.key
*.p12
*.pfx
id_rsa
id_rsa.*
id_ed25519
id_ed25519.*
known_hosts
**/secrets/**
**/credentials/**
**/.aws/**
**/.gcp/**
**/.kube/**
**/node_modules/**
**/vendor/**
**/dist/**
**/build/**
**/.git/**
**/__pycache__/**
**/*.log
**/fixtures/secrets/**
TABBYIGNORE

chown tabby:tabby /var/lib/tabby/.tabbyignore
chmod 640 /var/lib/tabby/.tabbyignore

echo "==> Writing Tabby env file"
cat > /etc/tabby/tabby.env <<ENV
TABBY_TOKEN=${TABBY_TOKEN}
TABBY_MODEL=${TABBY_MODEL}
TABBY_CHAT_MODEL=${TABBY_CHAT_MODEL}
TABBY_ROOT=/var/lib/tabby
RUST_LOG=info
ENV

chmod 600 /etc/tabby/tabby.env
chown root:tabby /etc/tabby/tabby.env

echo "==> Writing Tabby systemd unit"
DEVICE_FLAG="--device cuda"
if [[ "$GPU_PRESENT" -eq 0 ]]; then
  DEVICE_FLAG=""
fi

cat > /etc/systemd/system/tabby.service <<UNIT
[Unit]
Description=Tabby self-hosted code completion server
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=tabby
Group=tabby
EnvironmentFile=/etc/tabby/tabby.env
WorkingDirectory=/var/lib/tabby
ExecStart=/usr/local/bin/tabby serve \\
  --model \${TABBY_MODEL} \\
  --chat-model \${TABBY_CHAT_MODEL} \\
  ${DEVICE_FLAG} \\
  --host 127.0.0.1 \\
  --port 8080
Restart=on-failure
RestartSec=10
LimitNOFILE=64000
NoNewPrivileges=true
ProtectSystem=full
ProtectHome=true
PrivateTmp=true

[Install]
WantedBy=multi-user.target
UNIT

systemctl daemon-reload
systemctl enable --now tabby

echo "==> Waiting for Tabby on 127.0.0.1:8080 (first run downloads model weights)"
for i in {1..180}; do
  if ss -lntp | grep -q '127.0.0.1:8080'; then
    break
  fi
  sleep 2
done

if ! ss -lntp | grep -q '127.0.0.1:8080'; then
  echo "Tabby failed to listen on 127.0.0.1:8080"
  journalctl -u tabby -n 200 --no-pager || true
  exit 1
fi

echo "==> Installing nginx and certbot"
apt-get -y install nginx certbot python3-certbot-nginx

cat > /etc/nginx/sites-available/tabby <<NGINX
upstream tabby_backend {
    server 127.0.0.1:8080;
    keepalive 32;
}

server {
    listen 80;
    listen [::]:80;
    server_name ${TABBY_DOMAIN};
    return 301 https://\$host\$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name ${TABBY_DOMAIN};

    client_max_body_size 10M;
    proxy_read_timeout   300s;
    proxy_send_timeout   300s;
    proxy_connect_timeout 60s;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Content-Type-Options nosniff always;
    add_header X-Frame-Options SAMEORIGIN always;
    add_header Referrer-Policy strict-origin-when-cross-origin always;

    location / {
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;
        proxy_set_header Authorization \$http_authorization;
        proxy_http_version 1.1;
        proxy_pass http://tabby_backend;
    }
}
NGINX

ln -sf /etc/nginx/sites-available/tabby /etc/nginx/sites-enabled/tabby
rm -f /etc/nginx/sites-enabled/default

nginx -t
systemctl enable --now nginx
systemctl reload nginx

echo "==> Requesting Let's Encrypt certificate"
certbot --nginx --non-interactive --agree-tos \
  -m "${TABBY_EMAIL}" -d "${TABBY_DOMAIN}" --redirect

systemctl enable --now certbot.timer

echo "==> Final package update"
apt-get -y upgrade

echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Kernel:"
uname -r

echo
if [[ "$GPU_PRESENT" -eq 1 ]]; then
  echo "GPU:"
  nvidia-smi -L || true
else
  echo "GPU: not present (CPU mode)"
fi

echo
echo "Listeners:"
ss -lntp | grep -E ':(80|443|8080)\b' || true

echo
echo "Services:"
systemctl is-active tabby nginx fail2ban chrony || true

echo
echo "API token (store in your secrets manager, then remove /etc/tabby/tabby.env from disk):"
echo "${TABBY_TOKEN}"

echo
echo "IDE plugin endpoint:"
echo "https://${TABBY_DOMAIN}/"

echo
echo "Smoke test:"
echo "curl -fsS -X POST https://${TABBY_DOMAIN}/v1/completions \\"
echo "  -H 'Authorization: Bearer ${TABBY_TOKEN}' \\"
echo "  -H 'Content-Type: application/json' \\"
echo "  -d '{\"language\":\"python\",\"segments\":{\"prefix\":\"def fib(n):\\n    \"}}'"

echo
echo "Next steps:"
echo "1) Install the Tabby IDE plugin (VS Code, JetBrains, Vim) — set endpoint to https://${TABBY_DOMAIN}/ and paste the API token."
echo "2) Review /var/lib/tabby/.tabbyignore before adding repos via the admin UI — secrets must be excluded."
echo "3) Rotate TABBY_TOKEN out of /etc/tabby/tabby.env into your secrets manager."

Rendez-le exécutable et lancez-le :

chmod 700 /root/setup-tabby-ubuntu22.sh
TABBY_DOMAIN=tabby.example.com TABBY_EMAIL=ops@example.com /root/setup-tabby-ubuntu22.sh

Le premier démarrage télécharge les poids GGUF dans /var/lib/tabby/models — comptez quelques minutes avant que :8080 ne soit prêt. Une fois l’écouteur en place, installez le greffon Tabby dans VS Code ou JetBrains, pointez-le vers https://tabby.example.com/ avec le jeton bearer, et lancez le curl de validation de la section vérification. Avant d’ajouter un dépôt via le tableau de bord d’administration, révisez /var/lib/tabby/.tabbyignore — le contexte de complétion correspond à tout ce que l’indexeur lit, donc un .env égaré devient une suggestion d’autocomplétion. Le script n’active volontairement pas de sauvegardes au niveau hôte — les poids des modèles sont retéléchargeables depuis l’amont et l’index des dépôts est reconstruisible, donc les instantanés au niveau VM suffisent pour la reprise après sinistre.

Faites tourner le code-AI de production sur un environnement GPU infogéré Stack Harbor avec marge VRAM, cadence de patching et escalade Sev-1 en place : Cloud compute GPU.