Files
PriceForge/bible-local/operations.md
Mikhail Chusavitin df5be91353 Improve performance on poor connections: local assets, gzip, caching
- Replace Tailwind CDN (~350KB) with purged local CSS (~22KB)
- Replace htmx unpkg CDN with local static file
- Add Gzip middleware (standard library, sync.Pool) for all responses
- Add Cache-Control: public, max-age=3600 for /static/* assets
- Reduce status polling interval from 5s to 30s
- Add scripts/build-css.sh for CSS regeneration after template changes
- Document in bible-local/operations.md and history.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-14 14:51:21 +03:00

206 lines
3.9 KiB
Markdown

# Operations
## Configuration (`config.yaml`)
```yaml
server:
host: "127.0.0.1" # loopback-only
port: 8084
mode: "release" # debug | release
read_timeout: "30s"
write_timeout: "30s"
database:
host: "localhost"
port: 3306
name: "RFQ_LOG"
user: "priceforge"
password: "CHANGE_ME"
max_open_conns: 25
max_idle_conns: 5
conn_max_lifetime: "5m"
pricing:
default_method: "weighted_median"
default_period_days: 90
freshness_green_days: 30
freshness_yellow_days: 60
freshness_red_days: 90
min_quotes_for_median: 3
export:
temp_dir: "/tmp/priceforge-exports"
max_file_age: "1h"
alerts:
enabled: true
check_interval: "1h"
high_demand_threshold: 5
logging:
level: "info" # debug | info | warn | error
format: "json" # json | text
```
---
## Quick Start
```bash
cp config.example.yaml config.yaml
# Edit config.yaml: database.host, database.name, database.user, database.password
make run
# Open: http://127.0.0.1:8084/admin/pricing
```
---
## Commands
```bash
# Run
make run
go run ./cmd/pfs
# Build
make build # dev build
make build-release # optimized, version via ldflags
make build-all # cross-compile Linux/macOS/Windows
# Migrations
go run ./cmd/pfs -migrate
make backup-db
# Version
./bin/pfs -version
# Tests
make test
# Clean
make clean
```
---
## Build System (Makefile)
| Target | Action |
|--------|--------|
| `run` | `go run ./cmd/pfs` |
| `backup-db` | Run `go run ./cmd/dbbackup` using current `config.yaml` |
| `build` | Dev build with debug info |
| `build-release` | `-s -w` stripped + version ldflags |
| `build-linux` | GOOS=linux GOARCH=amd64 |
| `build-macos` | GOOS=darwin GOARCH=arm64 |
| `build-windows` | GOOS=windows |
| `build-all` | All platforms |
| `release` | `./scripts/release.sh` |
| `test` | `go test -v ./...` |
| `clean` | Remove `bin/` |
| `deps` | `go mod download && go mod tidy` |
| `watch` | Auto-restart with `entr` |
**Build variables**:
- `CGO_ENABLED=0` — static binaries
- `VERSION` — from `git describe` or `"dev"`
- `LDFLAGS``-s -w -X main.Version=$(VERSION)`
---
## Release
```bash
./scripts/release.sh
# Creates: releases/<version>/ with archives and SHA256SUMS.txt
```
---
## Migrations
SQL migrations in `migrations/` (25 files). Applied automatically on startup.
Manual run: `go run ./cmd/pfs -migrate`
Before any migration or DB repair:
```bash
make backup-db
```
Backup helper:
```bash
go run ./cmd/dbbackup
# optional:
go run ./cmd/dbbackup --config /path/to/config.yaml --out-dir /path/to/backups
```
Default output path:
```text
<PriceForge state dir>/backups/
```
Example on macOS:
```text
~/Library/Application Support/PriceForge/backups/
```
Migration runner: `internal/models/sql_migrations.go`
---
## macOS Gatekeeper
After downloading the binary:
```bash
xattr -d com.apple.quarantine /path/to/pfs-darwin-arm64
```
---
## Frontend Assets (Tailwind CSS)
Static assets are embedded into the binary from `web/static/`. CSS and JS are served locally —
no external CDN requests at runtime.
### Regenerate Tailwind CSS
Run this after adding new Tailwind utility classes to any HTML template:
```bash
scripts/build-css.sh
# or directly:
node_modules/.bin/tailwindcss -i tw-input.css -o web/static/tailwind.min.css --minify
```
First-time setup (requires Node.js):
```bash
npm install
```
`node_modules/` is excluded from git. `web/static/tailwind.min.css` **is** committed —
rebuilding is only needed when templates change.
### Files involved
| File | Purpose |
|------|---------|
| `tailwind.config.js` | Content paths for class scanning |
| `tw-input.css` | Tailwind input (base/components/utilities directives) |
| `web/static/tailwind.min.css` | Generated output — committed, embedded into binary |
| `web/static/js/htmx.min.js` | htmx — committed, embedded into binary |
| `scripts/build-css.sh` | Shortcut to regenerate CSS |
---
## Requirements
- Go 1.22+
- MariaDB / MySQL (working database, e.g. `RFQ_LOG`)