mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 21:29:11 +00:00
Use Pip to setup Khoj in Docker, Github Workflows. Publish to PyPi Automatically
### Details #### Github Workflows - Make Github Workflows use `pip` instead of `conda` - Publish Khoj as Python Package Automatically - Version based on [PEP440](https://peps.python.org/pep-0440/) and [Semantic Versioning](https://semver.org/) specs - On Push to Master: Publish a pre-release (alpha) to PyPI - On Push to PR: Publish a development-release on TestPyPI - On creating a (release) tag: Publish the latest version (Major.Minor.Patch) to PyPI #### Docker - Make `Dockerfile` use `pip` to build image for Khoj. Faster, more standard flow than `conda` - Only Build Docker Image on Push to Master - Availability of pip package negates the need for docker image for PR testing - Make Docker-Compose use Docker Image published to Github Container Registry - Default Image search to disabled. [Fix loading CLIP model](https://github.com/UKPLab/sentence-transformers/issues/1659) before re-enabling
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
.git/
|
.git/
|
||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
.venv/
|
||||||
|
docs/
|
||||||
|
tests/
|
||||||
|
build/
|
||||||
|
dist/
|
||||||
|
*.egg-info/
|
||||||
|
|||||||
10
.github/workflows/build.yml
vendored
10
.github/workflows/build.yml
vendored
@@ -1,16 +1,6 @@
|
|||||||
name: build
|
name: build
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
paths:
|
|
||||||
- src/**
|
|
||||||
- config/**
|
|
||||||
- setup.py
|
|
||||||
- Dockerfile
|
|
||||||
- docker-compose.yml
|
|
||||||
- .github/workflows/build.yml
|
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
|
|||||||
74
.github/workflows/publish.yml
vendored
Normal file
74
.github/workflows/publish.yml
vendored
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
name: publish
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
paths:
|
||||||
|
- src/**
|
||||||
|
- setup.py
|
||||||
|
- .github/workflows/publish.yml
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
paths:
|
||||||
|
- src/**
|
||||||
|
- setup.py
|
||||||
|
- .github/workflows/publish.yml
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
name: Publish App to PyPI
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Python 3.10
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.10'
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install build twine
|
||||||
|
|
||||||
|
- name: Install Application
|
||||||
|
run: |
|
||||||
|
pip install --upgrade .
|
||||||
|
|
||||||
|
- name: Publish Release to PyPI
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|
||||||
|
env:
|
||||||
|
TWINE_USERNAME: __token__
|
||||||
|
TWINE_PASSWORD: ${{ secrets.PYPI_API_KEY }}
|
||||||
|
run: |
|
||||||
|
rm -rf dist
|
||||||
|
python -m build
|
||||||
|
twine check dist/*
|
||||||
|
twine upload dist/*
|
||||||
|
|
||||||
|
- name: Publish Master to PyPI
|
||||||
|
if: github.ref == 'refs/heads/master'
|
||||||
|
env:
|
||||||
|
TWINE_USERNAME: __token__
|
||||||
|
TWINE_PASSWORD: ${{ secrets.PYPI_API_KEY }}
|
||||||
|
run: |
|
||||||
|
sed -E -i "s/version=(.*)',/version=\1a$(date +%s)',/g" setup.py
|
||||||
|
rm -rf dist
|
||||||
|
python -m build
|
||||||
|
twine check dist/*
|
||||||
|
twine upload dist/*
|
||||||
|
|
||||||
|
- name: Publish PR to Test PyPI
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
env:
|
||||||
|
TWINE_USERNAME: __token__
|
||||||
|
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_KEY }}
|
||||||
|
PULL_REQUEST_NUMBER: ${{ github.event.number }}
|
||||||
|
run: |
|
||||||
|
sed -E -i "s/version=(.*)',/version=\1.dev$PULL_REQUEST_NUMBER$(date +%s)',/g" setup.py
|
||||||
|
rm -rf dist
|
||||||
|
python -m build
|
||||||
|
twine check dist/*
|
||||||
|
twine upload -r testpypi dist/*
|
||||||
57
.github/workflows/test.yml
vendored
57
.github/workflows/test.yml
vendored
@@ -22,50 +22,25 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
strategy:
|
name: Run Tests
|
||||||
matrix:
|
runs-on: ubuntu-latest
|
||||||
include:
|
|
||||||
- os: ubuntu-latest
|
|
||||||
label: linux-64
|
|
||||||
prefix: /usr/share/miniconda3/envs/test
|
|
||||||
|
|
||||||
name: ${{ matrix.label }}
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Install Environment Dependencies
|
- name: Set up Python 3.10
|
||||||
shell: bash -l {0}
|
uses: actions/setup-python@v4
|
||||||
run: sudo apt-get -y install libimage-exiftool-perl
|
|
||||||
|
|
||||||
- name: Setup Mambaforge
|
|
||||||
uses: conda-incubator/setup-miniconda@v2
|
|
||||||
with:
|
with:
|
||||||
miniforge-variant: Mambaforge
|
python-version: '3.10'
|
||||||
miniforge-version: latest
|
|
||||||
activate-environment: test
|
|
||||||
use-mamba: true
|
|
||||||
environment-file: config/environment.yml
|
|
||||||
python-version: 3.8
|
|
||||||
auto-activate-base: false
|
|
||||||
use-only-tar-bz2: true
|
|
||||||
|
|
||||||
- name: Set cache date
|
- name: Install Dependencies
|
||||||
run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
pip install pytest
|
||||||
|
|
||||||
- uses: actions/cache@v2
|
- name: Install Application
|
||||||
with:
|
run: |
|
||||||
path: ${{ matrix.prefix }}
|
pip install --upgrade .
|
||||||
key: ${{ matrix.label }}-conda-${{ hashFiles('config/environment.yml') }}-${{ env.DATE }}-${{ env.CACHE_NUMBER }}
|
|
||||||
env:
|
|
||||||
# Increase this value to reset cache if environment.yml has not changed
|
|
||||||
CACHE_NUMBER: 0
|
|
||||||
id: cache
|
|
||||||
|
|
||||||
- name: Update environment
|
- name: Test Application
|
||||||
run: mamba env update -n test -f config/environment.yml
|
run: |
|
||||||
if: steps.cache.outputs.cache-hit != 'true'
|
pytest
|
||||||
|
|
||||||
- name: Run Pytest
|
|
||||||
shell: bash -l {0}
|
|
||||||
run: python -m pytest
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,6 +1,7 @@
|
|||||||
__pycache__
|
__pycache__
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.emacs.desktop*
|
.emacs.desktop*
|
||||||
|
*.py[cod]
|
||||||
tests/data/models
|
tests/data/models
|
||||||
tests/data/embeddings
|
tests/data/embeddings
|
||||||
src/.data
|
src/.data
|
||||||
|
|||||||
33
Dockerfile
33
Dockerfile
@@ -1,29 +1,22 @@
|
|||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
FROM continuumio/miniconda3:4.12.0
|
FROM python:3.10-slim-bullseye
|
||||||
|
LABEL org.opencontainers.image.source https://github.com/debanjum/khoj
|
||||||
|
|
||||||
# Install system dependencies.
|
# Install System Dependencies
|
||||||
RUN apt-get update -y && \
|
RUN apt-get update -y && \
|
||||||
apt-get -y install libimage-exiftool-perl
|
apt-get -y install libimage-exiftool-perl
|
||||||
|
|
||||||
# Add the local code to the /app directory and set it to be the working directory.
|
# Copy Application to Container
|
||||||
# Since we mount the /app directory as a volume in docker-compose.yml, this
|
COPY . /app
|
||||||
# allows us to automatically update the code in the Docker image when it's changed.
|
|
||||||
ADD . /app
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Get the arguments from the docker-compose environment.
|
# Install Python Dependencies
|
||||||
|
RUN pip install --upgrade pip && \
|
||||||
|
pip install --upgrade .
|
||||||
|
|
||||||
|
# Run the Application
|
||||||
|
# There are more arguments required for the application to run,
|
||||||
|
# but these should be passed in through the docker-compose.yml file.
|
||||||
ARG PORT
|
ARG PORT
|
||||||
EXPOSE ${PORT}
|
EXPOSE ${PORT}
|
||||||
|
ENTRYPOINT ["khoj"]
|
||||||
# Create the conda environment.
|
|
||||||
RUN conda env create -f config/environment.yml
|
|
||||||
|
|
||||||
# Use the conda environment we created to run the application.
|
|
||||||
# To enable the conda env, we cannot simply RUN `conda activate khoj`,
|
|
||||||
# since each RUN command in a Dockerfile is a separate bash shell.
|
|
||||||
# The environment would not carry forward.
|
|
||||||
# Instead, we'll use `conda run` to run the application.
|
|
||||||
# There are more arguments required for the script to run,
|
|
||||||
# but these should be passed in through the docker-compose.yml file.
|
|
||||||
ENTRYPOINT ["conda", "run", "--no-capture-output", "--name", "khoj", \
|
|
||||||
"python3", "-m", "src.main"]
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
include Readme.md
|
include Readme.md
|
||||||
graft docs*
|
graft src/interface/*
|
||||||
|
prune src/interface/web/images*
|
||||||
|
prune docs*
|
||||||
global-exclude .DS_Store *.py[cod]
|
global-exclude .DS_Store *.py[cod]
|
||||||
@@ -20,11 +20,11 @@ content-type:
|
|||||||
compressed-jsonl: /data/embeddings/transactions.jsonl.gz
|
compressed-jsonl: /data/embeddings/transactions.jsonl.gz
|
||||||
embeddings-file: /data/embeddings/transaction_embeddings.pt
|
embeddings-file: /data/embeddings/transaction_embeddings.pt
|
||||||
|
|
||||||
image:
|
# image:
|
||||||
input-directories: ["/data/images/"]
|
# input-directories: ["/data/images/"]
|
||||||
embeddings-file: "/data/embeddings/image_embeddings.pt"
|
# embeddings-file: "/data/embeddings/image_embeddings.pt"
|
||||||
batch-size: 50
|
# batch-size: 50
|
||||||
use-xmp-metadata: true
|
# use-xmp-metadata: true
|
||||||
|
|
||||||
music:
|
music:
|
||||||
input-files: ["/data/music/music.org"]
|
input-files: ["/data/music/music.org"]
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
version: "3.9"
|
version: "3.9"
|
||||||
services:
|
services:
|
||||||
server:
|
server:
|
||||||
build:
|
image: ghcr.io/debanjum/khoj:latest
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
args:
|
|
||||||
- PORT=8000
|
|
||||||
ports:
|
ports:
|
||||||
# If changing the local port (left hand side), no other changes required.
|
# If changing the local port (left hand side), no other changes required.
|
||||||
# If changing the remote port (right hand side),
|
# If changing the remote port (right hand side),
|
||||||
@@ -29,9 +25,5 @@ services:
|
|||||||
# You can set these volumes to point to empty directories on host
|
# You can set these volumes to point to empty directories on host
|
||||||
- ./tests/data/embeddings/:/data/embeddings/
|
- ./tests/data/embeddings/:/data/embeddings/
|
||||||
- ./tests/data/models/:/data/models/
|
- ./tests/data/models/:/data/models/
|
||||||
deploy:
|
|
||||||
resources:
|
|
||||||
limits:
|
|
||||||
memory: 8g
|
|
||||||
# Use 0.0.0.0 to explicitly set the host ip for the service on the container. https://pythonspeed.com/articles/docker-connection-refused/
|
# Use 0.0.0.0 to explicitly set the host ip for the service on the container. https://pythonspeed.com/articles/docker-connection-refused/
|
||||||
command: --host="0.0.0.0" --port=8000 -c=config/khoj_sample.yml -vv
|
command: --host="0.0.0.0" --port=8000 -c=config/khoj_sample.yml -vv
|
||||||
|
|||||||
4
setup.py
4
setup.py
@@ -7,7 +7,7 @@ this_directory = Path(__file__).parent
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='khoj-assistant',
|
name='khoj-assistant',
|
||||||
version='0.1.4',
|
version='0.1.5',
|
||||||
description="A natural language search engine for your personal notes, transactions and images",
|
description="A natural language search engine for your personal notes, transactions and images",
|
||||||
long_description=(this_directory / "Readme.md").read_text(encoding="utf-8"),
|
long_description=(this_directory / "Readme.md").read_text(encoding="utf-8"),
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
@@ -16,7 +16,7 @@ setup(
|
|||||||
url='https://github.com/debanjum/khoj',
|
url='https://github.com/debanjum/khoj',
|
||||||
license="GPLv3",
|
license="GPLv3",
|
||||||
keywords="search semantic-search productivity NLP org-mode markdown beancount images",
|
keywords="search semantic-search productivity NLP org-mode markdown beancount images",
|
||||||
python_requires=">=3.5, <4",
|
python_requires=">=3.8, <4",
|
||||||
packages=find_packages(
|
packages=find_packages(
|
||||||
where=".",
|
where=".",
|
||||||
exclude=["tests*"],
|
exclude=["tests*"],
|
||||||
|
|||||||
Reference in New Issue
Block a user