Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 118 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# JAN SERVER MAKEFILE
# ============================================================================================================
#
# A comprehensive build system for Jan Server - a microservices-based LLM API
# A comprehensive build system for Jan Server - a microservices-based LLM API
# with MCP (Model Context Protocol) tool integration.
#
# ============================================================================================================
Expand Down Expand Up @@ -49,14 +49,44 @@
# VARIABLES
# ============================================================================================================

# Docker Compose
COMPOSE = docker compose
COMPOSE_DEV_FULL = docker compose -f docker-compose.yml -f docker-compose.dev-full.yml
MONITOR_COMPOSE = docker compose -f infra/docker/observability.yml
# Container Engine Detection (docker or podman)
# Override with: make CONTAINER_ENGINE=podman <target>
CONTAINER_ENGINE ?= auto

ifeq ($(CONTAINER_ENGINE),auto)
# Auto-detect: prefer docker, fallback to podman
ifneq ($(shell command -v docker 2>/dev/null),)
DETECTED_ENGINE := docker
else ifneq ($(shell command -v podman 2>/dev/null),)
DETECTED_ENGINE := podman
else
DETECTED_ENGINE := docker
endif
else
DETECTED_ENGINE := $(CONTAINER_ENGINE)
endif

# Set compose command based on detected engine
ifeq ($(DETECTED_ENGINE),podman)
# Podman: use podman-compose with flattened compose file
# Generate with: python3 scripts/gen-podman-compose.py
PODMAN_COMPOSE_FILE ?= docker-compose.podman.yml
COMPOSE = podman-compose -f $(PODMAN_COMPOSE_FILE)
COMPOSE_DEV_FULL = podman-compose -f $(PODMAN_COMPOSE_FILE)
MONITOR_COMPOSE = podman-compose -f infra/docker/observability.yml
# Podman doesn't use BuildKit
DOCKER_BUILDKIT ?= 0
COMPOSE_DOCKER_CLI_BUILD ?= 0
else
# Docker: use docker compose v2
COMPOSE = docker compose
COMPOSE_DEV_FULL = docker compose -f docker-compose.yml -f docker-compose.dev-full.yml
MONITOR_COMPOSE = docker compose -f infra/docker/observability.yml
# BuildKit is required for additional_contexts in compose builds.
DOCKER_BUILDKIT ?= 1
COMPOSE_DOCKER_CLI_BUILD ?= 1
endif

# BuildKit is required for additional_contexts in compose builds.
DOCKER_BUILDKIT ?= 1
COMPOSE_DOCKER_CLI_BUILD ?= 1
export DOCKER_BUILDKIT COMPOSE_DOCKER_CLI_BUILD

MEDIA_SERVICE_KEY ?= changeme-media-key
Expand Down Expand Up @@ -975,6 +1005,86 @@ else
@curl -sf http://localhost:3010 >/dev/null && echo " SandboxFusion: healthy" || echo " SandboxFusion: unhealthy"
endif

# ============================================================================================================
# SECTION 10: PODMAN SUPPORT
# ============================================================================================================

.PHONY: engine-info podman-setup podman-network podman-ps podman-clean

## Show which container engine is being used
engine-info:
@echo "Container Engine Configuration"
@echo "=============================="
@echo "CONTAINER_ENGINE: $(CONTAINER_ENGINE)"
@echo "DETECTED_ENGINE: $(DETECTED_ENGINE)"
@echo "COMPOSE command: $(COMPOSE)"
@echo ""
ifeq ($(DETECTED_ENGINE),podman)
@podman --version
@podman-compose --version
@echo ""
@echo "Podman info:"
@podman info --format 'Rootless: {{.Host.Security.Rootless}}'
else
@docker --version
@docker compose version
endif

## Setup Podman environment (create networks, generate compose file)
podman-setup: podman-compose-generate podman-network
ifeq ($(DETECTED_ENGINE),podman)
@echo ""
@echo "Podman setup complete!"
@echo ""
@echo "To start services:"
@echo " make up-full"
@echo ""
@echo "Or explicitly use Podman:"
@echo " make CONTAINER_ENGINE=podman up-full"
else
@echo "Docker detected. For Podman, run:"
@echo " make CONTAINER_ENGINE=podman podman-setup"
endif

## Generate flattened compose file for podman-compose
podman-compose-generate:
@echo "Generating Podman-compatible compose file..."
@python3 scripts/gen-podman-compose.py
@echo ""

## Create required Podman networks
podman-network:
@echo "Creating container networks..."
ifeq ($(DETECTED_ENGINE),podman)
@podman network exists jan-server_default 2>/dev/null || podman network create jan-server_default
@podman network exists jan-server_mcp-network 2>/dev/null || podman network create jan-server_mcp-network
else
@docker network inspect jan-server_default >/dev/null 2>&1 || docker network create jan-server_default
@docker network inspect jan-server_mcp-network >/dev/null 2>&1 || docker network create jan-server_mcp-network
endif
@echo "Networks ready"

## List Jan Server containers (works with both Docker and Podman)
podman-ps:
ifeq ($(DETECTED_ENGINE),podman)
@podman ps --filter "label=com.docker.compose.project=server" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
else
@docker ps --filter "label=com.docker.compose.project=server" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
endif

