Skip to content

Commit

Permalink
dockerize (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmeier authored Jan 22, 2024
1 parent 008c458 commit 6dd32b7
Show file tree
Hide file tree
Showing 6 changed files with 578 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ragna/_version.py

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
108 changes: 108 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: docker

on:
pull_request:
paths:
- ".github/workflows/docker.yml"
- ".dockerignore"
- "Dockerfile"
- "environment-dev.yml"
- "pyproject.toml"
- "ragna-docker.toml"
- "requirements-docker.lock"
push:
branches:
- release/*
workflow_dispatch:

concurrency:
group: ${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
REGISTRY: quay.io
PROJECT: quansight/ragna

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup environment
uses: ./.github/actions/setup-env
with:
optional-dependencies: "false"

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set up Docker Build Cache
id: cache
run: |
CACHE_DIR="${HOME}/.cache/docker"
mkdir --parents "${CACHE_DIR}"
echo "cache-dir=${CACHE_DIR}" | tee --append $GITHUB_OUTPUT
- name: Restore docker cache
uses: actions/cache@v3
with:
path: ${{ steps.cache.outputs.cache-dir }}
key: docker-${{ hashFiles('Dockerfile','requirements-docker.lock') }}
restore-keys: docker-

- name: Setup metadata
id: metadata
run: |
IMAGE_NAME="${{ env.REGISTRY }}/${{ env.PROJECT }}"
echo "image-name=${IMAGE_NAME}" | tee --append $GITHUB_OUTPUT
VERSION=$(python -m setuptools_scm)
echo "version=${VERSION}" | tee --append $GITHUB_OUTPUT
TAG=$(echo "${VERSION}" | sed 's/+/-/g')
echo "tag=${TAG}" | tee --append $GITHUB_OUTPUT
TAGGED_IMAGE_NAME="${IMAGE_NAME}:${TAG}"
echo "tagged-image-name=${TAGGED_IMAGE_NAME}" | tee --append $GITHUB_OUTPUT
- name: Login to Quay.io
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }}

- name: Build and push on workflow dispatch
id: build
uses: docker/build-push-action@v5
with:
cache-from: type=local,src=${{ steps.cache.outputs.cache-dir }}
cache-to: type=local,dest=${{ steps.cache.outputs.cache-dir }}
tags: ${{ steps.metadata.outputs.tagged-image-name }}
build-args: |
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_RAGNA=${{ steps.metadata.outputs.version }}
# Unfortunately, there currently seems to be no way to build a multiplatform
# image and access a single one for the host platform afterwards. Thus, we
# only build a multiplatform image when we also want to push to the registry.
# https://github.com/docker/buildx/issues/166
# https://github.com/moby/buildkit/issues/1555
# prettier-ignore
platforms:
${{ github.event_name == 'workflow_dispatch' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
load: ${{ github.event_name != 'workflow_dispatch' }}
push: ${{ github.event_name == 'workflow_dispatch' }}

- name: Smoke test
run: docker run ${{ steps.metadata.outputs.tagged-image-name }} --version
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM python:3.11

WORKDIR /opt/ragna

COPY requirements-docker.lock .
RUN pip install --progress-bar=off --no-deps --no-cache --requirement requirements-docker.lock

# Pre-download the default embedding model
RUN python -c "from chromadb.utils.embedding_functions import ONNXMiniLM_L6_V2; ONNXMiniLM_L6_V2()._download_model_if_not_exists()"

COPY ragna ./ragna
COPY pyproject.toml .
# Since we don't copy the .git folder, but still use setuptools-scm as build-backend
# we need to make two manual changes:
# 1. With setuptools-scm all files that are tracked by git are automatically included in
# the built wheel. Since we have corresponding .dockerignore file to our .gitignore,
# the ragna folder only includes files that we are tracking. Thus, we just include
# everything manually.
# 2. We need to pass the version expliclitly as
# --build-arg SETUPTOOLS_SCM_PRETEND_VERSION_FOR_RAGNA=...,
# since setuptools-scm cannot infer the version
RUN echo '[tool.setuptools.package-data]\n"*" = ["*"]' >> pyproject.toml
ARG SETUPTOOLS_SCM_PRETEND_VERSION_FOR_RAGNA
RUN pip install --progress-bar=off --no-deps .

WORKDIR /var/ragna
COPY ragna-docker.toml ragna.toml

ENTRYPOINT ["ragna"]
CMD ["ui"]
2 changes: 2 additions & 0 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dependencies:
- pre-commit
- types-aiofiles
- sqlalchemy-stubs
- setuptools-scm
- pip-tools
# documentation
- mkdocs
- mkdocs-material
Expand Down
22 changes: 22 additions & 0 deletions ragna-docker.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local_cache_root = "/var/ragna"
document = "ragna.core.LocalDocument"
authentication = "ragna.deploy.RagnaDemoAuthentication"

[components]
source_storages = [
"ragna.source_storages.Chroma",
"ragna.source_storages.RagnaDemoSourceStorage",
"ragna.source_storages.LanceDB"
]
assistants = [
"ragna.assistants.RagnaDemoAssistant"
]

[api]
url = "http://0.0.0.0:31476"
origins = ["http://localhost:31477"]
database_url = "sqlite:////var/ragna/ragna.db"

[ui]
url = "http://0.0.0.0:31477"
origins = ["http://localhost:31477"]
Loading

0 comments on commit 6dd32b7

Please sign in to comment.