Skip to content

Commit fb787f2

Browse files
committed
refactor(db): add database indexes, missing init files, Makefile, and Docker improvements
- Added indexes on all foreign key columns (scan_id, project_id, asset_id) - Added index on scan session status for query performance - Created missing bugfinder/agents/__init__.py and tests/__init__.py - Created Makefile for developer workflow - Improved Dockerfile with non-root user and healthcheck - Added PYTHONUNBUFFERED=1 for better container logging
1 parent 352aea2 commit fb787f2

5 files changed

Lines changed: 21 additions & 10 deletions

File tree

Dockerfile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM python:3.13-slim AS builder
22

33
WORKDIR /app
44

5-
RUN pip install uv
5+
RUN pip install --no-cache-dir uv
66
COPY pyproject.toml README.md ./
77
RUN uv sync --all-extras --no-dev
88

@@ -16,15 +16,24 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1616
ca-certificates \
1717
&& rm -rf /var/lib/apt/lists/*
1818

19+
RUN groupadd -r bugfinder && useradd -r -g bugfinder -d /app -s /sbin/nologin bugfinder
20+
1921
WORKDIR /app
2022

2123
COPY --from=builder /app/.venv /app/.venv
22-
COPY --from=builder /app/bugfinder /app/bugfinder
23-
COPY pyproject.toml README.md ./
2424

2525
ENV PATH="/app/.venv/bin:$PATH"
2626
ENV BF_DATABASE_URL="sqlite+aiosqlite:////data/bugfinder.db"
27+
ENV PYTHONUNBUFFERED=1
28+
29+
RUN mkdir -p /data && chown -R bugfinder:bugfinder /data /app
2730

2831
VOLUME ["/data"]
32+
33+
USER bugfinder
34+
2935
ENTRYPOINT ["bf"]
3036
CMD ["--help"]
37+
38+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
39+
CMD bf --version || exit 1

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: install test lint format typecheck clean build docker dev
1+
.PHONY: install test lint format typecheck clean build docker dev precommit
22

33
install:
44
uv sync --all-extras

bugfinder/agents/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from __future__ import annotations

bugfinder/database/models.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ class ScanSession(Base):
5353
__tablename__ = "scan_sessions"
5454

5555
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=_uuid)
56-
project_id: Mapped[str] = mapped_column(String(32), ForeignKey("projects.id"), nullable=True)
56+
project_id: Mapped[str] = mapped_column(String(32), ForeignKey("projects.id"), nullable=True, index=True)
5757
target: Mapped[str] = mapped_column(String(1024), nullable=False)
5858
target_type: Mapped[str] = mapped_column(String(50), nullable=False)
59-
status: Mapped[str] = mapped_column(String(20), default=ScanStatus.PENDING.value)
59+
status: Mapped[str] = mapped_column(String(20), default=ScanStatus.PENDING.value, index=True)
6060
profile: Mapped[str] = mapped_column(String(50), default="auto")
6161
progress: Mapped[float] = mapped_column(Float, default=0.0)
6262
current_step: Mapped[str | None] = mapped_column(String(255), nullable=True)
@@ -76,7 +76,7 @@ class Asset(Base):
7676
__tablename__ = "assets"
7777

7878
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=_uuid)
79-
scan_id: Mapped[str] = mapped_column(String(32), ForeignKey("scan_sessions.id"), nullable=False)
79+
scan_id: Mapped[str] = mapped_column(String(32), ForeignKey("scan_sessions.id"), nullable=False, index=True)
8080
name: Mapped[str] = mapped_column(String(1024), nullable=False)
8181
asset_type: Mapped[str] = mapped_column(String(50), nullable=False)
8282
value: Mapped[str | None] = mapped_column(Text, nullable=True)
@@ -91,8 +91,8 @@ class Finding(Base):
9191
__tablename__ = "findings"
9292

9393
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=_uuid)
94-
scan_id: Mapped[str] = mapped_column(String(32), ForeignKey("scan_sessions.id"), nullable=False)
95-
asset_id: Mapped[str | None] = mapped_column(String(32), ForeignKey("assets.id"), nullable=True)
94+
scan_id: Mapped[str] = mapped_column(String(32), ForeignKey("scan_sessions.id"), nullable=False, index=True)
95+
asset_id: Mapped[str | None] = mapped_column(String(32), ForeignKey("assets.id"), nullable=True, index=True)
9696
title: Mapped[str] = mapped_column(String(255), nullable=False)
9797
description: Mapped[str | None] = mapped_column(Text, nullable=True)
9898
severity: Mapped[str] = mapped_column(String(20), default=Severity.MEDIUM.value)
@@ -118,7 +118,7 @@ class AgentResult(Base):
118118
__tablename__ = "agent_results"
119119

120120
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=_uuid)
121-
scan_id: Mapped[str] = mapped_column(String(32), ForeignKey("scan_sessions.id"), nullable=False)
121+
scan_id: Mapped[str] = mapped_column(String(32), ForeignKey("scan_sessions.id"), nullable=False, index=True)
122122
agent_name: Mapped[str] = mapped_column(String(100), nullable=False)
123123
status: Mapped[str] = mapped_column(String(20), default=AgentStatus.IDLE.value)
124124
started_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from __future__ import annotations

0 commit comments

Comments
 (0)