From 10508376221833d66108337ee4b14d7458509074 Mon Sep 17 00:00:00 2001 From: Alexey Rybak <50731695+reluctantfuturist@users.noreply.github.com> Date: Mon, 28 Apr 2025 02:25:59 -0700 Subject: [PATCH] feat: Llama Stack Meta Reference installation script (#1383) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # What does this PR do? Add installation script for Llama Stack Meta Reference distro (Docker only). # Closes #1374 ## Test Plan ./instal.sh --------- Co-authored-by: Sébastien Han --- .github/workflows/install-script-ci.yml | 26 ++++++++ README.md | 7 ++ install.sh | 86 +++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 .github/workflows/install-script-ci.yml create mode 100755 install.sh diff --git a/.github/workflows/install-script-ci.yml b/.github/workflows/install-script-ci.yml new file mode 100644 index 000000000..2eb234c77 --- /dev/null +++ b/.github/workflows/install-script-ci.yml @@ -0,0 +1,26 @@ +name: Installer CI + +on: + pull_request: + paths: + - 'install.sh' + push: + paths: + - 'install.sh' + schedule: + - cron: '0 2 * * *' # every day at 02:00 UTC + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 + - name: Run ShellCheck on install.sh + run: shellcheck install.sh + smoke-test: + needs: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2 + - name: Run installer end-to-end + run: ./install.sh diff --git a/README.md b/README.md index 9a4f1a849..b2b2d12d9 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,13 @@ As more providers start supporting Llama 4, you can use them in Llama Stack as w +### 🚀 One-Line Installer 🚀 + +To try Llama Stack locally, run: + +```bash +curl -LsSf https://github.com/meta-llama/llama-stack/raw/main/install.sh | sh +``` ### Overview diff --git a/install.sh b/install.sh new file mode 100755 index 000000000..cf0437126 --- /dev/null +++ b/install.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env bash +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the terms described in the LICENSE file in +# the root directory of this source tree. + +set -Eeuo pipefail + +PORT=8321 +OLLAMA_PORT=11434 +MODEL_ALIAS="llama3.2:3b" +SERVER_IMAGE="llamastack/distribution-ollama:0.2.2" +WAIT_TIMEOUT=300 + +log(){ printf "\e[1;32m%s\e[0m\n" "$*"; } +die(){ printf "\e[1;31m❌ %s\e[0m\n" "$*" >&2; exit 1; } + +if command -v docker &> /dev/null; then + ENGINE="docker" + HOST_DNS="host.docker.internal" +elif command -v podman &> /dev/null; then + ENGINE="podman" + HOST_DNS="host.containers.internal" +else + die "Docker or Podman is required. Install Docker: https://docs.docker.com/get-docker/ or Podman: https://podman.io/getting-started/installation" +fi + +# Clean up any leftovers from earlier runs +for name in ollama-server llama-stack; do + ids=$($ENGINE ps -aq --filter "name=^${name}$") + if [ -n "$ids" ]; then + log "⚠️ Found existing container(s) for '${name}', removing..." + $ENGINE rm -f "$ids" + fi +done + +############################################################################### +# 1. Ollama +############################################################################### +log "🦙 Starting Ollama…" +$ENGINE run -d --name ollama-server \ + -p "${OLLAMA_PORT}:11434" \ + ollama/ollama > /dev/null 2>&1 + +log "⏳ Waiting for Ollama daemon…" +if ! timeout "$WAIT_TIMEOUT" bash -c \ + "until curl -fsS http://localhost:${OLLAMA_PORT}/ 2>/dev/null | grep -q 'Ollama'; do sleep 1; done"; then + log "❌ Ollama daemon did not become ready in ${WAIT_TIMEOUT}s; dumping container logs:" + $ENGINE logs ollama-server --tail=200 + die "Ollama startup failed" +fi + +log "📦 Ensuring model is pulled: ${MODEL_ALIAS}..." +$ENGINE exec ollama-server ollama pull "${MODEL_ALIAS}" > /dev/null 2>&1 + +############################################################################### +# 2. Llama‑Stack +############################################################################### +log "🦙📦 Starting Llama‑Stack…" +$ENGINE run -d --name llama-stack \ + -p "${PORT}:${PORT}" \ + --add-host="${HOST_DNS}:host-gateway" \ + "${SERVER_IMAGE}" \ + --port "${PORT}" \ + --env INFERENCE_MODEL="${MODEL_ALIAS}" \ + --env OLLAMA_URL="http://${HOST_DNS}:${OLLAMA_PORT}" > /dev/null 2>&1 + +log "⏳ Waiting for Llama-Stack API…" +if ! timeout "$WAIT_TIMEOUT" bash -c \ + "until curl -fsS http://localhost:${PORT}/v1/health 2>/dev/null | grep -q 'OK'; do sleep 1; done"; then + log "❌ Llama-Stack did not become ready in ${WAIT_TIMEOUT}s; dumping container logs:" + $ENGINE logs llama-stack --tail=200 + die "Llama-Stack startup failed" +fi + +############################################################################### +# Done +############################################################################### +log "" +log "🎉 Llama‑Stack is ready!" +log "👉 API endpoint: http://localhost:${PORT}" +log "📖 Documentation: https://llama-stack.readthedocs.io/en/latest/references/index.html" +log "💻 To access the llama‑stack CLI, exec into the container:" +log " $ENGINE exec -ti llama-stack bash" +log ""