diff --git a/.gitignore b/.gitignore index af6e8f4..36c9aa7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,9 @@ +# Python __pycache__/ +*.py[cod] + +# Database instance/*.db + +# Docker +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0d90c0e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# Use official Python runtime as base image +FROM python:3.10-alpine + +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 +ENV FLASK_ENV production + +# Create and set working directory +WORKDIR /app + +# Install system dependencies +RUN apk add --no-cache gcc musl-dev linux-headers git + +# Install Python dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy application code +COPY . . + +# Expose the application port +EXPOSE 5001 + +# Run application with Gunicorn +CMD ["gunicorn", "--bind", "0.0.0.0:5001", "--workers", "4", "app:app"] diff --git a/README.md b/README.md index 5dacf16..04b350e 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ flask init-db ## Usage +### Local Development ```bash # Start development server flask run --host=0.0.0.0 --port=5001 @@ -31,8 +32,20 @@ flask run --host=0.0.0.0 --port=5001 pkill -f "flask run" && flask run --host=0.0.0.0 --port=5001 ``` +### Docker Deployment +```bash +# Build and start container +docker-compose up --build + +# For production (detached mode) +docker-compose up --build -d +``` + The application will be available at `http://localhost:5001` +### Persisting Data +The database will be preserved between container restarts through the `./instance` volume mount. + ## Features - User registration with password confirmation - Secure password hashing diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..51944bf --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3.8' + +services: + web: + build: . + ports: + - "5001:5001" + environment: + - FLASK_ENV=production + - FLASK_SECRET_KEY=${FLASK_SECRET_KEY:-your-secret-key-here} + - SQLALCHEMY_DATABASE_URI=sqlite:////app/instance/users.db + volumes: + - ./instance:/app/instance diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e5e192a --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +flask==3.0.0 +flask-sqlalchemy==3.1.1 +flask-login==0.6.3 +werkzeug==3.0.0 +gunicorn==21.2.0