diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..b2c9567 --- /dev/null +++ b/.env.example @@ -0,0 +1,11 @@ +# IMPORTANT: Generate a secure encryption key before deploying +# Run: openssl rand -base64 32 +# Then replace the value below with your generated key + +ENCRYPTION_KEY=change-this-to-a-secure-random-key + +# Optional: Set custom port (default is 7654) +# PORT=7654 + +# Environment +NODE_ENV=production diff --git a/.gitignore b/.gitignore index 5ef6a52..82c87bc 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ yarn-error.log* # env files (can opt-in for committing if needed) .env* +!.env.example # vercel .vercel @@ -39,3 +40,10 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts + +# Docker +docker-compose.override.yml + +# User data (encrypted local storage) +data/* +!data/.gitignore diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md new file mode 100644 index 0000000..69fbe44 --- /dev/null +++ b/DEPLOYMENT.md @@ -0,0 +1,148 @@ +# Capsule Budget - ZimaOS Deployment Guide + +## Quick Deploy + +1. **Clone or upload this repository to your ZimaOS device** + +2. **Run the deployment script:** + ```bash + ./deploy.sh + ``` + + This will: + - Generate a secure encryption key + - Clear any test data + - Build the Docker image + - Start the container + +3. **Access Capsule:** + - Open browser to `http://your-zima-ip:7654` + - Create your account and start budgeting! + +## Manual Deployment + +If you prefer manual setup: + +1. **Create .env file:** + ```bash + cp .env.example .env + ``` + +2. **Generate encryption key:** + ```bash + openssl rand -base64 32 + ``` + +3. **Update .env with your key:** + ```bash + ENCRYPTION_KEY=your-generated-key-here + ``` + +4. **Build and start:** + ```bash + docker-compose up -d + ``` + +## ZimaOS Integration + +### Using ZimaOS Apps + +If ZimaOS supports custom apps: + +1. Navigate to Apps section +2. Click "Add Custom App" +3. Point to this directory +4. Configure port: 7654 + +### Using ZimaOS File Manager + +1. Upload project via web interface or SMB +2. SSH into ZimaOS +3. Navigate to project directory +4. Run `./deploy.sh` + +## Data Persistence + +All user data is stored in `./data/` directory: +- User credentials (hashed) +- Budget data (encrypted with AES-GCM) +- Transaction history + +**Backup Strategy:** +```bash +# Backup data +cp -r data data-backup-$(date +%Y%m%d) + +# Or use ZimaOS snapshot feature +``` + +## Management Commands + +```bash +# View logs +docker-compose logs -f + +# Stop Capsule +docker-compose stop + +# Restart Capsule +docker-compose restart + +# Stop and remove container +docker-compose down + +# Rebuild after updates +docker-compose build --no-cache +docker-compose up -d +``` + +## Updating Capsule + +```bash +# Pull latest changes +git pull + +# Rebuild and restart +docker-compose down +docker-compose build +docker-compose up -d +``` + +Your data in `./data/` will persist across updates. + +## Security Notes + +- Change the default ENCRYPTION_KEY before first use +- Keep your `.env` file secure and never commit it +- Use ZimaOS firewall to restrict access if needed +- Consider VPN-only access for additional security + +## Troubleshooting + +### Container won't start +```bash +# Check logs +docker-compose logs + +# Verify .env file exists +ls -la .env +``` + +### Port already in use +Edit `docker-compose.yml` and change port mapping: +```yaml +ports: + - "8080:7654" # Change 8080 to your preferred port +``` + +### Data not persisting +Ensure `./data` directory has correct permissions: +```bash +chmod 755 data +``` + +## Support + +For issues or questions: +- GitHub: https://github.com/nmemmert/budget +- Check logs: `docker-compose logs -f` diff --git a/Dockerfile b/Dockerfile index d4ef318..2cb1755 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-alpine +FROM node:18-alpine # Set working directory WORKDIR /app @@ -6,34 +6,23 @@ WORKDIR /app # Copy package files COPY package*.json ./ -# Install dependencies -RUN npm ci +# Install dependencies (production only) +RUN npm ci --only=production # Copy source code COPY . . -# Set environment variables -ARG NEXT_PUBLIC_FIREBASE_API_KEY -ARG NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN -ARG NEXT_PUBLIC_FIREBASE_PROJECT_ID -ARG NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET -ARG NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID -ARG NEXT_PUBLIC_FIREBASE_APP_ID -ARG NEXT_PUBLIC_ENCRYPTION_KEY - -ENV NEXT_PUBLIC_FIREBASE_API_KEY=$NEXT_PUBLIC_FIREBASE_API_KEY -ENV NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=$NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN -ENV NEXT_PUBLIC_FIREBASE_PROJECT_ID=$NEXT_PUBLIC_FIREBASE_PROJECT_ID -ENV NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=$NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET -ENV NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=$NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID -ENV NEXT_PUBLIC_FIREBASE_APP_ID=$NEXT_PUBLIC_FIREBASE_APP_ID -ENV NEXT_PUBLIC_ENCRYPTION_KEY=$NEXT_PUBLIC_ENCRYPTION_KEY - # Build the application RUN npm run build -# Expose port -EXPOSE 3000 +# Create data directory for encrypted local storage +RUN mkdir -p /app/data && chmod 755 /app/data + +# Expose port 7654 (Capsule default port) +EXPOSE 7654 + +# Set production environment +ENV NODE_ENV=production # Start the application CMD ["npm", "start"] \ No newline at end of file diff --git a/README.md b/README.md index fb87d7d..0871b77 100644 --- a/README.md +++ b/README.md @@ -286,6 +286,30 @@ Date,Amount,Description,Category - Export to JSON format for data backup or integration - Includes complete transaction history and envelope details +## Deployment + +### ZimaOS Deployment (Recommended) + +Capsule is designed for self-hosted deployment on ZimaOS and similar platforms. + +**Quick Deploy:** +```bash +./deploy.sh +``` + +See [DEPLOYMENT.md](./DEPLOYMENT.md) for detailed ZimaOS deployment instructions. + +**Features:** +- Docker containerization for easy deployment +- Persistent data storage in `./data` directory +- Health checks and auto-restart +- Encrypted local storage (no cloud required) + +**Access:** +- Default port: 7654 +- Local: `http://localhost:7654` +- Network: `http://your-device-ip:7654` + ## Contributing 1. Fork the repository diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..9077392 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# Capsule Budget - ZimaOS Deployment Script + +set -e + +echo "๐Ÿš€ Deploying Capsule to ZimaOS..." +echo "" + +# Check if .env file exists +if [ ! -f .env ]; then + echo "โš ๏ธ .env file not found!" + echo "Creating .env from .env.example..." + cp .env.example .env + + # Generate a secure encryption key + ENCRYPTION_KEY=$(openssl rand -base64 32) + + # Update .env with generated key + if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS + sed -i '' "s/change-this-to-a-secure-random-key/$ENCRYPTION_KEY/" .env + else + # Linux + sed -i "s/change-this-to-a-secure-random-key/$ENCRYPTION_KEY/" .env + fi + + echo "โœ… Generated secure encryption key" + echo "" +fi + +# Clear test data +echo "๐Ÿงน Clearing test data..." +rm -rf data/* +echo "โœ… Test data cleared" +echo "" + +# Build and start containers +echo "๐Ÿ”จ Building Docker image..." +docker-compose build + +echo "" +echo "๐Ÿš€ Starting Capsule..." +docker-compose up -d + +echo "" +echo "โœ… Deployment complete!" +echo "" +echo "๐Ÿ“Š Capsule is running at:" +echo " http://localhost:7654" +echo " http://$(hostname -I | awk '{print $1}'):7654" +echo "" +echo "๐Ÿ”ง Useful commands:" +echo " docker-compose logs -f # View logs" +echo " docker-compose stop # Stop container" +echo " docker-compose restart # Restart container" +echo " docker-compose down # Stop and remove container" +echo "" +echo "๐Ÿ’พ Your data is stored in: ./data/" +echo "" diff --git a/docker-compose.yml b/docker-compose.yml index 610609d..95fdaa1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,15 +1,21 @@ version: '3.8' services: - budget-app: - image: ghcr.io/nmemmert/budget:dbaff55 + capsule: + build: . + container_name: capsule-budget ports: - - "3000:3000" + - "7654:7654" + volumes: + # Persist user data outside container + - ./data:/app/data environment: - NODE_ENV=production + # Generate a secure key: openssl rand -base64 32 + - ENCRYPTION_KEY=${ENCRYPTION_KEY:-change-this-to-a-secure-key} restart: unless-stopped healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:3000"] + test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:7654"] interval: 30s timeout: 10s retries: 3 diff --git a/package.json b/package.json index da12870..aaf84e9 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "next dev -p 7654", "build": "next build", - "start": "next start", + "start": "next start -p 7654", "lint": "eslint" }, "dependencies": {