From 54e382cbb326fab4011fece6b34301fe45c1fffa Mon Sep 17 00:00:00 2001 From: Jacob Hagstedt Date: Sun, 26 Apr 2026 20:29:45 +0200 Subject: [PATCH] Building docker --- backend/Dockerfile | 4 +-- backend/README.md | 75 ++++++++++++++++++++++++++++++++++++++++++ backend/pyproject.toml | 2 +- build-docker.sh | 16 +++++++++ docker-compose.yml | 2 +- push-docker.sh | 0 setup-docker.sh | 3 ++ 7 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 backend/README.md create mode 100644 build-docker.sh create mode 100644 push-docker.sh create mode 100644 setup-docker.sh diff --git a/backend/Dockerfile b/backend/Dockerfile index 195f2c1..6c85858 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -2,8 +2,8 @@ FROM python:3.14-slim AS base WORKDIR /app FROM base AS builder -# Copy pyproject.toml first to leverage Docker cache -COPY pyproject.toml . +# Copy pyproject.toml and README.md first to leverage Docker cache +COPY pyproject.toml README.md ./ # We can use pip to install the project in editable mode or just dependencies RUN pip install --no-cache-dir . diff --git a/backend/README.md b/backend/README.md new file mode 100644 index 0000000..75bee38 --- /dev/null +++ b/backend/README.md @@ -0,0 +1,75 @@ +# Baby Sleep Tracker + +A self-hosted web application for tracking infant sleep sessions, optimized for Raspberry Pi 4 (ARM64). + +## Features + +- **Tracker Tab**: Start and stop sleep sessions with a single click. Adjust start/end times easily. +- **Stats Tab**: Visualize sleep patterns with daily summaries (day vs. night), continuous time-slot grids, and wakeup/bedtime trend plots. +- **Responsive Design**: Built for mobile use via a clean, thumb-friendly UI. +- **Dockerized**: Easy deployment using Docker Compose. + +## Tech Stack + +- **Frontend**: React 19, Vite 6, TypeScript, Tailwind CSS v4, Recharts, TanStack Query. +- **Backend**: Python 3.12+, FastAPI, SQLModel (SQLAlchemy + P/Dantic), SQLite. +- **Deployment**: Docker, Docker Compose. + +## Getting Started + +### Prerequisites + +- [Docker](https://docs.docker.com/get-docker/) +- [Docker Compose](https://docs.docker.com/compose/install/) + +*Note: If building on an x86 machine for ARM64 (Raspberry Pi), ensure you use `docker buildx`.* + +### Running with Docker Compose + +1. Clone the repository. +2. Navigate to the project root. +3. Run the following command: + +```bash +docker compose up --build +``` + +The application will be available at: +- **Frontend**: [http://localhost](http://localhost) +- **Backend API**: [http://localhost:8000](http://localhost:8000) + +### Development Setup + +#### Backend + +Requires `uv` and Python 3.14+. + +```bash +cd backend +uv sync +uv run uvicorn app.main:app --reload +``` + +Run tests: +```bash +uv run pytest +``` + +#### Frontend + +```bash +cd frontend +npm install +npm run dev +``` + +Run tests: +```bash +npm run test +``` + +## Project Structure + +- `backend/`: FastAPI application, models, and API routes. +- `frontend/`: React application with components and hooks. +- `docker-compose.yml`: Orchestration for the full stack. diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 874e0c6..6ce2b72 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -2,7 +2,7 @@ name = "baby-sleep-tracker-backend" version = "0.1.0" description = "FastAPI backend for Baby Sleep Tracker" -readme = "../README.md" +readme = "README.md" requires-python = ">=3.14" dependencies = [ "fastapi", diff --git a/build-docker.sh b/build-docker.sh new file mode 100644 index 0000000..e1f2a49 --- /dev/null +++ b/build-docker.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +docker buildx build \ + --platform linux/arm64 \ + -t babymonitor-frontend:latest \ + -f frontend/Dockerfile + --load + frontend + +docker buildx build \ + --platform linux/arm64 \ + -t babymonitor-backend:latest \ + -f backend/Dockerfile + --load + backend + \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 3f746ed..39fc147 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,7 @@ services: context: ./frontend platforms: [linux/arm64] ports: - - "80:80" + - "8080:80" depends_on: - backend restart: unless-stopped diff --git a/push-docker.sh b/push-docker.sh new file mode 100644 index 0000000..e69de29 diff --git a/setup-docker.sh b/setup-docker.sh new file mode 100644 index 0000000..6652a81 --- /dev/null +++ b/setup-docker.sh @@ -0,0 +1,3 @@ +#!/bin/bash +docker buildx create --name babymonitorbuilder --use +docker buildx inspect --bootstrap