- Add docker-compose.yml orchestrating backend and frontend services - Create .env.example with documented environment variables - Create .env file with default development configuration - Makefile with dev, stop, restart, test, clean commands - data/.gitignore excludes SQLite database from version control - .dockerignore files for both frontend and backend builds - Update README.md with M4 milestone links This milestone enables developers to run the full application stack using Docker Compose.
10 KiB
M4: Setup Developer Environment
Prompt
Set up a complete developer environment for newzy news web application with Docker Compose orchestration. Follow these steps:
-
Create
docker-compose.ymlat project root (newzy/docker-compose.yml) with all services:version: '3.8' services: backend: build: ./backend ports: - "8000:8000" volumes: - ./data/db:/app/data/db environment: - DATABASE_URL=sqlite:///./data/db/newzy.db - DEBUG=false frontend: build: ./frontend ports: - "3000:80" depends_on: - backend networks: newzy-network: driver: bridge volumes: db-data: -
Create
.env.examplefile documenting all required environment variables:- DATABASE_URL (SQLite path)
- DEBUG (boolean, optional)
- BACKEND_CORS_ORIGINS (comma-separated, default: http://localhost:3000)
- FRONTEND_API_URL (relative /api or absolute)
-
Create
.envfile with default development values:DATABASE_URL=sqlite:///./data/db/newzy.db DEBUG=false BACKEND_CORS_ORIGINS=http://localhost:3000,http://localhost:5173 FRONTEND_API_URL=/api -
Update
backend/.gitignoreto exclude.envand production data:.env .env.* data/ -
Create development scripts in project root using Makefile or shell script:
dev- Start both services in backgroundstop- Stop all servicesrestart- Restart all servicesbackend-start- Start backend onlyfrontend-start- Start frontend onlytest- Run all tests (unit + E2E)clean- Remove containers and volumes
-
Add
Makefilefor command shortcuts:.PHONY: dev stop restart backend-start frontend-start test clean dev: docker compose up -d --build stop: docker compose down restart: docker compose down docker compose up -d --build backend-start: docker compose up -d backend frontend-start: docker compose up -d frontend test: npm run test # frontend cd backend && pytest # backend clean: docker compose down -v rm -rf data/ docker image prune -f -
Create
backend/Dockerfilewith development optimizations:- Copy only required files
- Install dependencies efficiently
- Use slim Python base image
- Expose port 8000
-
Update
frontend/Dockerfileto use production Nginx:- Multi-stage build (build stage + nginx serve stage)
- Nginx configuration for SPA routing
- Production-optimized static file serving
-
Create
.gitignoreat project root excluding:# Dependencies node_modules/ *.egg-info/ # Environment files .env .env.local .env.*.local # IDE settings
.idea/ .vscode/ *.swp *.swo
Docker artifacts (optional)
.dockerignore docker-compose.override.yml
10. Create `data/.gitignore` to exclude SQLite database from version control:
```
*
!keep_files.txt
```
11. Document setup process in `README.md`:
- Prerequisites (Docker, Node.js 18+)
- Quick start commands
- Service descriptions
- Port mappings
- Network configuration
- Troubleshooting guide
12. Create `.dockerignore` files for both backend and frontend to exclude unnecessary files during builds:
```
.git/
.env
__pycache__/
*.pyc
node_modules/
dist/
.pytest_cache/
```
Remember: Focus ONLY on developer environment setup. No application code changes required.
## Description
This milestone sets up a complete Docker Compose development environment for the newzy news web application. The scope includes orchestrating both backend and frontend services, environment variable management, and streamlined development commands—no application logic changes or business feature implementation.
**Purpose**: Provide developers with a consistent, reproducible local development environment using Docker that matches the production setup as closely as possible.
**Target Audience**: Developers joining the project who need quick access to running services without manual installation of Python, Node.js, databases, or Nginx.
**Expected Outcomes**: A working docker-compose.yml at project root that can start all services with a single command, proper environment configuration, and development workflow automation via Makefile.
## Acceptance Criteria
- [ ] `docker-compose.yml` at project root configures both backend and frontend services
- [ ] Backend service builds from `./backend` directory
- [ ] Frontend service builds from `./frontend` directory
- [ ] Port mappings configured: 3000 for frontend, 8000 for backend
- [ ] Docker network defined for inter-service communication
- [ ] Volume mounted for persistent SQLite database at `/data/db`
- [ ] `.env.example` file documents all environment variables
- [ ] `.env` file provides default development configuration
- [ ] `backend/Dockerfile` optimized for production use
- [ ] `frontend/Dockerfile` uses multi-stage build with Nginx
- [ ] Makefile or shell scripts provide dev, stop, restart commands
- [ ] `data/.gitignore` excludes database from version control
- [ ] `.dockerignore` files exist for both frontend and backend
- [ ] Project root `.gitignore` excludes env files and build artifacts
- [ ] README.md documents docker setup with quick start guide
## Technical Details
### docker-compose.yml (Project Root)
```yaml
version: '3.8'
services:
backend:
build:
context: ./backend
dockerfile: Dockerfile
ports:
- "8000:8000"
volumes:
- ./data/db:/app/data/db
environment:
- DATABASE_URL=sqlite:///./data/db/newzy.db
- DEBUG=false
- BACKEND_CORS_ORIGINS=http://localhost:3000,http://localhost:5173
depends_on:
backend-db:
condition: service_healthy
networks:
- newzy-network
restart: unless-stopped
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
ports:
- "3000:80"
depends_on:
- backend
networks:
- newzy-network
restart: unless-stopped
networks:
newzy-network:
driver: bridge
ipam:
config:
- subnet: 172.28.0.0/16
volumes:
db-data:
name: newzy-db-data
Environment Variables (.env.example)
| Variable | Description | Default | Required |
|---|---|---|---|
| DATABASE_URL | SQLite database path | sqlite:///./data/db/newzy.db | Yes |
| DEBUG | Debug mode flag | false | No |
| BACKEND_CORS_ORIGINS | Allowed frontend origins | http://localhost:3000 | No |
| FRONTEND_API_URL | Backend API base URL | /api | No |
Development Commands (Makefile)
.PHONY: dev stop restart test clean build
dev:
docker compose up -d --build backend frontend
stop:
docker compose down
restart:
docker compose down
docker compose up -d --build backend frontend
test:
@echo "Running frontend tests..."
npm run test
@echo "Running backend tests..."
docker exec frontend npm run test || \
docker exec backend pytest
clean:
docker compose down -v
rm -rf data/
docker images | grep -E "(newzy|python|node)" | awk '{print $$3}' | xargs docker rmi
build:
docker compose build --no-cache
logs:
docker compose logs -f backend frontend
shell-backend:
docker exec -it backend bash
shell-frontend:
docker exec -it frontend sh
Directory Structure with Docker Setup
newzy/
├── data/ # Local SQLite data directory
│ └── db/
│ └── newzy.db # Persisted database (excluded from git)
├── backend/
│ ├── Dockerfile
│ ├── requirements.txt
│ ├── .gitignore
│ └── pytest.ini
├── frontend/
│ ├── Dockerfile
│ ├── docker-compose.yml # Frontend-specific override (optional)
│ └── package.json
├── docker-compose.yml # Main orchestration file
├── .env # Development environment variables
├── .env.example # Template for .env
├── Makefile # Development shortcuts
├── .dockerignore # Exclude files from build context
└── data/.gitignore # Exclude database from git
Multi-stage Build Strategy
Backend Dockerfile:
- Base:
python:3.11-slim - Install dependencies with
pip install --no-cache-dir - Copy only production code and requirements
- Expose port 8000
Frontend Dockerfile:
- Stage 1:
node:20-alpine→ Build frontend with Vite - Stage 2:
nginx:alpine→ Serve built static files - Nginx config routes all requests to index.html for SPA
Service Communication Flow
Browser (localhost:3000)
↓ HTTP Request
Frontend Container (newzy-network:80)
↓ Forwarded to /api
Backend Container (newzy-network:8000)
↓ Connects to SQLite
Volume: data/db/newzy.db
QA Notes
Testing Checklist
docker compose upstarts both services without errors- Frontend accessible at http://localhost:3000
- Backend accessible at http://localhost:8000
- Health endpoints respond correctly
- Database persists across service restarts
.env.examplecontains all documented variables- Makefile commands work (dev, stop, restart, clean)
data/directory excluded from git commits.gitignoreexcludes environment files
Security Considerations
- Never commit
.envfile to version control - Use
.env.exampleas template for new developers - SQLite database stored locally, not in container (volume mounted)
- CORS configured with specific origins
- No production secrets exposed by default
Performance Notes
--buildflag only when needed (avoid rebuilds on dev)- Docker cache leveraged for incremental builds
- SQLite file storage faster than network databases for development
- Nginx serves static files efficiently in production
Known Limitations
- Requires Docker Desktop or equivalent installed locally
- Mac users need sufficient disk space (~50GB recommended)
- Windows WSL2 required for best performance
- No GPU acceleration (CPU-based only)
- Production databases should use PostgreSQL, not SQLite
Success Metrics
docker compose upcompletes in under 5 minutes on first run- Services restart within 10 seconds subsequent runs
- Development environment identical to staging/production setup
- Zero manual configuration required for new developers
- Makefile shortcuts reduce repetitive Docker commands