-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathMakefile
155 lines (138 loc) · 4.36 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# Simplified Makefile for Simba Docker Build and Deployment
# Variables with sensible defaults
DEVICE ?= auto
PLATFORM ?= auto
IMAGE_NAME ?= simba
IMAGE_TAG ?= latest
# Auto-detect device type
ifeq ($(DEVICE),auto)
ifeq ($(shell uname -m),arm64)
ifeq ($(shell uname -s),Darwin)
DEVICE := cpu
else
DEVICE := cpu
endif
else
ifneq ($(shell which nvidia-smi 2>/dev/null),)
DEVICE := cuda
else
DEVICE := cpu
endif
endif
endif
# Auto-detect platform
ifeq ($(PLATFORM),auto)
ifeq ($(shell uname -m),arm64)
DOCKER_PLATFORM := linux/arm64
else
DOCKER_PLATFORM := linux/amd64
endif
else ifeq ($(PLATFORM),arm64)
DOCKER_PLATFORM := linux/arm64
else ifeq ($(PLATFORM),amd64)
DOCKER_PLATFORM := linux/amd64
else
$(error Invalid PLATFORM. Must be one of: auto, arm64, amd64)
endif
# Set device-specific options
ifeq ($(DEVICE),cuda)
USE_GPU := true
RUNTIME := nvidia
ifeq ($(DOCKER_PLATFORM),linux/arm64)
$(error CUDA device is not supported on ARM architecture)
endif
else ifeq ($(DEVICE),mps)
# Show warning for MPS
$(warning MPS device requested but Docker containers cannot access Metal framework on macOS. Setting to CPU mode.)
DEVICE := cpu
USE_GPU := false
RUNTIME :=
else
USE_GPU := false
RUNTIME :=
endif
# Derived variables
FULL_IMAGE_NAME = $(IMAGE_NAME):$(IMAGE_TAG)
# Free up Docker storage before building
docker-prune:
@echo "Cleaning Docker resources to free up storage..."
@docker system prune -f
@docker builder prune -f
# Simple network setup
setup-network:
@echo "Setting up Docker network..."
@docker network inspect simba_network >/dev/null 2>&1 || docker network create simba_network
# Setup Buildx builder
setup-builder:
@echo "Setting up Buildx builder..."
@docker buildx rm simba-builder 2>/dev/null || true
@docker buildx create --name simba-builder \
--driver docker-container \
--driver-opt "image=moby/buildkit:buildx-stable-1" \
--driver-opt "network=host" \
--buildkitd-flags '--allow-insecure-entitlement security.insecure' \
--bootstrap --use
# Build image
build: docker-prune setup-network setup-builder
@echo "Building Docker image..."
@docker buildx build --builder simba-builder \
--platform ${DOCKER_PLATFORM} \
--build-arg USE_GPU=${USE_GPU} \
--build-arg TARGETARCH=${TARGETARCH} \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--progress=plain \
--no-cache \
-t ${IMAGE_NAME}:${IMAGE_TAG} \
-f docker/Dockerfile \
--load \
.
# Updated up command with proper profile handling
up: setup-network
@echo "Starting containers..."
@if [ "${DEVICE}" = "cuda" ]; then \
echo "Detected CUDA device - enabling GPU and Ollama"; \
DEVICE=cuda RUNTIME=nvidia RUN_OLLAMA=ollama docker compose -f docker/docker-compose.yml up -d; \
elif [ "${ENABLE_OLLAMA}" = "true" ]; then \
echo "Enabling Ollama without GPU"; \
DEVICE=${DEVICE} RUNTIME="" RUN_OLLAMA=ollama docker compose -f docker/docker-compose.yml up -d; \
else \
echo "Running without Ollama"; \
DEVICE=${DEVICE} RUNTIME="" RUN_OLLAMA=none docker compose -f docker/docker-compose.yml up -d; \
fi
@echo "Containers started successfully!"
# Down command - keep this part
down:
@echo "Stopping containers..."
@docker compose -f docker/docker-compose.yml down
@echo "Containers stopped."
# Restart command - keep this part
restart: down up
# Clean everything
clean: down
@echo "Cleaning Docker resources..."
@docker network rm simba_network 2>/dev/null || true
@docker volume rm docker_redis_data docker_ollama_models 2>/dev/null || true
@docker system prune -af --volumes
@echo "Cleanup complete!"
# Show logs
logs:
@docker compose -f docker/docker-compose.yml logs -f
# One-step build and run
run: build up
# Show help
help:
@echo "Simba Docker Commands:"
@echo " make build - Build Docker image"
@echo " make up - Start containers"
@echo " make down - Stop containers"
@echo " make restart - Restart all containers"
@echo " make clean - Clean up Docker resources"
@echo " make logs - View logs"
@echo ""
@echo "Options:"
@echo " DEVICE=cpu|cuda|auto (current: $(DEVICE))"
@echo " PLATFORM=amd64|arm64|auto (current: $(PLATFORM))"
@echo " Current platform: $(DOCKER_PLATFORM)"
@echo ""
@echo "Note: MPS (Metal Performance Shaders) is not supported in Docker containers."
.PHONY: setup-network setup-builder build up down restart clean logs run help ollama-enable ollama-disable docker-prune