Files
bookhoard/Makefile
T
john-okeefe cb04dbb542 fix(devops): force container recreation on rebuild to ensure template changes appear
Add --force-recreate flag to all build targets that create containers:
- build: Force recreation when building all containers
- rebuild-app: Force recreation of app container only (fixes template update issue)
- build-force: Force recreation even when using --no-cache
- test-env-up: Force recreation in test environment

This fixes a critical issue where 'make rebuild-app' would build a new image
but continue running the old container, causing template changes to not appear.

Root cause: podman-compose up --build doesn't recreate containers if they're
already running, even when a new image is built. The --force-recreate flag
ensures containers are recreated with the new image.

BuildKit caching still works as expected - cache is used during image build,
while --force-recreate ensures the new image is actually deployed.

Changes:
- build: Add --force-recreate flag
- rebuild-app: Add --force-recreate flag, update success message
- build-force: Add --force-recreate flag
- test-env-up: Add --force-recreate flag

Verified: Template changes now appear immediately after rebuild.
2026-02-22 19:48:36 -05:00

135 lines
4.5 KiB
Makefile

.PHONY: help test test-integration test-all build build-force clean rebuild rebuild-app restart up down logs ps test-env-up test-env-down verify-guidelines verify-quick
# Include .env file for environment variables (single source of truth)
# Ignore if .env doesn't exist yet
ifneq (,$(wildcard ./.env))
include .env
export
endif
# Default target
help:
@echo "Available targets:"
@echo ""
@echo "Development:"
@echo " make up - Start containers (if already built)"
@echo " make build - Build and start all containers"
@echo " make rebuild-app - Rebuild app container only (fast, for development)"
@echo " make restart - Restart app container (preserves db)"
@echo " make down - Stop all containers"
@echo " make rebuild - Clean, rebuild, and start all containers"
@echo " make build-force - Force rebuild without cache (slow, use if needed)"
@echo ""
@echo "Status & Logs:"
@echo " make ps - Show container status"
@echo " make logs - Show container logs (follow mode)"
@echo ""
@echo "Testing:"
@echo " make test - Run unit tests (from host, fast)"
@echo " make test-integration - Run integration tests (in containers, matches prod)"
@echo " make test-all - Run all tests (unit + integration)"
@echo " make test-env-up - Start containers with test mode enabled"
@echo " make test-env-down - Stop test environment"
@echo ""
@echo "Verification:"
@echo " make verify-guidelines - Run comprehensive guidelines check"
@echo " make verify-quick - Run quick guidelines check"
# Run unit tests locally (fast, no containers)
test:
go test ./internal/... -v -short
# Run integration tests in containers (matches production environment)
test-integration:
@echo "Building test containers..."
podman compose --profile tests build
@echo "Starting application containers..."
podman compose up -d db app
@echo "Waiting for services to be healthy..."
@until podman exec bookhoard_db pg_isready -U postgres > /dev/null 2>&1; do \
echo " Database not ready yet..."; \
sleep 2; \
done; \
echo " ✓ Database is ready"
@until podman exec bookhoard curl -sf http://localhost:8765/health > /dev/null 2>&1; do \
echo " Application not ready yet..."; \
sleep 2; \
done; \
echo " ✓ Application is ready"
@echo ""
@echo "Running integration tests in container..."
podman compose --profile tests run --rm tests
@echo ""
@echo "✅ Integration tests completed!"
@echo "📝 Containers are still running. Use 'make logs' to view logs or 'make clean' to stop."
# Run all tests
test-all: test test-integration
# Build and start containers
build:
podman compose up --build --force-recreate -d
# Force rebuild without cache (slow, use if needed)
build-force:
podman compose build --no-cache
podman compose up --force-recreate -d
# Stop and remove containers
clean:
podman compose down -v
# Clean rebuild (remove volumes, rebuild, start)
rebuild: clean build
# Quick start (if already built)
up:
podman compose up -d
# Stop all containers (alias for clean)
down:
podman compose down
# Rebuild app container only (fast, for development)
rebuild-app:
@echo "Rebuilding app container only (database stays running)..."
podman compose up --build --force-recreate -d app
@echo "✓ App container rebuilt and restarted"
# Restart app container (preserves database)
restart:
@echo "Restarting app container (database stays running)..."
podman compose restart app
@echo "✓ App container restarted"
# Show container status
ps:
podman compose ps
# Show container logs
logs:
podman compose logs -f
# Start containers with test mode enabled for manual testing
test-env-up:
@echo "Starting containers with test mode enabled..."
TEST_MODE=true RATE_LIMIT_ENABLED=false REQUESTS_PER_MINUTE=1000 podman compose up --build --force-recreate -d
@echo "Waiting for services to be ready..."
@until podman exec bookhoard_db pg_isready -U postgres > /dev/null 2>&1; do sleep 1; done
@until podman exec bookhoard curl -sf http://localhost:8765/health > /dev/null 2>&1; do sleep 1; done
@echo "✓ Test environment is ready!"
@echo "Application available at http://localhost:8765"
# Stop test environment
test-env-down:
podman compose down -v
# Verify project guidelines compliance
verify-guidelines:
@echo "Running comprehensive project guidelines verification..."
@./scripts/verify-guidelines.sh
verify-quick:
@echo "Running quick project guidelines verification..."
@./scripts/verify-quick.sh