diff --git a/.devcontainer/Containerfile b/.devcontainer/Containerfile new file mode 100644 index 000000000..0289dffb6 --- /dev/null +++ b/.devcontainer/Containerfile @@ -0,0 +1,9 @@ +FROM registry.access.redhat.com/ubi9/python-311:1-52 + +USER root + +COPY playground/tests/requirements.txt . + +RUN pip3 install -r requirements.txt && \ + dnf install -y podman buildah && \ + dnf clean all diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..2954b9a99 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,12 @@ +{ + "name": "recepies", + "build": { + "dockerfile": "Containerfile", + "context": ".." + }, + "privileged": true, + "containerEnv": { + "REGISTRY": "ghcr.io", + "IMAGE_NAME": "playground" + } +} diff --git a/.github/workflows/playground.yaml b/.github/workflows/playground.yaml new file mode 100644 index 000000000..d561265d7 --- /dev/null +++ b/.github/workflows/playground.yaml @@ -0,0 +1,54 @@ +name: playground + +on: + pull_request: + branches: + - main + push: + branches: + - main + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository_owner }}/playground + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + services: + registry: + image: registry:2.8.3 + ports: + - 5000:5000 + steps: + - uses: actions/checkout@v4.1.1 + + - name: Login to ghcr + uses: docker/login-action@v3.1.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Buildah Action + uses: redhat-actions/buildah-build@v2.13 + with: + image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: latest + containerfiles: ./playground/Containerfile + context: playground + + - name: Set up Python + uses: actions/setup-python@v5.0.0 + + - name: Install python modules + run: pip install -r playground/tests/requirements.txt + + - name: Download model + run: wget -P locallm/models https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q5_K_S.gguf + + - name: Run tests + run: pytest -s diff --git a/.gitignore b/.gitignore index 3c2129ef7..50cf3e3cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.gguf *.bin *_pycache_* +port_check.lock diff --git a/playground/Containerfile b/playground/Containerfile index e47b81dd9..89536f5b3 100644 --- a/playground/Containerfile +++ b/playground/Containerfile @@ -1,8 +1,7 @@ -FROM registry.access.redhat.com/ubi9/python-39:latest +FROM registry.access.redhat.com/ubi9/python-311:1-52 WORKDIR /locallm COPY requirements.txt /locallm/requirements.txt -RUN pip install --upgrade pip -RUN pip install --no-cache-dir --upgrade -r /locallm/requirements.txt +RUN pip install --no-cache-dir --verbose -r /locallm/requirements.txt COPY run.sh run.sh EXPOSE 8001 ENTRYPOINT [ "sh", "run.sh" ] diff --git a/playground/requirements.txt b/playground/requirements.txt index bbea3dd85..a3ffc4c08 100644 --- a/playground/requirements.txt +++ b/playground/requirements.txt @@ -1 +1,2 @@ -llama-cpp-python[server] \ No newline at end of file +llama-cpp-python[server]==0.2.57 +pip==24.0 diff --git a/playground/tests/__init__.py b/playground/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/playground/tests/conftest.py b/playground/tests/conftest.py new file mode 100644 index 000000000..edce735e1 --- /dev/null +++ b/playground/tests/conftest.py @@ -0,0 +1,24 @@ +import pytest_container +import os + + +TW = pytest_container.Container( + url=f"containers-storage:{os.environ['REGISTRY']}/{os.environ['IMAGE_NAME']}", + volume_mounts=[ + pytest_container.container.BindMount( + "/locallm/models", + host_path="./locallm/models", + flags=["ro"] + ) + ], + extra_environment_variables={"HOST": "0.0.0.0", "PORT": "8001"}, + forwarded_ports=[ + pytest_container.PortForwarding( + container_port=8001, + host_port=8001 + ) + ] + ) + +def pytest_generate_tests(metafunc): + pytest_container.auto_container_parametrize(metafunc) diff --git a/playground/tests/requirements.txt b/playground/tests/requirements.txt new file mode 100644 index 000000000..f20873d25 --- /dev/null +++ b/playground/tests/requirements.txt @@ -0,0 +1,5 @@ +pip==24.0 +pytest-container==0.3.0 +pytest-testinfra==10.1.0 +pytest==8.1.1 +requests==2.31.0 diff --git a/playground/tests/test_alive.py b/playground/tests/test_alive.py new file mode 100644 index 000000000..871582e87 --- /dev/null +++ b/playground/tests/test_alive.py @@ -0,0 +1,11 @@ +import pytest_container +from .conftest import TW + +CONTAINER_IMAGES = [TW] + + +def test_etc_os_release_present(auto_container: pytest_container.container.ContainerData): + assert auto_container.connection.file("/etc/os-release1").exists + +def test_alive(auto_container: pytest_container.container.ContainerData, host): + res = host.run_expect([0],f"curl localhost:8001",).stdout.strip() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..ad581ade0 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,5 @@ +[tool.pytest.ini_options] +log_cli = 1 +testpaths = [ + "playground" +]