Skip to content

Commit 8681e64

Browse files
setting up demo repo
0 parents  commit 8681e64

33 files changed

+2648
-0
lines changed

.env.example

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Flask Configuration
2+
FLASK_ENV=development
3+
SECRET_KEY=your-secret-key-here
4+
DEBUG=True
5+
6+
# Database
7+
DATABASE_URL=postgresql://username:password@localhost/bloghub_db
8+
9+
# Email Configuration
10+
MAIL_SERVER=smtp.gmail.com
11+
MAIL_PORT=587
12+
MAIL_USERNAME=your-email@example.com
13+
MAIL_PASSWORD=your-email-password
14+
15+
# External Services
16+
STRIPE_SECRET_KEY=sk_test_your_stripe_key
17+
STRIPE_PUBLIC_KEY=pk_test_your_stripe_key
18+
AWS_ACCESS_KEY_ID=your-aws-access-key
19+
AWS_SECRET_ACCESS_KEY=your-aws-secret-key
20+
21+
# Monitoring
22+
SENTRY_DSN=your-sentry-dsn
23+
24+
# Application Settings
25+
PORT=5000

.github/workflows/ci.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: CI Pipeline
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
python-version: [3.8, 3.9, '3.10', '3.11']
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install -r requirements.txt
29+
30+
- name: Lint with flake8
31+
run: |
32+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
33+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
34+
35+
- name: Type check with mypy
36+
run: |
37+
mypy app/ --ignore-missing-imports
38+
continue-on-error: true
39+
40+
- name: Run tests
41+
run: |
42+
pytest tests/ -v --cov=app --cov-report=xml
43+
44+
- name: Upload coverage
45+
uses: codecov/codecov-action@v3
46+
with:
47+
file: ./coverage.xml
48+
49+
security-scan:
50+
runs-on: ubuntu-latest
51+
52+
steps:
53+
- uses: actions/checkout@v3
54+
55+
- name: Run Bandit security scanner
56+
run: |
57+
pip install bandit
58+
bandit -r app/ -f json -o bandit-report.json
59+
continue-on-error: true
60+
61+
- name: Upload security report
62+
uses: actions/upload-artifact@v3
63+
with:
64+
name: security-report
65+
path: bandit-report.json
66+
67+
build:
68+
runs-on: ubuntu-latest
69+
needs: [test]
70+
71+
steps:
72+
- uses: actions/checkout@v3
73+
74+
- name: Build Docker image
75+
run: |
76+
docker build -t bloghub:${{ github.sha }} .
77+
78+
- name: Test Docker image
79+
run: |
80+
docker run -d -p 5000:5000 bloghub:${{ github.sha }}
81+
sleep 5
82+
curl -f http://localhost:5000/api/health || exit 1

