From 330c5a8818316f907edd3643216c476131bc75cb Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Tue, 25 Apr 2023 03:21:19 -0400 Subject: [PATCH] Use Debian Slim for base images, Fixes to CI actions (#221) * Use slim variant for Docker, CI fixes * Config must be added after installation * Use Python3.9, updates to CI * Change min required version of Python --- .github/workflows/docker-image.yml | 4 ++-- .github/workflows/pr-cleanup.yml | 16 ++++++++++----- .github/workflows/untagged-cleanup.yml | 8 +++++--- Dockerfile | 27 ++++++++++++-------------- README.md | 2 +- api/poetry.lock | 2 +- api/pyproject.toml | 2 +- redis.conf => config/redis.conf | 2 +- 8 files changed, 34 insertions(+), 29 deletions(-) rename redis.conf => config/redis.conf (96%) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 99b5061..a0f4b8c 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -50,7 +50,7 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Login to GitHub Container Registry - if: ${{ contains(fromJSON('["nsarrazin","gaby"]'), github.actor) }} + if: ${{ contains(fromJSON('["nsarrazin","gaby"]'), github.event.pull_request.user.login) }} uses: docker/login-action@v2 with: registry: ghcr.io @@ -61,7 +61,7 @@ jobs: uses: docker/build-push-action@v4 with: context: . - push: ${{ contains(fromJSON('["nsarrazin","gaby"]'), github.actor) }} + push: ${{ contains(fromJSON('["nsarrazin","gaby"]'), github.event.pull_request.user.login) }} target: release cache-from: type=gha cache-to: type=gha,mode=max diff --git a/.github/workflows/pr-cleanup.yml b/.github/workflows/pr-cleanup.yml index 48291f0..f7dcd5a 100644 --- a/.github/workflows/pr-cleanup.yml +++ b/.github/workflows/pr-cleanup.yml @@ -6,13 +6,19 @@ on: jobs: purge-pr-tagged-image: - name: Delete pr tagged image from ghcr.io - if: ${{ contains(fromJSON('["nsarrazin","gaby"]'), github.actor) == true }} + name: Delete container images from PR's + if: ${{ contains(fromJSON('["nsarrazin","gaby"]'), github.event.pull_request.user.login) }} continue-on-error: true runs-on: ubuntu-latest steps: - - uses: chipkent/action-cleanup-package@v1.0.3 + - uses: castlabs/get-package-version-id-action@v2.1 + id: version + with: + version: "pr-${{ github.event.pull_request.number }}" + + - uses: actions/delete-package-versions@v4 + if: ${{ steps.version.outputs.ids != '' }} with: package-name: ${{ github.event.repository.name }} - tag: pr-${{ github.event.pull_request.number }} - github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + min-versions-to-keep: 0 + package-version-ids: "${{ steps.version.outputs.ids }}" \ No newline at end of file diff --git a/.github/workflows/untagged-cleanup.yml b/.github/workflows/untagged-cleanup.yml index e87146a..eb15de3 100644 --- a/.github/workflows/untagged-cleanup.yml +++ b/.github/workflows/untagged-cleanup.yml @@ -16,7 +16,9 @@ jobs: name: Delete untagged images from ghcr.io runs-on: ubuntu-latest steps: - - uses: CerebralXor/action-cleanup-package@v1.0.1 - with: + - uses: actions/delete-package-versions@v4 + with: package-name: ${{ github.event.repository.name }} - github-token: ${{ secrets.GH_ACCESS_TOKEN }} \ No newline at end of file + package-type: container + min-versions-to-keep: 10 + delete-only-untagged-versions: true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b4fa67d..27c2bfd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,28 @@ # --------------------------------------- # Base image for node -FROM node:19 as node_base +FROM node:19-slim as node_base WORKDIR /usr/src/app # --------------------------------------- # Base image for runtime -FROM python:3.11 as base +FROM python:3.9-slim as base ENV TZ=Etc/UTC WORKDIR /usr/src/app # Install Redis -RUN apt-get update && apt-get install -y curl wget gnupg python3-pip cmake lsb-release +RUN apt-get update \ + && apt-get install -y curl wget gnupg cmake lsb-release \ + && curl -fsSL https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg \ + && echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/redis.list \ + && apt-get update \ + && apt-get install -y redis \ + && mkdir -p /etc/redis /var/redis \ + && pip install --upgrade pip -RUN curl -fsSL https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg && \ - echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/redis.list - -RUN apt-get update && \ - apt-get install -y redis - -RUN mkdir -p /etc/redis && mkdir -p /var/redis - -COPY ./redis.conf /etc/redis/redis.conf - -# clone the python bindings for llama.cpp -RUN pip install --upgrade pip +# Add redis config +COPY ./config/redis.conf /etc/redis/redis.conf # --------------------------------------- # Dev environment diff --git a/README.md b/README.md index 1503b10..b1532d6 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A chat interface based on [llama.cpp](https://github.com/ggerganov/llama.cpp) for running Alpaca models. Entirely self-hosted, no API keys needed. Fits on 4GB of RAM and runs on the CPU. - **SvelteKit** frontend -- **MongoDB** for storing chat history & parameters +- **Redis** for storing chat history & parameters - **FastAPI + beanie** for the API, wrapping calls to [llama.cpp](https://github.com/ggerganov/llama.cpp) [demo.webm](https://user-images.githubusercontent.com/25119303/226897188-914a6662-8c26-472c-96bd-f51fc020abf6.webm) diff --git a/api/poetry.lock b/api/poetry.lock index 2b6cf19..69eed33 100644 --- a/api/poetry.lock +++ b/api/poetry.lock @@ -426,7 +426,7 @@ files = [ [package.extras] docs = ["furo (>=2023.3.27)", "sphinx (>=6.1.3)", "sphinx-autodoc-typehints (>=1.23,!=1.23.4)"] -testing = ["covdefaults (>=2.3)", "coverage (>=7.2.3)", "diff-cover (>=7.5)", "pytest (>=7.3.1)", "pytest-cov (>=4)", "pytest-mock (>=3.10)", "pytest-timeout (>=2.1)"] +testing = ["covdefaults (>=2.3)", "coverage (>=7.2.3)", "diff-cover (>=7.5)", "pytest (>=7.3.1)", "pytest-cov (>=4)", "pytest-mock (>=3.9)", "pytest-timeout (>=2.1)"] [[package]] name = "frozenlist" diff --git a/api/pyproject.toml b/api/pyproject.toml index cef9649..c031475 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -21,7 +21,7 @@ requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" [tool.poetry.dependencies] -python=">=3.10,<4.0" +python=">=3.9,<4.0" asyncio = "^3.4.3" packaging = "^23.1" pydantic = "^1.10.7" diff --git a/redis.conf b/config/redis.conf similarity index 96% rename from redis.conf rename to config/redis.conf index 889a663..f6527d3 100644 --- a/redis.conf +++ b/config/redis.conf @@ -1,2 +1,2 @@ -appendonly yes +appendonly yes dir /data/db/ \ No newline at end of file