diff --git a/DATA_DEPLOYMENT.md b/DATA_DEPLOYMENT.md new file mode 100644 index 0000000..561f97e --- /dev/null +++ b/DATA_DEPLOYMENT.md @@ -0,0 +1,75 @@ +# Data Folder Deployment Guide + +## Overview + +The `./data` folder is the **persistent data storage** for the DigiServer deployment. It is **NOT committed to the repository** but contains all necessary files copied from the repo during deployment. + +## Structure + +``` +data/ +├── app/ # Complete application code (copied from ./app) +├── Caddyfile # Reverse proxy configuration (copied from root) +├── instance/ # Flask instance folder (database, configs) +├── uploads/ # User file uploads +├── caddy-data/ # Caddy SSL certificates and cache +└── caddy-config/ # Caddy configuration data +``` + +## Deployment Process + +### Step 1: Initialize Data Folder + +Run this script to copy all necessary files from the repository to `./data`: + +```bash +./init-data.sh +``` + +This will: +- Create the `./data` directory structure +- Copy `./app` folder to `./data/app` +- Copy `Caddyfile` to `./data/Caddyfile` +- Set proper permissions for all files and folders + +### Step 2: Start Docker Containers + +```bash +docker-compose up -d --build +``` + +### Step 3: Run Migrations (First Time Only) + +```bash +sudo bash deploy.sh +``` + +## Important Notes + +- **./data is NOT in git**: The `./data` folder is listed in `.gitignore` and will not be committed +- **All persistent data here**: Database files, uploads, certificates, and configurations are stored in `./data` +- **Easy backups**: To backup the entire deployment, backup the `./data` folder +- **Easy troubleshooting**: Check the `./data` folder to verify all required files are present +- **Updates**: When you pull new changes, run `./init-data.sh` to update app files in `./data` + +## Deployment Checklist + +✓ All volumes in docker-compose.yml point to `./data` +✓ `./data` folder contains: app/, Caddyfile, instance/, uploads/, caddy-data/, caddy-config/ +✓ Files are copied from repository to `./data` via init-data.sh +✓ Permissions are correctly set for Docker container user + +## Verification + +Before starting: +```bash +ls -la data/ +# Should show: app/, Caddyfile, instance/, uploads/, caddy-data/, caddy-config/ +``` + +After deployment check data folder for: +```bash +data/instance/*.db # Database files +data/uploads/ # User uploads +data/caddy-data/*.pem # SSL certificates +``` diff --git a/Dockerfile b/Dockerfile index 51309f9..1c855f0 100755 --- a/Dockerfile +++ b/Dockerfile @@ -31,9 +31,6 @@ COPY . . COPY docker-entrypoint.sh /docker-entrypoint.sh RUN chmod +x /docker-entrypoint.sh -# Create directories for uploads and database -RUN mkdir -p app/static/uploads instance - # Set environment variables ENV FLASK_APP=app.app:create_app ENV PYTHONUNBUFFERED=1 diff --git a/docker-compose.yml b/docker-compose.yml index 29d6a50..2cf2076 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,9 +8,9 @@ services: expose: - "5000" volumes: - - ./instance:/app/instance - - ./app/static/uploads:/app/app/static/uploads - - ./Caddyfile:/app/Caddyfile + - ./data/app:/app + - ./data/instance:/app/instance + - ./data/uploads:/app/app/static/uploads environment: - FLASK_ENV=production - SECRET_KEY=${SECRET_KEY:-your-secret-key-change-this} @@ -36,9 +36,9 @@ services: - "443:443/udp" # HTTP/3 support - "2019:2019" # Caddy admin API volumes: - - ./Caddyfile:/etc/caddy/Caddyfile:ro - - caddy-data:/data - - caddy-config:/config + - ./data/Caddyfile:/etc/caddy/Caddyfile:ro + - ./data/caddy-data:/data + - ./data/caddy-config:/config environment: - DOMAIN=${DOMAIN:-localhost} - EMAIL=${EMAIL:-admin@localhost} @@ -52,7 +52,3 @@ services: networks: digiserver-network: driver: bridge - -volumes: - caddy-data: - caddy-config: diff --git a/init-data.sh b/init-data.sh new file mode 100755 index 0000000..77db50c --- /dev/null +++ b/init-data.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# Initialize ./data folder with all necessary files for deployment + +set -e + +echo "🔧 Initializing data folder..." +mkdir -p data/{app,instance,uploads,caddy-data,caddy-config} + +echo "📁 Copying app folder..." +rm -rf data/app +cp -r app data/ + +echo "📋 Copying Caddyfile..." +cp Caddyfile data/ + +echo "🔐 Setting permissions..." +chmod 755 data/{app,instance,uploads,caddy-data,caddy-config} +chmod 644 data/Caddyfile +chmod -R 755 data/app/ +find data/app -type f \( -name "*.py" -o -name "*.html" -o -name "*.css" -o -name "*.js" \) -exec chmod 644 {} \; +chmod 777 data/instance data/uploads + +echo "✅ Data folder initialized successfully!" +echo "📊 Data folder contents:" +du -sh data/*/