rewrited redme.md file
This commit is contained in:
parent
de538bbdfb
commit
c7c422c31f
314
readme.md
314
readme.md
|
|
@ -1,120 +1,117 @@
|
||||||
cd ~/Dokumenti/scripts/Fitnes-tracker
|
# 🏋️ Fitness Tracker
|
||||||
|
|
||||||
# Stop the container
|
A lightweight, self-hosted fitness tracking application designed for StrongLifts 5×5 powerlifting programs. Built with Go and SQLite for simplicity, privacy, and performance.
|
||||||
docker compose down
|
|
||||||
|
|
||||||
# Create the folder if it doesn't exist (safe to run even if it exists)
|
## ✨ Features
|
||||||
mkdir -p fitness-data
|
|
||||||
|
|
||||||
# Make sure container user (uid 1000) can write there
|
- **Workout Logging**: Track exercises with start and finish times
|
||||||
sudo chown -R 1000:1000 fitness-data
|
- **A/B Templates**: StrongLifts-style alternating workout plans
|
||||||
sudo chmod 775 fitness-data
|
- **Automatic Rest Tracking**: Monitor recovery time between sets
|
||||||
|
- **Volume Analytics**: Daily, weekly, and monthly training volume statistics
|
||||||
|
- **Self-Hosted**: Complete data ownership with SQLite backend
|
||||||
|
- **Docker Support**: Containerized deployment with proper UID/GID handling
|
||||||
|
- **Persistent Storage**: External database mounting for easy backups
|
||||||
|
|
||||||
# Start again
|
## 📋 Table of Contents
|
||||||
docker compose up
|
|
||||||
|
|
||||||
|
- [Quick Start](#-quick-start)
|
||||||
|
- [Local Development](#-local-development)
|
||||||
|
- [Docker Deployment](#-docker-deployment)
|
||||||
|
- [Production Setup](#-production-setup)
|
||||||
|
- [Backup Strategy](#-backup-strategy)
|
||||||
|
- [Project Structure](#-project-structure)
|
||||||
|
- [License](#-license)
|
||||||
|
|
||||||
Fitness Tracker – Self-Hosted 5×5 Powerlifting App
|
## 🚀 Quick Start
|
||||||
|
|
||||||
A minimal self-hosted fitness tracker built in Go.
|
### Prerequisites
|
||||||
Includes:
|
|
||||||
|
|
||||||
Workout logging with start/finish
|
- Go 1.21+ (for local development)
|
||||||
|
- Docker & Docker Compose (for containerized deployment)
|
||||||
|
- Linux/macOS environment recommended
|
||||||
|
|
||||||
A/B templates (StrongLifts style)
|
### Clone the Repository
|
||||||
|
|
||||||
Automatic rest-time tracking
|
```bash
|
||||||
|
git clone https://forgejo.rozic-dev.com/Dejan/Fitnes-tracker.git
|
||||||
|
cd Fitnes-tracker
|
||||||
|
```
|
||||||
|
|
||||||
Volume tracking (today/week/month)
|
## 💻 Local Development
|
||||||
|
|
||||||
SQLite database
|
### 1. Install Go
|
||||||
|
|
||||||
Fully Dockerized (with UID/GID support)
|
|
||||||
|
|
||||||
External fitness.db mounted to host
|
|
||||||
|
|
||||||
This app is designed to be simple, private, and fast, perfect for home servers or local use.
|
|
||||||
|
|
||||||
📁 Project Structure
|
|
||||||
Fitnes-tracker/
|
|
||||||
│── main.go
|
|
||||||
│── go.mod
|
|
||||||
│── Dockerfile
|
|
||||||
│── docker-compose.yml
|
|
||||||
│── readme.md
|
|
||||||
│── fitness-data/ # External volume (database lives here)
|
|
||||||
│ └── fitness.db
|
|
||||||
|
|
||||||
🔥 1. Running Locally (Development Mode)
|
|
||||||
Install Go
|
|
||||||
|
|
||||||
Ubuntu / Debian:
|
|
||||||
|
|
||||||
|
**Ubuntu/Debian:**
|
||||||
|
```bash
|
||||||
sudo apt update
|
sudo apt update
|
||||||
sudo apt install -y golang-go
|
sudo apt install -y golang-go
|
||||||
|
|
||||||
|
|
||||||
Verify:
|
|
||||||
|
|
||||||
go version
|
go version
|
||||||
|
```
|
||||||
|
|
||||||
Run the app
|
### 2. Run the Application
|
||||||
|
|
||||||
Inside the project folder:
|
```bash
|
||||||
|
|
||||||
cd Fitnes-tracker
|
|
||||||
DATABASE_URL=./fitness.db go run main.go
|
DATABASE_URL=./fitness.db go run main.go
|
||||||
|
```
|
||||||
|
|
||||||
|
The application will be available at `http://localhost:8080`
|
||||||
|
|
||||||
Open in browser:
|
The SQLite database will be created as `./fitness.db` in the project directory.
|
||||||
|
|
||||||
👉 http://localhost:8080
|
## 🐳 Docker Deployment
|
||||||
|
|
||||||
Local DB file will be created as:
|
### 1. Prepare the Environment
|
||||||
|
|
||||||
./fitness.db
|
Create the data directory with proper permissions:
|
||||||
|
|
||||||
🐳 2. Running with Docker (Recommended)
|
```bash
|
||||||
|
|
||||||
Make sure Docker + docker-compose are installed:
|
|
||||||
|
|
||||||
sudo apt install -y docker.io docker-compose-plugin
|
|
||||||
sudo usermod -aG docker $USER
|
|
||||||
newgrp docker
|
|
||||||
|
|
||||||
Create external DB directory
|
|
||||||
mkdir -p fitness-data
|
mkdir -p fitness-data
|
||||||
|
|
||||||
Fix permissions so container user (UID 1000) can write
|
|
||||||
sudo chown -R 1000:1000 fitness-data
|
sudo chown -R 1000:1000 fitness-data
|
||||||
sudo chmod 775 fitness-data
|
sudo chmod 775 fitness-data
|
||||||
|
```
|
||||||
|
|
||||||
Build the Docker image
|
### 2. Build and Start
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Build the Docker image
|
||||||
docker compose build
|
docker compose build
|
||||||
|
|
||||||
Start the app
|
# Start the application
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
|
|
||||||
|
# View logs
|
||||||
Check logs:
|
|
||||||
|
|
||||||
docker compose logs -f
|
docker compose logs -f
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Verify Installation
|
||||||
|
|
||||||
You should see:
|
The application should now be running at `http://localhost:8080`
|
||||||
|
|
||||||
|
Check the logs for confirmation:
|
||||||
|
```
|
||||||
Using database file: /data/fitness.db
|
Using database file: /data/fitness.db
|
||||||
Listening on :8080 ...
|
Listening on :8080 ...
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4. Managing the Container
|
||||||
|
|
||||||
Open:
|
```bash
|
||||||
|
# Stop the application
|
||||||
|
docker compose down
|
||||||
|
|
||||||
👉 http://localhost:8080
|
# Restart the application
|
||||||
|
docker compose restart
|
||||||
|
|
||||||
🔧 3. Docker Compose Explained
|
# Rebuild after code changes
|
||||||
|
docker compose build
|
||||||
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
Your docker-compose.yml:
|
## 🔧 Docker Configuration
|
||||||
|
|
||||||
|
The `docker-compose.yml` configuration:
|
||||||
|
|
||||||
|
```yaml
|
||||||
services:
|
services:
|
||||||
fitness:
|
fitness:
|
||||||
build: .
|
build: .
|
||||||
|
|
@ -126,88 +123,143 @@ services:
|
||||||
- ./fitness-data:/data
|
- ./fitness-data:/data
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
|
```
|
||||||
|
|
||||||
What it does:
|
**Key Features:**
|
||||||
|
- **Volume Mount**: `./fitness-data` → `/data` (persistent storage on host)
|
||||||
|
- **Database Location**: `fitness-data/fitness.db`
|
||||||
|
- **Auto-restart**: Container restarts automatically unless manually stopped
|
||||||
|
- **Non-root User**: Runs as UID 1000 for security
|
||||||
|
|
||||||
Mounts ./fitness-data → /data inside container
|
### Verify Container User
|
||||||
|
|
||||||
SQLite DB stored on host: fitness-data/fitness.db
|
|
||||||
|
|
||||||
App always restarts unless manually stopped
|
|
||||||
|
|
||||||
Binds port 8080 (browser UI)
|
|
||||||
|
|
||||||
👤 4. Running container as UID 1000:1000
|
|
||||||
|
|
||||||
The app inside the container runs as a regular Linux user (not root).
|
|
||||||
This avoids permission issues and is safer.
|
|
||||||
|
|
||||||
To check container UID/GID:
|
|
||||||
|
|
||||||
|
```bash
|
||||||
docker exec -it fitness-tracker id
|
docker exec -it fitness-tracker id
|
||||||
|
```
|
||||||
|
|
||||||
Expected output:
|
Expected output:
|
||||||
|
```
|
||||||
uid=1000(appuser) gid=1000(appuser)
|
uid=1000(appuser) gid=1000(appuser)
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🌐 Production Setup
|
||||||
|
|
||||||
If permissions are wrong, fix host directory:
|
### Reverse Proxy with Traefik
|
||||||
|
|
||||||
|
Add these labels to your `docker-compose.yml`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
fitness:
|
||||||
|
# ... existing configuration ...
|
||||||
|
labels:
|
||||||
|
- "traefik.enable=true"
|
||||||
|
- "traefik.http.routers.fitness.rule=Host(`fitness.yourdomain.com`)"
|
||||||
|
- "traefik.http.routers.fitness.entrypoints=websecure"
|
||||||
|
- "traefik.http.routers.fitness.tls.certresolver=letsencrypt"
|
||||||
|
- "traefik.http.services.fitness.loadbalancer.server.port=8080"
|
||||||
|
networks:
|
||||||
|
- traefik_default
|
||||||
|
|
||||||
|
networks:
|
||||||
|
traefik_default:
|
||||||
|
external: true
|
||||||
|
```
|
||||||
|
|
||||||
|
## 💾 Backup Strategy
|
||||||
|
|
||||||
|
### Manual Backup
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Copy data directory
|
||||||
|
cp -r fitness-data fitness-data-backup-$(date +%Y%m%d)
|
||||||
|
|
||||||
|
# Create compressed archive
|
||||||
|
tar -czvf fitness-backup-$(date +%Y%m%d).tar.gz fitness-data/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Automated Backup Script
|
||||||
|
|
||||||
|
Create a cron job to back up daily:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Edit crontab
|
||||||
|
crontab -e
|
||||||
|
|
||||||
|
# Add daily backup at 2 AM
|
||||||
|
0 2 * * * tar -czvf ~/backups/fitness-$(date +\%Y\%m\%d).tar.gz ~/Fitnes-tracker/fitness-data/
|
||||||
|
```
|
||||||
|
|
||||||
|
## 📁 Project Structure
|
||||||
|
|
||||||
|
```
|
||||||
|
Fitnes-tracker/
|
||||||
|
├── main.go # Application entry point
|
||||||
|
├── go.mod # Go module dependencies
|
||||||
|
├── go.sum # Dependency checksums
|
||||||
|
├── Dockerfile # Container build instructions
|
||||||
|
├── docker-compose.yml # Docker Compose configuration
|
||||||
|
├── readme.md # This file
|
||||||
|
├── .gitignore # Git ignore rules
|
||||||
|
└── fitness-data/ # Persistent data directory (not in git)
|
||||||
|
└── fitness.db # SQLite database
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🛠️ Troubleshooting
|
||||||
|
|
||||||
|
### Permission Issues
|
||||||
|
|
||||||
|
If you encounter database permission errors:
|
||||||
|
|
||||||
|
```bash
|
||||||
sudo chown -R 1000:1000 fitness-data
|
sudo chown -R 1000:1000 fitness-data
|
||||||
sudo chmod 775 fitness-data
|
sudo chmod 775 fitness-data
|
||||||
|
docker compose restart
|
||||||
|
```
|
||||||
|
|
||||||
📦 5. Rebuilding & Updating
|
### Port Already in Use
|
||||||
|
|
||||||
Whenever you modify Go code:
|
Change the port mapping in `docker-compose.yml`:
|
||||||
|
|
||||||
docker compose build
|
```yaml
|
||||||
|
ports:
|
||||||
|
- "8081:8080" # Use port 8081 instead
|
||||||
|
```
|
||||||
|
|
||||||
|
### Database Locked
|
||||||
|
|
||||||
|
Ensure only one instance is running:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose down
|
||||||
|
# Wait a few seconds
|
||||||
docker compose up -d
|
docker compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🤝 Contributing
|
||||||
|
|
||||||
If you want to clean old images:
|
1. Fork the repository
|
||||||
|
2. Create a feature branch: `git checkout -b feature-name`
|
||||||
|
3. Commit your changes: `git commit -m 'Add feature'`
|
||||||
|
4. Push to the branch: `git push origin feature-name`
|
||||||
|
5. Open a pull request
|
||||||
|
|
||||||
docker system prune -f
|
### Git Configuration
|
||||||
|
|
||||||
📤 6. Production Setup (Traefik Support)
|
```bash
|
||||||
|
git config --global user.name "Your Name"
|
||||||
|
git config --global user.email "your.email@example.com"
|
||||||
|
```
|
||||||
|
|
||||||
To put behind Traefik:
|
## 📝 License
|
||||||
|
|
||||||
Add labels inside docker-compose.yml:
|
This project is private and proprietary.
|
||||||
|
|
||||||
labels:
|
## 🔗 Links
|
||||||
- "traefik.enable=true"
|
|
||||||
- "traefik.http.routers.fitness.rule=Host(`fitness.rozic-dev.com`)"
|
|
||||||
- "traefik.http.routers.fitness.entrypoints=websecure"
|
|
||||||
- "traefik.http.routers.fitness.tls.certresolver=letsencrypt"
|
|
||||||
- "traefik.http.services.fitness.loadbalancer.server.port=8080"
|
|
||||||
networks:
|
|
||||||
- traefik_default
|
|
||||||
|
|
||||||
💾 7. Backup
|
- Repository: [https://forgejo.rozic-dev.com/Dejan/Fitnes-tracker](https://forgejo.rozic-dev.com/Dejan/Fitnes-tracker)
|
||||||
|
- Issues: [Report a bug](https://forgejo.rozic-dev.com/Dejan/Fitnes-tracker/issues)
|
||||||
|
|
||||||
Just back up the fitness-data/ folder:
|
---
|
||||||
|
|
||||||
cp -r fitness-data fitness-data-backup
|
**Built with ❤️ for the StrongLifts community**
|
||||||
|
|
||||||
|
|
||||||
Or tar it:
|
|
||||||
|
|
||||||
tar -czvf fitness-backup.tar.gz fitness-data/
|
|
||||||
|
|
||||||
📚 8. Git Instructions
|
|
||||||
Set your identity once:
|
|
||||||
git config --global user.name "Dejan R."
|
|
||||||
git config --global user.email "dejan@example.com"
|
|
||||||
|
|
||||||
Useful Commands
|
|
||||||
git add .
|
|
||||||
git commit -m "update"
|
|
||||||
git push
|
|
||||||
|
|
||||||
.gitignore (already included)
|
|
||||||
*.db
|
|
||||||
fitness-data/
|
|
||||||
|
|
||||||
|
|
||||||
DB files will never pollute your git history.
|
|
||||||
Loading…
Reference in a new issue