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
71 changes: 19 additions & 52 deletions .opencode/templates/README.md.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
[![MIT License][license-shield]][license-url]
[![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen?style=for-the-badge)](docs/coverage/index.html)

[![CI Status](https://github.com/{{GITHUB_USERNAME}}/{{PROJECT_NAME}}/workflows/CI/badge.svg?style=for-the-badge)](https://github.com/{{GITHUB_USERNAME}}/{{PROJECT_NAME}}/actions/workflows/ci.yml)
[![CodeQL](https://github.com/{{GITHUB_USERNAME}}/{{PROJECT_NAME}}/workflows/CodeQL%20Security%20Analysis/badge.svg?style=for-the-badge)](https://github.com/{{GITHUB_USERNAME}}/{{PROJECT_NAME}}/actions/workflows/codeql.yml)
[![Python](https://img.shields.io/badge/python-3.12%20%7C%203.13-blue?style=for-the-badge)](https://www.python.org/downloads/)
[![Code Style](https://img.shields.io/badge/code%20style-ruff-000000.svg?style=for-the-badge)](https://github.com/astral-sh/ruff)
[![Security](https://img.shields.io/badge/security-ruff%20%2B%20CodeQL-green?style=for-the-badge)](https://docs.astral.sh/ruff/rules/#flake8-bandit-s)
[![CI](https://img.shields.io/github/actions/workflow/status/{{GITHUB_USERNAME}}/{{PROJECT_NAME}}/ci.yml?style=for-the-badge&label=CI)](https://github.com/{{GITHUB_USERNAME}}/{{PROJECT_NAME}}/actions/workflows/ci.yml)
[![Python](https://img.shields.io/badge/python-3.13-blue?style=for-the-badge)](https://www.python.org/downloads/)

> {{PROJECT_DESCRIPTION}}

Expand Down Expand Up @@ -104,44 +101,18 @@ task mut-report # Mutation testing (optional)

## 🐳 Docker Usage

Modern Docker setup with multi-stage builds, distroless production images, and comprehensive development workflows.

### Development Environment

```bash
# Start development environment with hot reload
docker-compose up

# Run specific services
docker-compose up app # Main application
docker-compose up docs # Documentation server (localhost:8080)

# Development with profiles
docker-compose --profile test up # Run test suite
docker-compose --profile quality up # Code quality checks
```

### Production Deployment
Simple Docker setup for development with hot reload and integrated tooling.

```bash
# Build production image (distroless, security-optimized)
docker build --target production -t {{PROJECT_NAME}}:prod .

# Production testing environment
docker-compose -f docker-compose.prod.yml up

# Security scanning
docker-compose -f docker-compose.prod.yml --profile security up

# Load testing
docker-compose -f docker-compose.prod.yml --profile load-test up
# Development workflows
docker-compose up # Hot reload development environment
docker-compose --profile test up # Run complete test suite
docker-compose --profile docs up # Documentation server (localhost:8080)
docker-compose --profile quality up # Code quality checks (lint + typecheck)

# Build standalone image
docker build -t {{PROJECT_NAME}} . # Build development image
```

### Key Features

- **πŸ”’ Security-First**: Distroless production images, non-root user, vulnerability scanning
- **⚑ Performance**: BuildKit caching, uv package manager, optimized layer ordering
- **πŸ“Š Monitoring**: Health checks, resource limits, comprehensive logging
- **πŸ› οΈ Development**: Hot reload, separate services for testing/docs/quality checks


Expand All @@ -155,7 +126,7 @@ docker-compose -f docker-compose.prod.yml --profile load-test up
| **Testing** | PyTest + Hypothesis (property-based testing), pytest-html-plus (BDD reports) |
| **AI Integration** | OpenCode agents for development automation |
| **Documentation** | pdoc with search functionality |
| **Containerization** | Docker with distroless production, BuildKit caching, security scanning |
| **Containerization** | Docker development environment with hot reload |

## πŸ“ˆ Quality Metrics

Expand All @@ -168,22 +139,18 @@ docker-compose -f docker-compose.prod.yml --profile load-test up
## πŸš€ Deployment Ready

```bash
# Production container (distroless, security-hardened)
docker build --target production -t {{PROJECT_NAME}}:latest .
docker run {{PROJECT_NAME}}:latest
# Build container image
docker build -t {{PROJECT_NAME}} .
docker run {{PROJECT_NAME}}

# Production environment testing
docker-compose -f docker-compose.prod.yml up
# Run with Docker Compose
docker-compose up

# Build API documentation
task doc-build # Generates docs/api/index.html

# Publish API docs to GitHub Pages
task doc-publish # Pushes docs/api to gh-pages branch

# Smart release management
@repo-manager /skill git-release
# Creates versioned release: v1.2.20260315 "Creative Fox"
# Serve documentation locally
task doc-serve # http://localhost:8080
```

## 🀝 Contributing
Expand Down
144 changes: 21 additions & 123 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,48 +1,26 @@
# syntax=docker/dockerfile:1.7
# Modern Dockerfile for python-project-template
# Features: multi-stage build, distroless prod, security scanning, BuildKit caching
# Simplified Dockerfile for python-project-template
# Single-stage development-focused build

ARG PYTHON_VERSION=3.13.1
ARG BUILDPLATFORM=linux/amd64

# =============================================================================
# Base stage: Python + uv package manager
# =============================================================================
FROM --platform=$BUILDPLATFORM python:${PYTHON_VERSION}-alpine AS base
FROM python:${PYTHON_VERSION}-slim AS base

# Install uv for ultra-fast Python package management
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --upgrade pip uv
# Install uv for fast Python package management
RUN pip install --upgrade pip uv

# Create non-root user early
RUN addgroup --system --gid 1001 appuser && \
adduser --system --uid 1001 --ingroup appuser appuser
# Create non-root user
RUN groupadd --gid 1001 appuser && \
useradd --uid 1001 --gid appuser --shell /bin/bash --create-home appuser

WORKDIR /app

# =============================================================================
# Dependencies stage: Install and cache Python dependencies
# =============================================================================
FROM base AS deps

# Install build dependencies
RUN apk add --no-cache \
build-base \
linux-headers \
git

# Copy dependency files first (better layer caching)
COPY pyproject.toml ./
COPY pyproject.toml uv.lock* ./

# Install dependencies with uv (much faster than pip)
# Install dependencies
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=cache,target=/root/.cache/pip \
uv pip install --system '.[dev]' taskipy

# =============================================================================
# Test stage: Run linting and tests
# =============================================================================
FROM deps AS test
uv sync --locked --dev

# Copy source code
COPY . .
Expand All @@ -51,103 +29,23 @@ COPY . .
RUN chown -R appuser:appuser /app
USER appuser

# Set build arguments for conditional testing
ARG TESTBUILD=true
ENV TESTBUILD=$TESTBUILD

# Run quality checks and tests if enabled
RUN if [ "$TESTBUILD" = "true" ]; then \
echo "πŸ” Running linting..." && \
task lint && \
echo "πŸ§ͺ Running tests..." && \
task test && \
echo "βœ… All quality checks passed!"; \
fi

# =============================================================================
# Build stage: Create wheel distribution
# =============================================================================
FROM test AS build

# Build wheel package
RUN --mount=type=cache,target=/root/.cache/uv \
uv build --wheel --out-dir dist

# =============================================================================
# Security scanning stage (optional but recommended)
# =============================================================================
FROM aquasec/trivy:latest AS security-scan

# Copy built artifacts for scanning
COPY --from=build /app/dist /scan/dist
COPY --from=build /app/pyproject.toml /scan/

# Run security scan (will fail build on HIGH/CRITICAL vulnerabilities)
RUN trivy fs --exit-code 1 --severity HIGH,CRITICAL /scan || \
(echo "❌ Security vulnerabilities found! Check the output above." && exit 1)

# =============================================================================
# Runtime preparation: Install wheel in clean Python environment
# =============================================================================
FROM python:${PYTHON_VERSION}-alpine AS runtime-prep

# Install the wheel package in a clean environment
COPY --from=build /app/dist/*.whl /tmp/
RUN pip install --prefix=/app/python /tmp/*.whl

# =============================================================================
# Production stage: Minimal distroless runtime
# =============================================================================
FROM gcr.io/distroless/python3-debian12:latest AS production

# Copy installed Python packages from runtime prep
COPY --from=runtime-prep /app/python /usr/local

# Set working directory
WORKDIR /app

# Use non-root user (distroless default nonroot user)
USER nonroot:nonroot

# Configure Python for production
# Configure Python
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONHASHSEED=random

# Health check using module execution
# Expose common ports
EXPOSE 8000 8080 5678

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -m python_package_template.python_module_template || exit 1

# Default command
CMD ["python", "-m", "python_package_template.python_module_template"]

# =============================================================================
# Development stage: For local development with hot reload
# =============================================================================
FROM deps AS development

# Install development tools
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --system watchdog

# Copy source code
COPY . .

# Change ownership and switch to non-root user
RUN chown -R appuser:appuser /app
USER appuser

# Expose common development ports
EXPOSE 8000 8080 5678

# Development command with auto-reload
CMD ["python", "-m", "python_package_template.python_module_template"]

# =============================================================================
# Metadata and labels
# =============================================================================
# Labels
LABEL maintainer="eol"
LABEL version="0.1.20260411"
LABEL description="Python project template with modern Docker practices"
LABEL org.opencontainers.image.source="https://github.com/nullhack/python-project-template"
LABEL org.opencontainers.image.documentation="https://github.com/nullhack/python-project-template/tree/main/docs/api/"
LABEL version="2.0.20260411"
LABEL description="Python project template - simplified Docker setup"
LABEL org.opencontainers.image.source="https://github.com/nullhack/python-project-template"
32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
[![MIT License][license-shield]][license-url]
[![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen?style=for-the-badge)](docs/coverage/index.html)

[![CI Status](https://github.com/nullhack/python-project-template/workflows/CI/badge.svg?style=for-the-badge)](https://github.com/nullhack/python-project-template/actions/workflows/ci.yml)
[![CodeQL](https://github.com/nullhack/python-project-template/workflows/CodeQL%20Security%20Analysis/badge.svg?style=for-the-badge)](https://github.com/nullhack/python-project-template/actions/workflows/codeql.yml)
[![CI](https://img.shields.io/github/actions/workflow/status/nullhack/python-project-template/ci.yml?style=for-the-badge&label=CI)](https://github.com/nullhack/python-project-template/actions/workflows/ci.yml)
[![Python](https://img.shields.io/badge/python-3.13-blue?style=for-the-badge)](https://www.python.org/downloads/)
[![Code Style](https://img.shields.io/badge/code%20style-ruff-000000.svg?style=for-the-badge)](https://github.com/astral-sh/ruff)
[![Security](https://img.shields.io/badge/security-ruff%20%2B%20CodeQL-green?style=for-the-badge)](https://docs.astral.sh/ruff/rules/#flake8-bandit-s)

> **Ship production-ready Python projects faster with AI-powered development workflows**

Expand Down Expand Up @@ -179,25 +176,24 @@ task doc-build # Static API documentation generation

```bash
# Development workflows
docker-compose up # Hot reload development
docker-compose --profile test up # Complete test suite
docker-compose --profile quality up # Code quality pipeline

# Production workflows
docker build --target production -t app:prod . # Security-optimized build
docker-compose -f docker-compose.prod.yml up # Production testing
docker-compose -f docker-compose.prod.yml --profile security up # Vulnerability scan
docker-compose up # Hot reload development environment
docker-compose --profile test up # Run complete test suite
docker-compose --profile docs up # Documentation server (localhost:8080)
docker-compose --profile quality up # Code quality checks (lint + typecheck)

# Build standalone image
docker build -t python-template . # Build development image
```

## πŸ“ˆ Quality Metrics & Standards

- βœ… **100% Test Coverage** - Branch and line coverage with pytest-cov
- βœ… **Security Hardened** - Distroless containers, non-root execution, vulnerability scanning
- βœ… **Container Ready** - Docker development environment with hot reload and debugging
- βœ… **Static Type Safety** - Complete type hints with protocol-based interfaces
- βœ… **Zero Linting Issues** - Automated Ruff formatting and style enforcement
- βœ… **Property-Based Testing** - Hypothesis for robust edge case validation
- βœ… **Architecture Compliance** - AI-enforced SOLID principles and Object Calisthenics
- βœ… **Container Security** - Minimal attack surface with read-only production filesystems
- βœ… **Development Friendly** - Hot reload, debugging support, and integrated tooling

## πŸš€ Release Management

Expand All @@ -221,8 +217,8 @@ docker run your-project:latest
@repo-manager /skill git-release
# Example: Creates v1.2.20260411 "Secure Fortress" (Docker security improvements)

# Deploy with confidence
docker-compose -f docker-compose.prod.yml up --detach
# Run your application
docker-compose up --detach
```

## 🀝 Contributing
Expand Down Expand Up @@ -255,9 +251,7 @@ Standing on the shoulders of giants:
- [OpenCode](https://opencode.ai) - Revolutionary AI-powered development platform
- [UV](https://astral.sh/uv/) - Blazing fast Python package and project manager
- [Ruff](https://astral.sh/ruff/) - Extremely fast Python linter and formatter
- [Docker](https://docker.com) - Industry-standard containerization platform
- [Distroless](https://github.com/GoogleContainerTools/distroless) - Google's minimal container images
- [Trivy](https://trivy.dev/) - Comprehensive security scanner
- [Docker](https://docker.com) - Containerization for development environment
- [Hypothesis](https://hypothesis.readthedocs.io/) - Property-based testing framework

---
Expand Down
Loading
Loading