## Clean up container resources
podman-clean:
@echo "Cleaning up Jan Server container resources..."
$(COMPOSE) down -v --remove-orphans 2>/dev/null || true
ifeq ($(DETECTED_ENGINE),podman)
@podman volume prune -f
@podman network prune -f
else
@docker volume prune -f
@docker network prune -f
endif
@echo "Cleanup complete"

# ============================================================================================================
# END OF MAKEFILE
# ============================================================================================================
127 changes: 127 additions & 0 deletions Makefile.podman
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# ============================================================================================================
# JAN SERVER - PODMAN OVERRIDE MAKEFILE
# ============================================================================================================
#
# This file provides Podman-specific overrides for Jan Server.
# Include this in your main Makefile or use it directly.
#
# Usage:
# make -f Makefile.podman up-full # Use Podman directly
# make CONTAINER_ENGINE=podman up-full # Override in main Makefile
#
# Requirements:
# - Podman 4.0+ (you have 5.7.1)
# - podman-compose 1.0.6+ (you have 1.5.0)
#
# ============================================================================================================

# Container Engine Detection
# Supports: docker, podman, auto (detect)
CONTAINER_ENGINE ?= podman

# Podman-specific compose command
# podman-compose is more compatible than 'podman compose' for complex setups
COMPOSE = podman-compose
COMPOSE_DEV_FULL = podman-compose -f docker-compose.yml -f docker-compose.dev-full.yml
MONITOR_COMPOSE = podman-compose -f infra/docker/observability.yml

# Podman doesn't use BuildKit, but these are harmless
DOCKER_BUILDKIT ?= 0
COMPOSE_DOCKER_CLI_BUILD ?= 0

# Podman rootless networking
# For host.docker.internal equivalent in rootless Podman
PODMAN_HOST_GATEWAY ?= host.containers.internal

# ============================================================================================================
# PODMAN-SPECIFIC TARGETS
# ============================================================================================================

.PHONY: podman-setup podman-check podman-socket podman-network

## Setup Podman environment for Jan Server
podman-setup: podman-check podman-network
@echo "Podman environment ready for Jan Server"
@echo ""
@echo "Quick start:"
@echo " make -f Makefile.podman up-full"
@echo ""
@echo "Or set in your shell:"
@echo " export CONTAINER_ENGINE=podman"
@echo " make up-full"

## Check Podman installation and version
podman-check:
@echo "Checking Podman installation..."
@podman --version || (echo "ERROR: Podman not found" && exit 1)
@podman-compose --version || (echo "ERROR: podman-compose not found" && exit 1)
@echo ""
@echo "Podman info:"
@podman info --format '{{.Host.OS}} / {{.Host.Arch}} / cgroups {{.Host.CgroupsVersion}}'
@echo ""
@echo "Rootless mode: $$(podman info --format '{{.Host.Security.Rootless}}')"

## Enable Podman socket for Docker API compatibility (optional)
podman-socket:
@echo "Enabling Podman socket..."
systemctl --user enable --now podman.socket
@echo ""
@echo "Socket path: $${XDG_RUNTIME_DIR}/podman/podman.sock"
@echo ""
@echo "To use with Docker CLI:"
@echo " export DOCKER_HOST=unix://$${XDG_RUNTIME_DIR}/podman/podman.sock"

## Create required networks for Jan Server
podman-network:
@echo "Creating Podman networks..."
@podman network exists jan-server_default 2>/dev/null || podman network create jan-server_default
@podman network exists jan-server_mcp-network 2>/dev/null || podman network create jan-server_mcp-network
@echo "Networks ready"

## List Jan Server containers
podman-ps:
@podman ps --filter "label=com.docker.compose.project=jan-server" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"

## Show Podman resource usage
podman-stats:
@podman stats --no-stream --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}"

## Clean up Podman resources
podman-clean:
@echo "Cleaning up Jan Server Podman resources..."
$(COMPOSE) down -v --remove-orphans 2>/dev/null || true
@podman volume prune -f
@podman network prune -f
@echo "Cleanup complete"

## Fix common Podman issues
podman-fix:
@echo "Applying common Podman fixes..."
@echo ""
@echo "1. Resetting Podman storage (if corrupted)..."
@echo " Run manually if needed: podman system reset"
@echo ""
@echo "2. Checking cgroup configuration..."
@if [ -f /sys/fs/cgroup/cgroup.controllers ]; then \
echo " cgroups v2 detected (good)"; \
else \
echo " cgroups v1 detected - consider upgrading"; \
fi
@echo ""
@echo "3. Checking user namespaces..."
@cat /proc/sys/user/max_user_namespaces 2>/dev/null || echo " Cannot read max_user_namespaces"

# ============================================================================================================
# OVERRIDE MAIN MAKEFILE TARGETS
# ============================================================================================================

# Include the main Makefile targets but with Podman compose
include Makefile

# Override check-deps for Podman
check-deps:
@echo "Checking Podman dependencies..."
@podman --version >/dev/null 2>&1 || echo "Podman not found"
@podman-compose --version >/dev/null 2>&1 || echo "podman-compose not found"
@go version >/dev/null 2>&1 || echo "Go not found (optional)"
@echo "Dependency check complete"
Loading