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
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ docker-compose.yml
# Documentation
*.md

# Not needed at runtime (make test-docker bind-mounts tests/ + pytest.ini)
tests/
docs/
deploy/
scripts/
.github/

# Testing
.pytest_cache/
.coverage
Expand Down
66 changes: 31 additions & 35 deletions .github/workflows/ci-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,25 @@ name: CI + Docker Build & Push
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
paths-ignore:
- 'docs/**'
- 'mkdocs.yml'
- '**/*.md'
workflow_dispatch:

permissions:
contents: read
packages: write

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y libzbar0

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest

- name: Run tests
run: pytest -v
uses: ./.github/workflows/test.yml
permissions:
contents: read

docker-build:
needs: test
Expand All @@ -47,21 +33,31 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker image
run: |
docker build \
-t ghcr.io/owasp/pwnzzai:latest \
-t ghcr.io/owasp/pwnzzai:${{ github.sha }} \
.
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/owasp/pwnzzai
tags: |
type=raw,value=latest
type=raw,value=${{ github.sha }}

- name: Push Docker image
run: |
docker push ghcr.io/owasp/pwnzzai:latest
docker push ghcr.io/owasp/pwnzzai:${{ github.sha }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
18 changes: 15 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@ name: Lint

on:
pull_request:
paths-ignore:
- 'docs/**'
- 'mkdocs.yml'
- '**/*.md'
push:
branches: [ main ]
paths-ignore:
- 'docs/**'
- 'mkdocs.yml'
- '**/*.md'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest

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

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'

- run: pip install ruff

- run: ruff check .
- run: ruff check .
27 changes: 19 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
name: Run Tests

on:
push:
branches: [main]
on:
pull_request:
branches: [main]
paths-ignore:
- 'docs/**'
- 'mkdocs.yml'
- '**/*.md'
workflow_dispatch:
workflow_call:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
test:
Expand All @@ -17,8 +27,12 @@ jobs:

- name: Setup Python
uses: actions/setup-python@v5
with:
with:
python-version: '3.12'
cache: pip
cache-dependency-path: |
requirements.txt
requirements-test.txt

- name: Install System Dependencies
run: |
Expand All @@ -30,9 +44,6 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-test.txt


- name: Run Tests
run: pytest -v


run: pytest -v
20 changes: 12 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ FROM python:3.11-slim

WORKDIR /app

RUN apt-get update && apt-get install -y build-essential \
# libzbar0: runtime for pyzbar (QR labs). Wheels cover numpy/sklearn/Pillow/faiss; no compiler.
RUN apt-get update && apt-get install -y --no-install-recommends \
libzbar0 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY requirements.txt .
RUN python -m pip install --upgrade pip && \
pip install \
--retries 10 \
--timeout 600 \
-r requirements.txt
# CPU torch first so sentence-transformers does not pull the CUDA wheel (~GB of nvidia-*).
# Do not pin torch in requirements.txt: host/macOS venvs stay unchanged.
RUN python -m pip install --upgrade --no-cache-dir pip && \
pip install --no-cache-dir --retries 10 --timeout 600 \
torch --index-url https://download.pytorch.org/whl/cpu && \
pip install --no-cache-dir --retries 10 --timeout 600 \
-r requirements.txt

COPY . .

Expand All @@ -23,7 +26,8 @@ EXPOSE 8080

ENV FLASK_APP=main.py
ENV PYTHONUNBUFFERED=1
# Compose DNS to the separate ollama service (not installed in this image).
ENV OLLAMA_HOST=http://ollama:11434

# Start Ollama in background, wait for it, then start Flask
CMD ollama serve > /tmp/ollama.log 2>&1 & sleep 5 && flask run --host=0.0.0.0 --port=8080 --no-reload
# Flask only. Ollama runs as compose service ollama/ollama:latest.
CMD ["flask", "run", "--host=0.0.0.0", "--port=8080", "--no-reload"]
7 changes: 0 additions & 7 deletions Dockerfile.ollama

This file was deleted.

16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,21 @@ test-docker-build: ## Build $(TEST_IMAGE) from Dockerfile for test runs
docker build -t "$(TEST_IMAGE)" .

.PHONY: test-docker
test-docker: test-docker-build ## Run pytest -v inside $(TEST_IMAGE) (installs requirements-test in container)
docker run --rm -t "$(TEST_IMAGE)" \
test-docker: test-docker-build ## Run pytest -v inside $(TEST_IMAGE) (bind-mounts tests; image excludes tests/)
docker run --rm -t \
-v "$(CURDIR)/tests:/app/tests:ro" \
-v "$(CURDIR)/pytest.ini:/app/pytest.ini:ro" \
-v "$(CURDIR)/requirements-test.txt:/app/requirements-test.txt:ro" \
"$(TEST_IMAGE)" \
sh -lc 'python -m pip install -q -r requirements-test.txt && pytest -v'

.PHONY: test-docker-cov
test-docker-cov: test-docker-build ## pytest with coverage inside container
docker run --rm -t "$(TEST_IMAGE)" \
test-docker-cov: test-docker-build ## pytest with coverage inside container (bind-mounts tests)
docker run --rm -t \
-v "$(CURDIR)/tests:/app/tests:ro" \
-v "$(CURDIR)/pytest.ini:/app/pytest.ini:ro" \
-v "$(CURDIR)/requirements-test.txt:/app/requirements-test.txt:ro" \
"$(TEST_IMAGE)" \
sh -lc 'python -m pip install -q -r requirements-test.txt && pytest --cov=application --cov-report=term-missing -v'

# =============================================================================
Expand Down
14 changes: 8 additions & 6 deletions deploy/Dockerfile.pwnzzai-workshop
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ FROM python:3.11-slim

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends build-essential \
# libzbar0: runtime for pyzbar (QR labs). Wheels cover numpy/sklearn/Pillow/faiss; no compiler.
RUN apt-get update && apt-get install -y --no-install-recommends \
libzbar0 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

COPY requirements.txt .
RUN python -m pip install --upgrade pip && \
pip install \
--retries 10 \
--timeout 600 \
-r requirements.txt
# CPU torch first so sentence-transformers does not pull the CUDA wheel (~GB of nvidia-*).
RUN python -m pip install --upgrade --no-cache-dir pip && \
pip install --no-cache-dir --retries 10 --timeout 600 \
torch --index-url https://download.pytorch.org/whl/cpu && \
pip install --no-cache-dir --retries 10 --timeout 600 \
-r requirements.txt

COPY . .

Expand Down