-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
152 lines (135 loc) · 3.95 KB
/
Makefile
File metadata and controls
152 lines (135 loc) · 3.95 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
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
# ProxiMeter Makefile
# Build, run, test, and push Docker images
# Configuration
IMAGE_NAME := proximeter/rtsp-streams
IMAGE_TAG := dev
PLATFORM := linux/amd64
APP_PORT := 8000
REGISTRY := ghcr.io/clsferguson
FULL_IMAGE := $(REGISTRY)/proximeter:latest
# Default target
.PHONY: help
help:
@echo "ProxiMeter - RTSP Stream Manager"
@echo ""
@echo "Available targets:"
@echo " make build - Build Docker image (linux/amd64)"
@echo " make run - Run container locally"
@echo " make stop - Stop running container"
@echo " make logs - View container logs"
@echo " make test - Run tests in container"
@echo " make shell - Open shell in running container"
@echo " make clean - Remove container and image"
@echo " make push - Push image to registry"
@echo " make health - Check health endpoint"
@echo " make metrics - View Prometheus metrics"
@echo " make dry-run - Test build with CI_DRY_RUN=true"
@echo ""
@echo "Environment variables:"
@echo " APP_PORT=$(APP_PORT)"
@echo " IMAGE_NAME=$(IMAGE_NAME)"
@echo " IMAGE_TAG=$(IMAGE_TAG)"
@echo " PLATFORM=$(PLATFORM)"
# Build Docker image with buildx
.PHONY: build
build:
@echo "Building Docker image for $(PLATFORM)..."
docker buildx build \
--platform $(PLATFORM) \
--tag $(IMAGE_NAME):$(IMAGE_TAG) \
--load \
.
@echo "Build complete: $(IMAGE_NAME):$(IMAGE_TAG)"
# Run container locally
.PHONY: run
run:
@echo "Starting container on port $(APP_PORT)..."
docker run -d \
--name proximeter-rtsp-streams \
--platform $(PLATFORM) \
-p $(APP_PORT):$(APP_PORT) \
-v $(PWD)/config:/app/config \
-e APP_PORT=$(APP_PORT) \
-e LOG_LEVEL=INFO \
--restart unless-stopped \
$(IMAGE_NAME):$(IMAGE_TAG)
@echo "Container started. Access at http://localhost:$(APP_PORT)"
@echo "Run 'make logs' to view logs"
# Stop and remove container
.PHONY: stop
stop:
@echo "Stopping container..."
-docker stop proximeter-rtsp-streams
-docker rm proximeter-rtsp-streams
@echo "Container stopped and removed"
# View container logs
.PHONY: logs
logs:
docker logs -f proximeter-rtsp-streams
# Run tests (pytest in container)
.PHONY: test
test:
@echo "Running tests..."
docker run --rm \
--platform $(PLATFORM) \
-v $(PWD)/tests:/app/tests \
-e CI_DRY_RUN=false \
$(IMAGE_NAME):$(IMAGE_TAG) \
sh -c "pip install pytest pytest-asyncio && pytest tests/ -v"
# Open shell in running container
.PHONY: shell
shell:
docker exec -it proximeter-rtsp-streams /bin/bash
# Clean up container and image
.PHONY: clean
clean: stop
@echo "Removing image..."
-docker rmi $(IMAGE_NAME):$(IMAGE_TAG)
@echo "Cleanup complete"
# Push image to registry
.PHONY: push
push:
@echo "Tagging image for registry..."
docker tag $(IMAGE_NAME):$(IMAGE_TAG) $(FULL_IMAGE)
@echo "Pushing to $(FULL_IMAGE)..."
docker push $(FULL_IMAGE)
@echo "Push complete"
# Check health endpoint
.PHONY: health
health:
@echo "Checking health endpoint..."
@curl -s http://localhost:$(APP_PORT)/health | jq . || curl -s http://localhost:$(APP_PORT)/health
# View Prometheus metrics
.PHONY: metrics
metrics:
@echo "Fetching Prometheus metrics..."
@curl -s http://localhost:$(APP_PORT)/metrics
# Test build with CI_DRY_RUN
.PHONY: dry-run
dry-run:
@echo "Testing build with CI_DRY_RUN=true..."
docker run --rm \
--platform $(PLATFORM) \
-e CI_DRY_RUN=true \
$(IMAGE_NAME):$(IMAGE_TAG)
@echo "Dry run successful - container built and dependencies verified"
# Rebuild and restart (convenience target)
.PHONY: rebuild
rebuild: stop build run
@echo "Rebuild and restart complete"
# Run with docker-compose
.PHONY: compose-up
compose-up:
@echo "Starting with docker-compose..."
docker compose up --build -d
@echo "Services started. Access at http://localhost:$(APP_PORT)"
# Stop docker-compose
.PHONY: compose-down
compose-down:
@echo "Stopping docker-compose services..."
docker compose down
@echo "Services stopped"
# View docker-compose logs
.PHONY: compose-logs
compose-logs:
docker compose logs -f