From f714fa46ba9a44a40121ec9f2b2931f5139cb30d Mon Sep 17 00:00:00 2001 From: jafreli Date: Sat, 19 Jul 2025 00:46:42 +0200 Subject: [PATCH] =?UTF-8?q?Hinzuf=C3=BCgen=20des=20Docker=20Containerst?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 58 ++++++++++++++++ .gitea/workflows/docker.yml | 76 +++++++++++++++++++++ Dockerfile | 33 +++++++++ README.md | 129 ++++++++++++++++++++++++++++++++++++ docker-compose.yml | 15 +++++ requirements.txt | 3 + 6 files changed, 314 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitea/workflows/docker.yml create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 docker-compose.yml create mode 100644 requirements.txt diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6bd87a1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,58 @@ +# Git +.git +.gitignore +.gitea + +# Python +__pycache__ +*.pyc +*.pyo +*.pyd +.Python +env +pip-log.txt +pip-delete-this-directory.txt +.tox +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.log +.git +.mypy_cache +.pytest_cache +.hypothesis + +# Virtual environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Documentation +README.md +*.md + +# Database (will be created in container) +habits.json \ No newline at end of file diff --git a/.gitea/workflows/docker.yml b/.gitea/workflows/docker.yml new file mode 100644 index 0000000..727c064 --- /dev/null +++ b/.gitea/workflows/docker.yml @@ -0,0 +1,76 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + - master + tags: + - 'v*' + pull_request: + branches: + - main + - master + +env: + REGISTRY: git.out.jafre.li # Ersetze mit deiner Gitea-Domain + IMAGE_NAME: habit-tracker + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ gitea.actor }} + password: ${{ secrets.GITEA_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ gitea.repository_owner }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Generate deployment info + run: | + echo "## Docker Image Built Successfully! 🐳" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "**Image:** \`${{ env.REGISTRY }}/${{ gitea.repository_owner }}/${{ env.IMAGE_NAME }}:latest\`" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### Quick Start:" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY + echo "docker run -d \\" >> $GITHUB_STEP_SUMMARY + echo " --name habit-tracker \\" >> $GITHUB_STEP_SUMMARY + echo " -p 5000:5000 \\" >> $GITHUB_STEP_SUMMARY + echo " -v habit-data:/app/data \\" >> $GITHUB_STEP_SUMMARY + echo " ${{ env.REGISTRY }}/${{ gitea.repository_owner }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cae85c8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# Use Python 3.11 slim image +FROM python:3.11-slim + +# Set working directory +WORKDIR /app + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + gcc \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements first for better caching +COPY requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy application code +COPY . . + +# Create directory for database +RUN mkdir -p /app/data + +# Expose port +EXPOSE 5000 + +# Set environment variables +ENV FLASK_APP=app.py +ENV FLASK_ENV=production +ENV PYTHONPATH=/app + +# Run the application +CMD ["python", "-m", "flask", "run", "--host=0.0.0.0", "--port=5000"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e416ef7 --- /dev/null +++ b/README.md @@ -0,0 +1,129 @@ +# Habit Tracker + +Ein einfacher Habit Tracker mit wöchentlicher Ansicht, gebaut mit Flask und JavaScript. + +## Features + +- 📅 Wöchentliche Ansicht (7 Zeilen für jeden Wochentag) +- 🎯 Anpassbare Tagesziele (1-20x pro Tag) +- 🎨 Individuelle Farben für jedes Habit +- 🔥 Streak-Zähler +- 📱 Responsive Design +- 🐳 Docker-Support + +## Schnellstart mit Docker + +### Aus der Registry +```bash +docker run -d \ + --name habit-tracker \ + -p 5000:5000 \ + -v habit-data:/app/data \ + gitea.example.com/username/habit-tracker:latest +``` + +### Lokal bauen +```bash +# Repository klonen +git clone +cd habit-tracker + +# Mit Docker Compose +docker-compose up -d + +# Oder manuell +docker build -t habit-tracker . +docker run -d \ + --name habit-tracker \ + -p 5000:5000 \ + -v habit-data:/app/data \ + habit-tracker +``` + +## Lokale Entwicklung + +```bash +# Virtual Environment erstellen +python -m venv venv +source venv/bin/activate # Linux/Mac +# oder +venv\Scripts\activate # Windows + +# Dependencies installieren +pip install -r requirements.txt + +# App starten +python app.py +``` + +Die App ist dann unter http://localhost:5000 erreichbar. + +## Konfiguration + +### Umgebungsvariablen +- `FLASK_ENV`: `production` oder `development` (Standard: `production`) +- `FLASK_APP`: `app.py` (Standard) + +### Volumes +- `/app/data`: Hier wird die `habits.json` Datenbank gespeichert + +## Deployment + +### Docker Compose (Empfohlen) +```yaml +version: '3.8' + +services: + habit-tracker: + image: gitea.example.com/username/habit-tracker:latest + ports: + - "5000:5000" + volumes: + - ./data:/app/data + environment: + - FLASK_ENV=production + restart: unless-stopped +``` + +### Reverse Proxy (Nginx) +```nginx +server { + listen 80; + server_name habits.example.com; + + location / { + proxy_pass http://localhost:5000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} +``` + +## Bedienung + +1. **Habit hinzufügen**: Namen eingeben und "Hinzufügen" klicken +2. **Heute abhaken**: ✓-Button klicken (zeigt Fortschritt bei Zielen >1) +3. **Vergangene Tage bearbeiten**: Drei-Punkte-Menü → Modal öffnen +4. **Einstellungen**: Im Modal Farbe und Tagesziel anpassen +5. **Löschen**: Im Modal über den "Löschen"-Button + +## Technische Details + +- **Backend**: Flask (Python) +- **Frontend**: Vanilla JavaScript +- **Datenbank**: TinyDB (JSON-basiert) +- **Styling**: CSS Grid/Flexbox +- **Container**: Multi-Arch (AMD64/ARM64) + +## CI/CD + +Der Gitea-Workflow baut automatisch Docker-Images bei: +- Push auf `main`/`master` Branch +- Neue Tags (z.B. `v1.0.0`) +- Pull Requests + +## Lizenz + +MIT License \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8f8a787 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: '3.8' + +services: + habit-tracker: + build: . + ports: + - "5000:5000" + volumes: + - habit-data:/app/data + environment: + - FLASK_ENV=production + restart: unless-stopped + +volumes: + habit-data: \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b591fb8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +Flask==2.3.3 +tinydb==4.8.0 +Werkzeug==2.3.7 \ No newline at end of file