-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathMakefile
More file actions
40 lines (32 loc) · 1.04 KB
/
Copy pathMakefile
File metadata and controls
40 lines (32 loc) · 1.04 KB
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
PORT ?= 8080
IMAGE_NAME := python-server:latest
CONTAINER_NAME := python-server
.PHONY: run test build docker-build docker-run stop clean
run:
python3 server.py
test:
@echo "Starting server on port $(PORT)..."
@( \
set -e; \
python3 server.py & SERVER_PID=$$!; \
trap "kill -9 $$SERVER_PID 2>/dev/null || true" EXIT; \
sleep 1; \
echo "Testing / endpoint..."; \
curl -s -o /dev/null -w "%{http_code}" http://localhost:$(PORT)/ | grep -q '^200$$'; \
echo "Testing /health endpoint..."; \
curl -s http://localhost:$(PORT)/health | grep -q '"status":"ok"'; \
echo "Smoke tests passed."; \
)
build:
python3 -m py_compile server.py
@echo "Build check passed."
docker-build:
docker build -t $(IMAGE_NAME) .
docker-run:
docker run -d --rm --name $(CONTAINER_NAME) -e PORT=$(PORT) -p $(PORT):$(PORT) $(IMAGE_NAME)
stop:
-docker stop $(CONTAINER_NAME)
-docker rm $(CONTAINER_NAME) 2>/dev/null || true
clean:
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
find . -type f -name '*.pyc' -delete 2>/dev/null || true