Files
silo/Makefile
forbes f5b03989ff feat(storage): add MinIO to filesystem migration tool
Standalone binary (cmd/migrate-storage) that downloads all files from
MinIO and writes them to the local filesystem for decommissioning MinIO.

Queries revision files, item file attachments, and item thumbnails from
the database, then downloads each from MinIO preserving the object key
structure as filesystem paths. Supports --dry-run, --verbose, atomic
writes via temp+rename, and idempotent re-runs (skips existing files
with matching size).
2026-02-18 14:12:32 -06:00

198 lines
5.8 KiB
Makefile

.PHONY: build run test test-integration clean migrate fmt lint \
docker-build docker-up docker-down docker-logs docker-ps \
docker-clean docker-rebuild \
web-install web-dev web-build \
migrate-storage
# =============================================================================
# Local Development
# =============================================================================
# Build all binaries (frontend + backend)
build: web-build
go build -o silo ./cmd/silo
go build -o silod ./cmd/silod
# Run the API server locally
run:
go run ./cmd/silod -config config.yaml
# Run the CLI
cli:
go run ./cmd/silo $(ARGS)
# Run unit tests (integration tests skipped without TEST_DATABASE_URL)
test:
go test -v ./...
# Run all tests including integration tests (requires PostgreSQL)
test-integration:
TEST_DATABASE_URL="postgres://silo:silodev@localhost:5432/silo_test?sslmode=disable" go test -v -count=1 ./...
# Clean build artifacts
clean:
rm -f silo silod
rm -f *.out
rm -rf web/dist
# Format code
fmt:
go fmt ./...
goimports -w .
# Lint code
lint:
golangci-lint run
# Tidy dependencies
tidy:
go mod tidy
# =============================================================================
# Database
# =============================================================================
# Run database migrations (requires SILO_DB_* environment variables)
migrate:
./scripts/init-db.sh
# Build and run MinIO → filesystem migration tool
# Usage: make migrate-storage DEST=/opt/silo/data [ARGS="--dry-run --verbose"]
migrate-storage:
go build -o migrate-storage ./cmd/migrate-storage
@echo "Built ./migrate-storage"
@echo "Run: ./migrate-storage -config <config.yaml> -dest <dir> [-dry-run] [-verbose]"
# Connect to database (requires psql)
db-shell:
PGPASSWORD=$${SILO_DB_PASSWORD:-silodev} psql -h $${SILO_DB_HOST:-localhost} -U $${SILO_DB_USER:-silo} -d $${SILO_DB_NAME:-silo}
# =============================================================================
# Docker
# =============================================================================
# Build Docker image
docker-build:
docker build -t silo:latest -f build/package/Dockerfile .
# Start the full stack (postgres + minio + silo)
docker-up:
docker compose -f deployments/docker-compose.yaml up -d
# Start with rebuild
docker-up-build:
docker compose -f deployments/docker-compose.yaml up -d --build
# Stop the stack
docker-down:
docker compose -f deployments/docker-compose.yaml down
# Stop and remove volumes (WARNING: deletes data)
docker-clean:
docker compose -f deployments/docker-compose.yaml down -v
# View logs
docker-logs:
docker compose -f deployments/docker-compose.yaml logs -f
# View logs for specific service
docker-logs-silo:
docker compose -f deployments/docker-compose.yaml logs -f silo
docker-logs-postgres:
docker compose -f deployments/docker-compose.yaml logs -f postgres
docker-logs-minio:
docker compose -f deployments/docker-compose.yaml logs -f minio
# Show running containers
docker-ps:
docker compose -f deployments/docker-compose.yaml ps
# Rebuild and restart
docker-rebuild: docker-down docker-build docker-up
# Shell into silo container
docker-shell:
docker compose -f deployments/docker-compose.yaml exec silo /bin/sh
# =============================================================================
# API Testing
# =============================================================================
# Test health endpoint
api-health:
curl -s http://localhost:8080/health | jq .
# Test ready endpoint
api-ready:
curl -s http://localhost:8080/ready | jq .
# List schemas
api-schemas:
curl -s http://localhost:8080/api/schemas | jq .
# List items
api-items:
curl -s http://localhost:8080/api/items | jq .
# Create sample item
api-create-item:
curl -s -X POST http://localhost:8080/api/items \
-H "Content-Type: application/json" \
-d '{"schema":"kindred-rd","project":"CS100","category":"F01","material":"316","description":"Test screw"}' | jq .
# =============================================================================
# Web Frontend
# =============================================================================
web-install:
cd web && npm ci
web-dev:
cd web && npm run dev
web-build:
cd web && npm run build
# =============================================================================
# Help
# =============================================================================
help:
@echo "Silo Makefile targets:"
@echo ""
@echo "Local Development:"
@echo " build - Build CLI and server binaries"
@echo " run - Run API server locally"
@echo " cli ARGS=... - Run CLI with arguments"
@echo " test - Run unit tests (integration tests skip without DB)"
@echo " test-integration - Run all tests including integration (needs PostgreSQL)"
@echo " fmt - Format code"
@echo " lint - Run linter"
@echo " tidy - Tidy go.mod"
@echo ""
@echo "Docker:"
@echo " docker-build - Build Docker image"
@echo " docker-up - Start full stack (postgres + minio + silo)"
@echo " docker-down - Stop the stack"
@echo " docker-clean - Stop and remove volumes (deletes data)"
@echo " docker-logs - View all logs"
@echo " docker-ps - Show running containers"
@echo " docker-rebuild - Rebuild and restart"
@echo ""
@echo "Database:"
@echo " migrate - Run database migrations"
@echo " db-shell - Connect to database with psql"
@echo ""
@echo "API Testing:"
@echo " api-health - Test health endpoint"
@echo " api-schemas - List schemas"
@echo " api-items - List items"
@echo " api-create-item - Create a test item"
@echo ""
@echo "Web Frontend:"
@echo " web-install - Install npm dependencies"
@echo " web-dev - Start Vite dev server"
@echo " web-build - Build production bundle"