-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
172 lines (132 loc) · 6.63 KB
/
Copy pathMakefile
File metadata and controls
172 lines (132 loc) · 6.63 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
.PHONY: all proto-gen proto-gen-go proto-gen-py proto-lint proto-breaking \
go-build go-test go-lint go-fmt \
docker-go-test docker-go-lint docker-go-fmt \
py-test py-lint py-fmt \
docker-py-test docker-py-lint docker-py-fmt \
docker-build docker-up docker-down docker-logs \
deps deps-go deps-py lint docker-lint
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
DOCKER_GO_IMAGE ?= golang:1.22-alpine
DOCKER_PY_IMAGE ?= python:3.12-slim
GOLANGCI_LINT_VERSION ?= v1.64.8
# Source is mounted read-only; a named volume provides a writable module/build
# cache that persists across runs so repeated invocations stay fast.
DOCKER_GO_RUN := docker run --rm \
-v "$(ROOT_DIR):/workspace:ro" \
-v iot-sim-gocache:/root/.cache \
-v iot-sim-gopath:/go \
-w /workspace/device-runtime \
$(DOCKER_GO_IMAGE)
# Source is mounted read-only; pip cache is persisted in a named volume.
DOCKER_PY_RUN := docker run --rm \
-v "$(ROOT_DIR)/orchestrator:/workspace:ro" \
-v iot-sim-pipcache:/root/.cache/pip \
-w /workspace \
$(DOCKER_PY_IMAGE)
# ── Dependencies ────────────────────────────────────────────────────────────
GOLANGCI_LINT := $(shell go env GOPATH)/bin/golangci-lint
GOIMPORTS := $(shell go env GOPATH)/bin/goimports
# Fetch/tidy Go modules and install Go dev tools.
deps-go:
cd device-runtime && go mod tidy
@test -f $(GOLANGCI_LINT) || go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
@test -f $(GOIMPORTS) || go install golang.org/x/tools/cmd/goimports@latest
# Install Python dependencies via pipenv.
deps-py:
cd orchestrator && pipenv install --dev
deps: deps-go deps-py
# ── Proto ────────────────────────────────────────────────────────────────────
proto-gen: proto-gen-go proto-gen-py
proto-gen-go:
buf generate
proto-gen-py:
cd orchestrator && pipenv run python -m grpc_tools.protoc \
-I ../proto \
-I $$(pipenv run python -c "import grpc_tools, os; print(os.path.join(os.path.dirname(grpc_tools.__file__), '_proto'))") \
--python_out=gen/python \
--grpc_python_out=gen/python \
../proto/simulator/v1/*.proto
proto-lint:
buf lint
proto-breaking:
buf breaking --against '.git#branch=main'
# ── Go ───────────────────────────────────────────────────────────────────────
go-build:
cd device-runtime && go build ./cmd/runtime
go-test:
cd device-runtime && go test ./...
# Auto-fix Go import ordering and formatting.
go-fmt:
@test -f $(GOIMPORTS) || go install golang.org/x/tools/cmd/goimports@latest
cd device-runtime && $(GOIMPORTS) -w -local github.com/virtual-iot-simulator ./...
cd device-runtime && gofmt -w ./...
# Auto-installs golangci-lint to $(GOPATH)/bin if missing.
go-lint:
@test -f $(GOLANGCI_LINT) || go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
cd device-runtime && $(GOLANGCI_LINT) run ./...
# ── Python ───────────────────────────────────────────────────────────────────
py-test:
cd orchestrator && pipenv run pytest tests/ -v
# Check formatting and lint (CI-safe: no writes).
py-lint:
cd orchestrator && pipenv run ruff format --check .
cd orchestrator && pipenv run ruff check .
# Auto-fix formatting and safe lint issues.
py-fmt:
cd orchestrator && pipenv run ruff format .
cd orchestrator && pipenv run ruff check --fix .
# ── Docker — image builds & compose ─────────────────────────────────────────
docker-build:
docker build -f deployments/Dockerfile.runtime -t iot-simulator-runtime:latest .
docker build -f deployments/Dockerfile.orchestrator -t iot-simulator-orchestrator:latest .
docker build -f deployments/Dockerfile.frontend -t iot-simulator-frontend:latest .
docker-up:
docker compose -f deployments/docker-compose.yaml up -d
docker-down:
docker compose -f deployments/docker-compose.yaml down
docker-logs:
docker compose -f deployments/docker-compose.yaml logs -f
# ── Docker — Go: test / lint / fmt ──────────────────────────────────────────
# These targets run inside a plain golang image — no local Go install needed.
docker-go-test:
$(DOCKER_GO_RUN) sh -c "go test ./..."
docker-go-lint:
$(DOCKER_GO_RUN) sh -c "\
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) && \
golangci-lint run ./..."
# fmt writes back to the host via a rw mount (goimports + gofmt).
docker-go-fmt:
docker run --rm \
-v "$(ROOT_DIR)/device-runtime:/workspace" \
-w /workspace \
$(DOCKER_GO_IMAGE) sh -c "\
go install golang.org/x/tools/cmd/goimports@latest && \
goimports -w -local github.com/virtual-iot-simulator ./... && \
gofmt -w ./..."
# ── Docker — Python: test / lint / fmt ──────────────────────────────────────
# These targets run inside a plain python image — no pipenv needed on the host.
DOCKER_PY_INSTALL := pip install --quiet --no-cache-dir \
grpcio grpcio-tools protobuf typer pydantic pyyaml rich fastapi \
"uvicorn[standard]" pytest pytest-asyncio httpx ruff
docker-py-test:
$(DOCKER_PY_RUN) sh -c "$(DOCKER_PY_INSTALL) && pytest tests/ -v"
docker-py-lint:
$(DOCKER_PY_RUN) sh -c "\
pip install --quiet --no-cache-dir ruff && \
ruff format --check . && \
ruff check ."
# fmt writes back to the host via a rw mount.
docker-py-fmt:
docker run --rm \
-v "$(ROOT_DIR)/orchestrator:/workspace" \
-w /workspace \
$(DOCKER_PY_IMAGE) sh -c "\
pip install --quiet --no-cache-dir ruff && \
ruff format . && \
ruff check --fix ."
# Run all Docker-based checks (no local toolchain required).
docker-lint: docker-go-lint docker-py-lint
# ── All ──────────────────────────────────────────────────────────────────────
# Run all checks (lint + build + test). Used in CI.
lint: go-lint py-lint
all: proto-lint proto-gen go-build go-test go-lint py-test py-lint