Restructure the container setup to support registry-based deployment:
the default docker-compose.yml now pulls a prebuilt app image from the
Gitea container registry instead of building locally, while a new
docker-compose.dev.yml override preserves the local build + integration
test workflow for development.
Why:
- Production and self-hosting should consume a published image, not
rebuild from source on the host. The default `docker compose up` now
pulls the app image (git.linuxhg.com/bookhoard/bookhoard) alongside the
public postgres image, with no build step required.
- Development still needs to build from source and run integration
tests, so those concerns move to an override file the Makefile applies.
Shared config (env, volumes, ports, healthchecks) lives in one place to
avoid drift between environments.
Changes:
- docker-compose.yml (prod base): the app service now references
`image: git.linuxhg.com/bookhoard/bookhoard:${IMAGE_TAG:-latest}` instead
of a build context. The tests service is removed (moved to the
override). IMAGE_TAG lets deployers pin or roll back a specific version.
- docker-compose.dev.yml (new override): adds the local `build:` context
for the app and defines the integration `tests` service (profile-gated).
Everything else is inherited from the base file via compose merging.
- Makefile: introduce a COMPOSE variable that merges the base and
override (`-f docker-compose.yml -f docker-compose.dev.yml`); all dev
targets now use it. Plain `docker compose` against the base file only
remains the production path.
- README: quickstart updated to pull and start prebuilt images; clone URL
points at the Gitea instance.
The development workflow (`make rebuild-app`, `make test-integration`,
etc.) is functionally unchanged.
161 lines
5.9 KiB
Makefile
161 lines
5.9 KiB
Makefile
.PHONY: help test test-integration test-all rebuild rebuild-force rebuild-app rebuild-app-force rebuild-force-db clean 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
|
|
|
|
# Auto-detect container runtime: prefer docker, fall back to podman
|
|
# Override with: CONTAINER_RUNTIME=podman make rebuild-app
|
|
CONTAINER_RUNTIME ?= $(shell command -v docker 2>/dev/null || command -v podman 2>/dev/null)
|
|
|
|
# Dev compose stack: base prod file merged with the dev override (local build + tests).
|
|
# Prod deploy does NOT use this — it runs plain `docker compose` against the base file only.
|
|
COMPOSE := $(CONTAINER_RUNTIME) compose -f docker-compose.yml -f docker-compose.dev.yml
|
|
|
|
# Default target
|
|
help:
|
|
@echo "Available targets:"
|
|
@echo ""
|
|
@echo "Development:"
|
|
@echo " make up - Start containers (if already built)"
|
|
@echo " make rebuild - Rebuild all containers (database preserved)"
|
|
@echo " make rebuild-force - Rebuild all containers, no cache (database preserved)"
|
|
@echo " make rebuild-app - Rebuild app container only (fast, database preserved)"
|
|
@echo " make rebuild-app-force - Rebuild app container only, no cache (database preserved)"
|
|
@echo " make rebuild-force-db - Rebuild all containers, no cache (DELETES database)"
|
|
@echo " make restart - Restart app container (preserves db)"
|
|
@echo " make down - Stop all containers (preserves volumes)"
|
|
@echo " make clean - Stop and remove all containers and volumes"
|
|
@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..."
|
|
$(COMPOSE) --profile tests build
|
|
@echo "Starting application containers..."
|
|
$(COMPOSE) up -d db app
|
|
@echo "Waiting for services to be healthy..."
|
|
@until $(CONTAINER_RUNTIME) 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 $(CONTAINER_RUNTIME) 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..."
|
|
$(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
|
|
|
|
# Rebuild app container only (preserve DB, with cache)
|
|
rebuild-app:
|
|
@echo "Rebuilding app container (database stays running)..."
|
|
$(COMPOSE) up --build --force-recreate -d app
|
|
@echo "✓ App container rebuilt and restarted"
|
|
|
|
# Rebuild app container only (preserve DB, no cache)
|
|
rebuild-app-force:
|
|
@echo "Force rebuilding app container (database stays running, no cache)..."
|
|
$(COMPOSE) build --no-cache app
|
|
$(COMPOSE) up --force-recreate -d app
|
|
@echo "✓ App container rebuilt and restarted"
|
|
|
|
# Rebuild all containers (preserve DB, with cache)
|
|
rebuild:
|
|
@echo "Rebuilding all containers (database preserved)..."
|
|
$(COMPOSE) up --build --force-recreate -d
|
|
@echo "✓ All containers rebuilt and restarted"
|
|
|
|
# Rebuild all containers (preserve DB, no cache)
|
|
rebuild-force:
|
|
@echo "Force rebuilding all containers (database preserved, no cache)..."
|
|
$(COMPOSE) build --no-cache
|
|
$(COMPOSE) up --force-recreate -d
|
|
@echo "✓ All containers rebuilt and restarted"
|
|
|
|
# Rebuild all containers (remove DB, no cache)
|
|
rebuild-force-db:
|
|
@echo "Force rebuilding all containers (database will be DELETED, no cache)..."
|
|
$(COMPOSE) down -v
|
|
$(COMPOSE) build --no-cache
|
|
$(COMPOSE) up --force-recreate -d
|
|
@echo "✓ All containers rebuilt and restarted"
|
|
|
|
# Stop and remove containers
|
|
clean:
|
|
$(COMPOSE) down -v
|
|
|
|
# Quick start (if already built)
|
|
up:
|
|
$(COMPOSE) up -d
|
|
|
|
# Stop all containers (alias for clean)
|
|
down:
|
|
$(COMPOSE) down
|
|
|
|
# Restart app container (preserves database)
|
|
restart:
|
|
@echo "Restarting app container (database stays running)..."
|
|
$(COMPOSE) restart app
|
|
@echo "✓ App container restarted"
|
|
|
|
# Show container status
|
|
ps:
|
|
$(COMPOSE) ps
|
|
|
|
# Show container logs
|
|
logs:
|
|
$(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 $(COMPOSE) up --build --force-recreate -d
|
|
@echo "Waiting for services to be ready..."
|
|
@until $(CONTAINER_RUNTIME) exec bookhoard_db pg_isready -U postgres > /dev/null 2>&1; do sleep 1; done
|
|
@until $(CONTAINER_RUNTIME) 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:
|
|
$(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
|