added docker for production

This commit is contained in:
Andreas Jönsson 2025-11-15 19:19:42 +01:00
parent 6d4bf67d5a
commit f6b3020350
5 changed files with 64 additions and 0 deletions

7
.gitignore vendored
View File

@ -1,2 +1,9 @@
# Python
__pycache__/ __pycache__/
*.py[cod]
# Database
instance/*.db instance/*.db
# Docker
.env

26
Dockerfile Normal file
View File

@ -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"]

View File

@ -23,6 +23,7 @@ flask init-db
## Usage ## Usage
### Local Development
```bash ```bash
# Start development server # Start development server
flask run --host=0.0.0.0 --port=5001 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 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` 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 ## Features
- User registration with password confirmation - User registration with password confirmation
- Secure password hashing - Secure password hashing

13
docker-compose.yml Normal file
View File

@ -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

5
requirements.txt Normal file
View File

@ -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