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
53 changes: 53 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Git
.git
.gitignore

# Python
__pycache__
*.py[cod]
*$py.class
.pytest_cache
*.egg-info
dist
build
.eggs

# Virtual environments
.venv
venv
ENV

# IDE
.idea
.vscode
*.swp
*.swo

# Testing
htmlcov
.coverage
.tox
.nox

# Logs
*.log
logs/

# OS
.DS_Store
Thumbs.db

# Documentation (not needed in container)
*.md
!README.md

# Development files
.env
*.bak
*.backup

# Test files (optional - include if you want to run tests in container)
test_*.py

# Windows batch files (not needed in container)
*.bat
29 changes: 29 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Library Management System Configuration
# Copy this file to .env and modify as needed

# Server Configuration
HOST=127.0.0.1
PORT=8000
DEBUG=false

# CORS Configuration
# Comma-separated list of allowed origins
# For production, specify your actual domain(s)
CORS_ORIGINS=http://localhost:8000,http://127.0.0.1:8000
CORS_ALLOW_CREDENTIALS=true
CORS_ALLOW_METHODS=GET,POST,PUT,DELETE,OPTIONS
CORS_ALLOW_HEADERS=Content-Type,Authorization

# Data Configuration
LIBRARY_FILE=library.json

# Logging Configuration
# Options: DEBUG, INFO, WARNING, ERROR, CRITICAL
LOG_LEVEL=INFO
# Leave empty for stdout only, or specify a file path
LOG_FILE=
LOG_FORMAT=%(asctime)s - %(name)s - %(levelname)s - %(message)s

# OpenLibrary API Configuration
OPENLIBRARY_BASE_URL=https://openlibrary.org
OPENLIBRARY_TIMEOUT=10
83 changes: 83 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Continuous Integration workflow for Library Management System
# Runs tests and linting on every push and pull request

name: CI

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

jobs:
test:
name: Test (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"

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

- name: Lint with ruff
run: |
ruff check . --output-format=github

- name: Run tests
run: |
pytest -v --tb=short

- name: Run tests with coverage
if: matrix.python-version == '3.11'
run: |
pytest --cov=. --cov-report=xml --cov-report=term-missing

- name: Upload coverage to Codecov
if: matrix.python-version == '3.11'
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
fail_ci_if_error: false

docker:
name: Docker Build
runs-on: ubuntu-latest
needs: test

steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: library-management:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Test Docker image
run: |
docker run -d --name test-container -p 8000:8000 library-management:latest
sleep 5
curl -f http://localhost:8000/health || exit 1
docker stop test-container
102 changes: 102 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Release workflow for Library Management System
# Creates releases and publishes Docker images when tags are pushed

name: Release

on:
push:
tags:
- "v*"

jobs:
release:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v4

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

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

- name: Run tests
run: pytest -v

- name: Extract version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
body: |
## Library Management System v${{ steps.get_version.outputs.VERSION }}

### Installation

**Using pip:**
```bash
pip install -r requirements.txt
```

**Using Docker:**
```bash
docker pull ghcr.io/${{ github.repository }}:${{ steps.get_version.outputs.VERSION }}
docker run -p 8000:8000 ghcr.io/${{ github.repository }}:${{ steps.get_version.outputs.VERSION }}
```

See [CHANGELOG.md](CHANGELOG.md) for detailed changes.

docker-publish:
name: Publish Docker Image
runs-on: ubuntu-latest
needs: release
permissions:
contents: read
packages: write

steps:
- 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.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
91 changes: 91 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# IDE settings
.idea/
.vscode/
*.swp
*.swo
*~
.project
.pydevproject
.settings/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# Logs
*.log
logs/

# Local development
.DS_Store
Thumbs.db

# Backup files
*.bak
*.backup
library_backup*.json
Loading