# Task 003: VPS Deployment Preparation (Apache + Systemd) Prepare the application for deployment on a VPS using Apache2 as a reverse proxy and Systemd for process management. ## Target Environment - **OS:** Linux (VPS) - **Web Server:** Apache2 - **Process Manager:** Systemd - **Directory Structure:** - Root: `/site/{fqdn}/` - Binary: `/site/{fqdn}/app` - Data: `/site/{fqdn}/data/` (Database location) - Webroot: `/site/{fqdn}/public/` (Static assets) ## Plan ### 1. Configuration Updates - Ensure the application can accept configuration via Environment Variables for: - `PORT` (Default: 8080) - `DB_PATH` (Default: `./task.db`, Target: `/site/{fqdn}/data/dashboard.db`) - `SESSION_KEY` (Secret) - `STATIC_DIR` (Optional: if we want to point to `public` explicitly) ### 2. Create Deployment Artifacts Create a `deployment/` directory containing: #### A. Systemd Unit File (`deployment/task-dashboard.service`) - **Description:** Manages the Go application process. - **Key Settings:** - `ExecStart=/site/{fqdn}/app` - `WorkingDirectory=/site/{fqdn}/` - `User=www-data` (or specific user) - `Restart=always` - `EnvironmentFile=/site/{fqdn}/.env` (or inline env vars) #### B. Apache VHost Configuration (`deployment/apache.conf`) - **Description:** Reverse proxy configuration. - **Key Settings:** - Based on provided template. - `DocumentRoot /site/{fqdn}/public` - `ProxyPass / http://localhost:8080/` - `ProxyPassReverse / http://localhost:8080/` - Serve static assets directly via Apache for performance (optional but recommended). ### 3. Documentation - Create `docs/deployment.md` with instructions: 1. **Build:** `go build -o app cmd/dashboard/main.go` 2. **Setup:** - `mkdir -p /site/{fqdn}/{data,public}` - Copy `app` to `/site/{fqdn}/` - Copy `web/static` content to `/site/{fqdn}/public/` - Copy `web/templates` to `/site/{fqdn}/templates` (or ensure app can find them) 3. **Service:** Install and enable systemd service. 4. **Apache:** Enable site and modules (`proxy`, `proxy_http`). ## Considerations - **Static Files:** We should decide if Apache serves `/static` directly from `/site/{fqdn}/public` or if the Go app handles it. Serving via Apache is preferred for performance. - **Templates:** The Go app needs access to HTML templates. We need to ensure the `WorkingDirectory` allows relative path resolution to `web/templates` or configure an absolute path.