diff --git a/Makefile b/Makefile index e797f7c..80541d8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all build test test-unit test-integration lint coverage clean install help docker-up docker-down docker-test docker-test-integration release release-version +.PHONY: all build test test-unit test-integration lint coverage clean install help docker-up docker-down docker-test docker-test-integration start stop release release-version # Binary name BINARY_NAME=relspec @@ -14,6 +14,26 @@ GOGET=$(GOCMD) get GOMOD=$(GOCMD) mod GOCLEAN=$(GOCMD) clean +# Auto-detect container runtime (Docker or Podman) +CONTAINER_RUNTIME := $(shell \ + if command -v podman > /dev/null 2>&1; then \ + echo "podman"; \ + elif command -v docker > /dev/null 2>&1; then \ + echo "docker"; \ + else \ + echo "none"; \ + fi) + +# Detect compose command +COMPOSE_CMD := $(shell \ + if [ "$(CONTAINER_RUNTIME)" = "podman" ]; then \ + echo "podman-compose"; \ + elif command -v docker-compose > /dev/null 2>&1; then \ + echo "docker-compose"; \ + else \ + echo "docker compose"; \ + fi) + all: lint test build ## Run linting, tests, and build build: ## Build the binary @@ -81,12 +101,26 @@ deps: ## Download dependencies $(GOMOD) tidy @echo "Dependencies updated" +start: docker-up ## Alias for docker-up (start PostgreSQL test database) + +stop: docker-down ## Alias for docker-down (stop PostgreSQL test database) + docker-up: ## Start PostgreSQL test database - @echo "Starting PostgreSQL test database..." - @if command -v docker-compose > /dev/null 2>&1; then \ - docker-compose up -d postgres; \ + @echo "Starting PostgreSQL test database (using $(CONTAINER_RUNTIME))..." + @if [ "$(CONTAINER_RUNTIME)" = "none" ]; then \ + echo "Error: Neither Docker nor Podman is installed"; \ + exit 1; \ + fi + @if [ "$(CONTAINER_RUNTIME)" = "podman" ]; then \ + podman run -d --name relspec-test-postgres \ + -e POSTGRES_USER=relspec \ + -e POSTGRES_PASSWORD=relspec_test_password \ + -e POSTGRES_DB=relspec_test \ + -p 5433:5432 \ + -v ./tests/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql:Z \ + postgres:16-alpine 2>/dev/null || echo "Container already running"; \ else \ - docker compose up -d postgres; \ + $(COMPOSE_CMD) up -d postgres; \ fi @echo "Waiting for PostgreSQL to be ready..." @sleep 3 @@ -94,16 +128,21 @@ docker-up: ## Start PostgreSQL test database @echo "Connection: postgres://relspec:relspec_test_password@localhost:5433/relspec_test" docker-down: ## Stop PostgreSQL test database - @echo "Stopping PostgreSQL test database..." - @if command -v docker-compose > /dev/null 2>&1; then \ - docker-compose down; \ + @echo "Stopping PostgreSQL test database (using $(CONTAINER_RUNTIME))..." + @if [ "$(CONTAINER_RUNTIME)" = "podman" ]; then \ + podman stop relspec-test-postgres 2>/dev/null || true; \ + podman rm relspec-test-postgres 2>/dev/null || true; \ else \ - docker compose down; \ + $(COMPOSE_CMD) down; \ fi @echo "PostgreSQL stopped" -docker-test: ## Run PostgreSQL integration tests with Docker - @./tests/postgres/run_tests.sh +docker-test: ## Run PostgreSQL integration tests with Docker/Podman + @if [ "$(CONTAINER_RUNTIME)" = "podman" ]; then \ + ./tests/postgres/run_tests_podman.sh; \ + else \ + ./tests/postgres/run_tests.sh; \ + fi docker-test-integration: docker-up ## Start DB and run integration tests @echo "Running integration tests..."