updated readme after major changes in code
This commit is contained in:
parent
65ed8d0659
commit
e4a8f7f6c7
154
README.md
154
README.md
@ -1,90 +1,106 @@
|
||||
# Flask Base Application
|
||||
# Flask Base Project
|
||||
|
||||
A simple Flask web application with user authentication features.
|
||||
A starter template for Flask web applications with Docker support, user authentication, and deployment configurations.
|
||||
|
||||
## Features
|
||||
|
||||
- User registration, login, and dashboard functionality
|
||||
- Docker and Docker Compose for containerized environments
|
||||
- SQLite database (with optional PostgreSQL support)
|
||||
- Environment configuration via .env file
|
||||
- Jinja2 templating with base HTML structure
|
||||
- Git version control integration
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Python 3.9+
|
||||
- Docker 20.10+
|
||||
- Docker Compose 2.4+
|
||||
|
||||
## Installation
|
||||
|
||||
1. Clone the repository:
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone https://git.leoan.se/andreas/flask-base.git
|
||||
git clone ssh://git@git.leoan.se:30009/andreas/flask-base.git
|
||||
cd flask-base
|
||||
|
||||
# Create and activate virtual environment (recommended)
|
||||
python -m venv venv
|
||||
source venv/bin/activate # On Linux/MacOS
|
||||
# venv\Scripts\activate # On Windows
|
||||
|
||||
# Install dependencies
|
||||
pip install flask flask-sqlalchemy flask-login werkzeug
|
||||
|
||||
# Initialize database
|
||||
flask init-db
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Local Development
|
||||
2. Install Python dependencies:
|
||||
```bash
|
||||
# Start development server
|
||||
flask run --host=0.0.0.0 --port=5001
|
||||
|
||||
# Optional: Kill any existing flask server first
|
||||
pkill -f "flask run" && flask run --host=0.0.0.0 --port=5001
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### Docker Deployment
|
||||
3. Configure environment variables:
|
||||
```bash
|
||||
# First generate and set your secret key
|
||||
python -c 'import secrets; print(f"FLASK_SECRET_KEY={secrets.token_hex(32)}")' >> .env
|
||||
cp .env.example .env
|
||||
# Edit .env with your configuration
|
||||
```
|
||||
|
||||
# Then start the container
|
||||
## Running the Application
|
||||
|
||||
### Development Mode
|
||||
```bash
|
||||
flask run --port=5000 --debug
|
||||
```
|
||||
|
||||
### Production Mode with Docker
|
||||
```bash
|
||||
docker-compose up --build
|
||||
|
||||
# Production deployment (detached mode)
|
||||
docker-compose up --build -d
|
||||
```
|
||||
|
||||
Note: Docker will automatically load the `.env` file from your project root
|
||||
|
||||
The application will be available at `http://localhost:5001`
|
||||
|
||||
### Persisting Data
|
||||
The database file (database.db) will be preserved between container restarts through the `./instance` volume mount.
|
||||
|
||||
**Important:** After renaming the database:
|
||||
1. Delete the old database file if it exists:
|
||||
```bash
|
||||
rm instance/users.db
|
||||
```
|
||||
2. Reinitialize the database:
|
||||
```bash
|
||||
flask init-db
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
### Secret Key Management
|
||||
The application uses a hierarchical configuration for the secret key:
|
||||
1. Environment variable `FLASK_SECRET_KEY` (highest priority)
|
||||
2. Hardcoded value in `app.py` (development fallback only)
|
||||
|
||||
**Production Setup:**
|
||||
```bash
|
||||
# Generate a secure secret key
|
||||
python -c 'import secrets; print(secrets.token_hex(32))'
|
||||
|
||||
# Update .env file
|
||||
echo "FLASK_SECRET_KEY=your_generated_secret_here" >> .env
|
||||
Essential environment variables in `.env`:
|
||||
```ini
|
||||
FLASK_APP=app.py
|
||||
FLASK_ENV=production
|
||||
DATABASE_URL=sqlite:///instance/app.db
|
||||
SECRET_KEY=your-secret-key-here
|
||||
```
|
||||
|
||||
**Important Security Notes:**
|
||||
- Never commit the `.env` file to version control
|
||||
- The default secret key should only be used for development
|
||||
- In production, use proper secret management (Vault, KMS, etc.)
|
||||
## Deployment
|
||||
|
||||
## Features
|
||||
- User registration with password confirmation
|
||||
- Secure password hashing
|
||||
- Login/logout functionality
|
||||
- SQLite database
|
||||
- Environment-based configuration
|
||||
1. Build production Docker image:
|
||||
```bash
|
||||
docker build -t flask-base:latest .
|
||||
```
|
||||
|
||||
2. Start container with database:
|
||||
```bash
|
||||
docker-compose -f docker-compose.prod.yml up -d
|
||||
```
|
||||
|
||||
## Project Structure
|
||||
```
|
||||
flask-base/
|
||||
├── app.py
|
||||
├── Dockerfile
|
||||
├── docker-compose.yml
|
||||
├── requirements.txt
|
||||
└── templates/
|
||||
├── base.html
|
||||
├── login.html
|
||||
├── register.html
|
||||
└── dashboard.html
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Create your feature branch:
|
||||
```bash
|
||||
git checkout -b feature/your-feature
|
||||
```
|
||||
|
||||
2. Commit changes:
|
||||
```bash
|
||||
git commit -m 'Add some feature'
|
||||
```
|
||||
|
||||
3. Push to branch:
|
||||
```bash
|
||||
git push origin feature/your-feature
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT License - see [LICENSE](LICENSE) for details
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user