Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Git
.git/
.gitignore

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
*.egg-info/
dist/
build/
.pytest_cache/
.coverage
htmlcov/
.tox/
.mypy_cache/
.ruff_cache/

# Virtual environments
venv/
env/
ENV/
.venv/

# IDEs
.vscode/
.idea/
*.swp
*.swo
*~
.DS_Store

# Project specific
tests/
docs/
examples/
scripts/
*.md
!README.md
pytest.ini
.github/
.gitlab-ci.yml
coordination/
memory/
output/
rdf_output/
metadata-tmp/
rdf-tmp/
tmp/
tmp-sample-data/
sample_data/
test-cli/
task_log.jsonl
task_queue.jsonl

# Docker
docker-compose*.yml
Dockerfile*
!Dockerfile
.dockerignore

# Buildpack
project.toml
pack.toml

# Keep only essential files for runtime
86 changes: 86 additions & 0 deletions .github/workflows/build-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Build Artifacts

on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]

jobs:
build-docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

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

- name: Build Docker image
run: |
docker build -t knowledgebase-processor:latest .
docker save knowledgebase-processor:latest | gzip > knowledgebase-processor-docker.tar.gz

- name: Upload Docker artifact
uses: actions/upload-artifact@v4
with:
name: docker-image
path: knowledgebase-processor-docker.tar.gz

build-wheel:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install Poetry
uses: snok/install-poetry@v1

- name: Build wheel
run: |
poetry build

- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: python-wheel
path: dist/

# build-executable:
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# os: [ubuntu-latest, windows-latest, macos-latest]

# steps:
# - uses: actions/checkout@v4

# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: '3.12'

# - name: Install Poetry
# uses: snok/install-poetry@v1

# - name: Install dependencies
# run: |
# poetry install --only=main

# - name: Install PyInstaller
# run: |
# poetry add --group dev pyinstaller

# - name: Build executable
# run: |
# poetry run pyinstaller --onefile --name kb src/knowledgebase_processor/cli_v2/main.py

# - name: Upload executable
# uses: actions/upload-artifact@v4
# with:
# name: executable-${{ matrix.os }}
# path: dist/kb*
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Multi-stage build to handle Python dependencies with C extensions
FROM python:3.12-slim as builder

# Install build dependencies
RUN apt-get update && apt-get install -y \
build-essential \
gcc \
g++ \
&& rm -rf /var/lib/apt/lists/*

# Install poetry
RUN pip install poetry

# Copy dependency files
COPY pyproject.toml poetry.lock ./

# Configure poetry to not create virtual environment
RUN poetry config virtualenvs.create false

# Install dependencies
RUN poetry install --only=main --no-root

# Production stage
FROM python:3.12-slim as runtime

# Create non-root user
RUN useradd --create-home --shell /bin/bash kbp

# Copy installed packages from builder
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin

# Copy application code
COPY src/ /app/src/
COPY pyproject.toml README.md /app/

WORKDIR /app

# Install the package
RUN pip install -e .

USER kbp

# Default command
CMD ["kb", "--help"]
75 changes: 75 additions & 0 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Alpine-based Dockerfile for knowledgebase-processor
# Smaller image size but requires more careful dependency management

# Build stage
FROM python:3.12-alpine as builder

# Install build dependencies for Alpine
# Note: Alpine uses musl libc which can cause compatibility issues
RUN apk add --no-cache \
gcc \
g++ \
musl-dev \
linux-headers \
python3-dev \
openblas-dev \
gfortran \
build-base \
cmake \
# Required for some Python packages
libffi-dev \
openssl-dev

# Install poetry
RUN pip install --no-cache-dir poetry==1.8.2

WORKDIR /app

# Copy dependency files
COPY pyproject.toml poetry.lock ./

# Configure poetry
RUN poetry config virtualenvs.create false

# Install dependencies - longer build time due to compilation
RUN poetry install --no-interaction --no-ansi --no-root --only main

# Copy and install application
COPY src/ ./src/
COPY README.md ./
RUN poetry install --no-interaction --no-ansi --only-root

# Runtime stage
FROM python:3.12-alpine

# Install runtime dependencies only
RUN apk add --no-cache \
openblas \
libgfortran \
libstdc++ \
# For health checks
curl

# Create non-root user
RUN adduser -D -u 1000 kbuser

# Copy from builder
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin

WORKDIR /app
COPY --from=builder /app/src ./src
COPY pyproject.toml README.md ./

# Create data directories
RUN mkdir -p /app/data /app/output /app/metadata && \
chown -R kbuser:kbuser /app

USER kbuser

ENV PYTHONUNBUFFERED=1

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD kb --version || exit 1

CMD ["kb", "--help"]
Loading