.gitignore

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
build/
8+
develop-eggs/
9+
dist/
10+
downloads/
11+
eggs/
12+
.eggs/
13+
lib/
14+
lib64/
15+
parts/
16+
sdist/
17+
var/
18+
wheels/
19+
*.egg-info/
20+
.installed.cfg
21+
*.egg
22+
23+
# Virtual environments
24+
venv/
25+
env/
26+
ENV/
27+
.venv
28+
29+
# IDEs
30+
.vscode/
31+
.idea/
32+
*.swp
33+
*.swo
34+
*~
35+
.DS_Store
36+
37+
# Testing
38+
.pytest_cache/
39+
.coverage
40+
htmlcov/
41+
*.cover
42+
43+
# Database
44+
*.db
45+
*.sqlite
46+
*.sqlite3
47+
48+
# Logs
49+
*.log
50+
logs/
51+
52+
# Environment variables
53+
.env
54+
.env.local
55+
56+
# Uploads
57+
app/static/uploads/*
58+
!app/static/uploads/.gitkeep
59+
60+
# Backups
61+
backups/
62+
*.sql
63+
*.gz
64+
65+
# OS
66+
Thumbs.db

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM python:3.11-slim
2+
3+
LABEL maintainer="team@bloghub.com"
4+
LABEL description="BlogHub CMS Application"
5+
6+
WORKDIR /app
7+
8+
# Install system dependencies
9+
RUN apt-get update && apt-get install -y \
10+
postgresql-client \
11+
sqlite3 \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
# Copy requirements
15+
COPY requirements.txt .
16+
17+
# Install Python dependencies
18+
RUN pip install --no-cache-dir -r requirements.txt
19+
20+
# Copy application code
21+
COPY . .
22+
23+
# Create necessary directories
24+
RUN mkdir -p /app/app/static/uploads /app/logs
25+
26+
# Expose port
27+
EXPOSE 5000
28+
29+
# Set environment variables
30+
ENV FLASK_APP=app.py
31+
ENV PYTHONUNBUFFERED=1
32+
33+
# Run the application
34+
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "4", "app:create_app()"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 BlogHub Team
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MANIFEST.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include requirements.txt
2+
include LICENSE
3+
include README.md
4+
recursive-include app/templates *
5+
recursive-include app/static *
6+
recursive-exclude * __pycache__
7+
recursive-exclude * *.py[co]

Makefile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
.PHONY: help install test lint format run docker-build docker-up clean
2+
3+
help:
4+
@echo "BlogHub - Make commands"
5+
@echo ""
6+
@echo "install Install dependencies"
7+
@echo "test Run tests"
8+
@echo "lint Run linters"
9+
@echo "format Format code"
10+
@echo "run Run development server"
11+
@echo "docker-build Build Docker image"
12+
@echo "docker-up Start Docker containers"
13+
@echo "clean Clean up temporary files"
14+
15+
install:
16+
pip install -r requirements.txt
17+
18+
test:
19+
pytest tests/ -v
20+
21+
test-cov:
22+
pytest tests/ -v --cov=app --cov-report=html --cov-report=term
23+
24+
lint:
25+
flake8 app/ tests/
26+
mypy app/ --ignore-missing-imports
27+
28+
format:
29+
black app/ tests/
30+
31+
run:
32+
python app.py
33+
34+
docker-build:
35+
docker build -t bloghub:latest .
36+
37+
docker-up:
38+
docker-compose up -d
39+
40+
docker-down:
41+
docker-compose down
42+
43+
migrate:
44+
sqlite3 bloghub.db < migrations/001_initial_schema.sql
45+
46+
clean:
47+
find . -type d -name __pycache__ -exec rm -rf {} +
48+
find . -type f -name "*.pyc" -delete
49+
find . -type f -name "*.pyo" -delete
50+
find . -type d -name "*.egg-info" -exec rm -rf {} +
51+
rm -rf .pytest_cache
52+
rm -rf htmlcov
53+
rm -rf dist
54+
rm -rf build
55+
rm -f .coverage

app.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
BlogHub - A Simple CMS Platform
3+
Main application entry point
4+
"""
5+
import os
6+
from flask import Flask
7+
from app.routes import posts, auth, admin, api
8+
from app.utils.database import init_db
9+
from config import Config
10+
11+
def create_app(config_class=Config):
12+
"""
13+
Application factory pattern for creating Flask app instances.
14+
15+
Args:
16+
config_class: Configuration class to use
17+
18+
Returns:
19+
Flask application instance
20+
"""
21+
app = Flask(__name__)
22+
app.config.from_object(config_class)
23+
24+
# Initialize database
25+
init_db(app)
26+
27+
# Register blueprints
28+
app.register_blueprint(posts.bp)
29+
app.register_blueprint(auth.bp)
30+
app.register_blueprint(admin.bp)
31+
app.register_blueprint(api.bp)
32+
33+
# Error handlers
34+
@app.errorhandler(404)
35+
def not_found(error):
36+
return {"error": "Not found"}, 404
37+
38+
@app.errorhandler(500)
39+
def internal_error(error):
40+
return {"error": "Internal server error"}, 500
41+
42+
return app
43+
44+
if __name__ == '__main__':
45+
app = create_app()
46+
# Get port from environment or use default
47+
port = int(os.environ.get('PORT', 5000))
48+
app.run(host='0.0.0.0', port=port, debug=app.config['DEBUG'])

app/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
BlogHub application package.
3+
"""
4+
__version__ = '1.2.0'

app/models/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""
2+
Database models for BlogHub.
3+
"""
4+
from .user import User
5+
from .post import Post
6+
from .comment import Comment
7+
8+
__all__ = ['User', 'Post', 'Comment']

0 commit comments

Comments
 (0)