Refactor MQTT course and bound backend message processing
Move lesson source into the teaching structure, align the course path with the learner's Go and DevOps experience, and add the interactive lesson guides. Add advanced DevOps lifecycle study as a separate section. Bound MQTT message work and drain accepted jobs during shutdown; align the backend implementation with the revised course through Section 6.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
GO ?= go
|
||||
DOCKER_COMPOSE ?= docker compose
|
||||
|
||||
CONFIG ?= configs/lab.toml
|
||||
DEVICE_ID ?= device-001
|
||||
BACKEND_CLIENT_ID ?= lab-backend
|
||||
SIMULATOR_CLIENT_ID ?= lab-simulator-$(DEVICE_ID)
|
||||
BIN_DIR ?= bin
|
||||
|
||||
.PHONY: help build configcheck broker-up broker-down broker-logs backend simulator lab-up
|
||||
|
||||
help: ## List available commands
|
||||
@awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z0-9_-]+:.*##/ {printf "%-16s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
||||
|
||||
build: ## Build the backend, simulator, and config checker into $(BIN_DIR)/
|
||||
@mkdir -p $(BIN_DIR)
|
||||
$(GO) build -o $(BIN_DIR)/backend ./cmd/backend
|
||||
$(GO) build -o $(BIN_DIR)/simulator ./cmd/simulator
|
||||
$(GO) build -o $(BIN_DIR)/configcheck ./cmd/configcheck
|
||||
|
||||
configcheck: ## Validate the lab configuration and credentials
|
||||
$(GO) run ./cmd/configcheck -config $(CONFIG) -username backend
|
||||
|
||||
broker-up: ## Start the Mosquitto lab broker in the background
|
||||
$(DOCKER_COMPOSE) -f compose.yml up -d broker
|
||||
|
||||
broker-down: ## Stop the broker without deleting its volumes
|
||||
$(DOCKER_COMPOSE) -f compose.yml down
|
||||
|
||||
broker-logs: ## Follow broker logs
|
||||
$(DOCKER_COMPOSE) -f compose.yml logs --follow broker
|
||||
|
||||
backend: broker-up ## Ensure the broker is running, then run the backend (Ctrl+C to stop)
|
||||
$(GO) run ./cmd/backend -config $(CONFIG) -username backend -client-id $(BACKEND_CLIENT_ID) -device-id $(DEVICE_ID)
|
||||
|
||||
simulator: broker-up ## Ensure the broker is running, then run the simulator (Ctrl+C to stop)
|
||||
$(GO) run ./cmd/simulator -config $(CONFIG) -username simulator -client-id $(SIMULATOR_CLIENT_ID) -device-id $(DEVICE_ID)
|
||||
|
||||
lab-up: build ## Build everything, start the broker, then run both services together
|
||||
$(DOCKER_COMPOSE) -f compose.yml up -d broker
|
||||
@set -m; \
|
||||
trap 'kill "$$simulator_pid" "$$backend_pid" 2>/dev/null || true; wait "$$simulator_pid" "$$backend_pid" 2>/dev/null || true' EXIT INT TERM; \
|
||||
$(BIN_DIR)/simulator -config $(CONFIG) -username simulator -client-id $(SIMULATOR_CLIENT_ID) -device-id $(DEVICE_ID) & simulator_pid=$$!; \
|
||||
$(BIN_DIR)/backend -config $(CONFIG) -username backend -client-id $(BACKEND_CLIENT_ID) -device-id $(DEVICE_ID) & backend_pid=$$!; \
|
||||
wait "$$simulator_pid" "$$backend_pid"
|
||||
Reference in New Issue
Block a user