diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..f667ab162 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,19 @@ +.venv +__pycache__ +*.pyc +*.pyo +*.pyd +*.so +.git +.gitignore +htmlcov* +.coverage +coverage* +.cache +.mypy_cache +.pytest_cache +.ruff_cache +uv.lock +node_modules +build +/tmp diff --git a/.github/workflows/install-script-ci.yml b/.github/workflows/install-script-ci.yml index a37919f56..82aa56482 100644 --- a/.github/workflows/install-script-ci.yml +++ b/.github/workflows/install-script-ci.yml @@ -30,8 +30,11 @@ jobs: - name: Build a single provider run: | - USE_COPY_NOT_MOUNT=true LLAMA_STACK_DIR=. uv run --no-sync \ - llama stack build --template starter --image-type container --image-name test + docker build . \ + -f containers/Containerfile \ + --build-arg INSTALL_MODE=editable \ + --build-arg DISTRO_NAME=starter \ + --tag llama-stack:starter-ci - name: Run installer end-to-end run: | diff --git a/.github/workflows/providers-build.yml b/.github/workflows/providers-build.yml index 53b6edccf..76f9e159a 100644 --- a/.github/workflows/providers-build.yml +++ b/.github/workflows/providers-build.yml @@ -14,6 +14,8 @@ on: - '.github/workflows/providers-build.yml' - 'llama_stack/distributions/**' - 'pyproject.toml' + - 'containers/Containerfile' + - '.dockerignore' pull_request: paths: @@ -24,6 +26,8 @@ on: - '.github/workflows/providers-build.yml' - 'llama_stack/distributions/**' - 'pyproject.toml' + - 'containers/Containerfile' + - '.dockerignore' concurrency: group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.ref }} @@ -60,15 +64,25 @@ jobs: - name: Install dependencies uses: ./.github/actions/setup-runner - - name: Print build dependencies + - name: List build dependencies run: | - uv run llama stack build --distro ${{ matrix.distro }} --image-type ${{ matrix.image-type }} --image-name test --print-deps-only + uv run llama stack list-deps ${{ matrix.distro }} | tee deps.txt - - name: Run Llama Stack Build + - name: Install distribution into venv + if: matrix.image-type == 'venv' run: | - # USE_COPY_NOT_MOUNT is set to true since mounting is not supported by docker buildx, we use COPY instead - # LLAMA_STACK_DIR is set to the current directory so we are building from the source - USE_COPY_NOT_MOUNT=true LLAMA_STACK_DIR=. uv run llama stack build --distro ${{ matrix.distro }} --image-type ${{ matrix.image-type }} --image-name test + if [ -s deps.txt ]; then + xargs -L1 uv pip install < deps.txt + fi + + - name: Build container image + if: matrix.image-type == 'container' + run: | + docker build . \ + -f containers/Containerfile \ + --build-arg INSTALL_MODE=editable \ + --build-arg DISTRO_NAME=${{ matrix.distro }} \ + --tag llama-stack:${{ matrix.distro }}-ci - name: Print dependencies in the image if: matrix.image-type == 'venv' @@ -86,7 +100,7 @@ jobs: - name: Build a single provider run: | - USE_COPY_NOT_MOUNT=true LLAMA_STACK_DIR=. uv run llama stack build --image-type venv --image-name test --providers inference=remote::ollama + LLAMA_STACK_DIR=. uv run llama stack build --image-type venv --image-name test --providers inference=remote::ollama build-custom-container-distribution: runs-on: ubuntu-latest @@ -97,11 +111,16 @@ jobs: - name: Install dependencies uses: ./.github/actions/setup-runner - - name: Build a single provider + - name: Build container image run: | - yq -i '.image_type = "container"' llama_stack/distributions/ci-tests/build.yaml - yq -i '.image_name = "test"' llama_stack/distributions/ci-tests/build.yaml - USE_COPY_NOT_MOUNT=true LLAMA_STACK_DIR=. uv run llama stack build --config llama_stack/distributions/ci-tests/build.yaml + BASE_IMAGE=$(yq -r '.distribution_spec.container_image // "python:3.12-slim"' llama_stack/distributions/ci-tests/build.yaml) + docker build . \ + -f containers/Containerfile \ + --build-arg INSTALL_MODE=editable \ + --build-arg DISTRO_NAME=ci-tests \ + --build-arg BASE_IMAGE="$BASE_IMAGE" \ + --build-arg RUN_CONFIG_PATH=/workspace/llama_stack/distributions/ci-tests/run.yaml \ + -t llama-stack:ci-tests - name: Inspect the container image entrypoint run: | @@ -112,7 +131,7 @@ jobs: fi entrypoint=$(docker inspect --format '{{ .Config.Entrypoint }}' $IMAGE_ID) echo "Entrypoint: $entrypoint" - if [ "$entrypoint" != "[llama stack run /app/run.yaml]" ]; then + if [ "$entrypoint" != "[/usr/local/bin/llama-stack-entrypoint.sh]" ]; then echo "Entrypoint is not correct" exit 1 fi @@ -129,17 +148,19 @@ jobs: - name: Pin distribution to UBI9 base run: | yq -i ' - .image_type = "container" | - .image_name = "ubi9-test" | .distribution_spec.container_image = "registry.access.redhat.com/ubi9:latest" ' llama_stack/distributions/ci-tests/build.yaml - - name: Build dev container (UBI9) - env: - USE_COPY_NOT_MOUNT: "true" - LLAMA_STACK_DIR: "." + - name: Build UBI9 container image run: | - uv run llama stack build --config llama_stack/distributions/ci-tests/build.yaml + BASE_IMAGE=$(yq -r '.distribution_spec.container_image // "registry.access.redhat.com/ubi9:latest"' llama_stack/distributions/ci-tests/build.yaml) + docker build . \ + -f containers/Containerfile \ + --build-arg INSTALL_MODE=editable \ + --build-arg DISTRO_NAME=ci-tests \ + --build-arg BASE_IMAGE="$BASE_IMAGE" \ + --build-arg RUN_CONFIG_PATH=/workspace/llama_stack/distributions/ci-tests/run.yaml \ + -t llama-stack:ci-tests-ubi9 - name: Inspect UBI9 image run: | @@ -150,7 +171,7 @@ jobs: fi entrypoint=$(docker inspect --format '{{ .Config.Entrypoint }}' $IMAGE_ID) echo "Entrypoint: $entrypoint" - if [ "$entrypoint" != "[llama stack run /app/run.yaml]" ]; then + if [ "$entrypoint" != "[/usr/local/bin/llama-stack-entrypoint.sh]" ]; then echo "Entrypoint is not correct" exit 1 fi diff --git a/.github/workflows/test-external-provider-module.yml b/.github/workflows/test-external-provider-module.yml index b43cefb27..8421b78d3 100644 --- a/.github/workflows/test-external-provider-module.yml +++ b/.github/workflows/test-external-provider-module.yml @@ -48,7 +48,12 @@ jobs: - name: Build distro from config file run: | - USE_COPY_NOT_MOUNT=true LLAMA_STACK_DIR=. uv run llama stack build --config tests/external/ramalama-stack/build.yaml + docker build . \ + -f containers/Containerfile \ + --build-arg INSTALL_MODE=editable \ + --build-arg DISTRO_NAME=ramalama-stack \ + --build-arg RUN_CONFIG_PATH=/workspace/tests/external/ramalama-stack/run.yaml \ + --tag llama-stack:ramalama-stack - name: Start Llama Stack server in background if: ${{ matrix.image-type }} == 'venv' diff --git a/.github/workflows/test-external.yml b/.github/workflows/test-external.yml index a1013ad9e..3ae6793ea 100644 --- a/.github/workflows/test-external.yml +++ b/.github/workflows/test-external.yml @@ -44,7 +44,7 @@ jobs: - name: Print distro dependencies run: | - USE_COPY_NOT_MOUNT=true LLAMA_STACK_DIR=. uv run --no-sync llama stack list-deps tests/external/build.yaml + uv run --no-sync llama stack list-deps tests/external/build.yaml - name: Build distro from config file run: |