-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
133 lines (110 loc) · 4.64 KB
/
Makefile
File metadata and controls
133 lines (110 loc) · 4.64 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
SHELL := /bin/bash
# ⚙️ Configuration
APP ?= water_system
DOCKER_COMPOSE := COMPOSE_BAKE=true docker compose
VAULT ?= ansible-vault
GOLANGCI_LINT_VERSION ?= v2.11.4
# Default goal
.DEFAULT_GOAL := help
# ────────────────────────────────────────────────────────────────
# 🐳 Docker
# ────────────────────────────────────────────────────────────────
.PHONY: create-network
create-network:
@set -euo pipefail; \
echo "🚀 Creating $(APP) network..."; \
docker network create $(APP)
.PHONY: docker-up
docker-up: create-network
@set -euo pipefail; \
echo "🚀 Starting services with Docker Compose..."; \
$(DOCKER_COMPOSE) up -d --build
.PHONY: docker-down
docker-down:
@set -euo pipefail; \
echo "🛑 Stopping and removing Docker Compose services..."; \
$(DOCKER_COMPOSE) down
.PHONY: docker-ps
docker-ps:
@set -euo pipefail; \
echo "📋 Active services:"; \
$(DOCKER_COMPOSE) ps
.PHONY: docker-exec
docker-exec:
@set -euo pipefail; \
echo "🔎 Opening shell inside ..."; \
$(DOCKER_COMPOSE) exec $(APP) sh
.PHONY: docker-logs
docker-logs:
@set -euo pipefail; \
echo "👀 Showing logs for container $(APP) (CTRL+C to exit)..."; \
docker logs -f $(APP)
# ────────────────────────────────────────────────────────────────
# 🧹 Code quality: format, lint, tests
# ────────────────────────────────────────────────────────────────
.PHONY: fmt
fmt:
@set -euo pipefail; \
echo "👉 Formatting code with gofumpt..."; \
go tool gofumpt -w .
.PHONY: security
security:
@set -euo pipefail; \
echo "👉 Check security"; \
go tool govulncheck ./...
.PHONY: install-lint
install-lint:
@set -euo pipefail; \
echo "🔧 Installing golangci-lint $(GOLANGCI_LINT_VERSION)..."; \
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
.PHONY: lint
lint: install-lint
@set -euo pipefail; \
echo "🚀 Executing golangci-lint..."; \
golangci-lint run ./...
.PHONY: test
test:
@set -euo pipefail; \
echo "🧪 Running unit tests (race, JSON → tparse)..."; \
go test -race ./... -json -cover -coverprofile=coverage.out| go tool tparse -all
.PHONY: test-functional
test-functional:
@set -euo pipefail; \
echo "🧪 Running functional tests..."; \
# Example: adjust to your own functional test suite
go test -tags=functional ./... -v
check: fmt security lint test
.PHONY: generate-schema
generate-schema:
@set -euo pipefail; \
echo "🧪 Generating code from json schemas..."; \
devops/scripts/import_jsonschema.sh
.PHONY: clean
clean:
@set -euo pipefail; \
echo "🧹 Cleaning local artifacts..."; \
rm -rf bin dist coverage .*cache || true; \
go clean -testcache
edit-vault:
@set -euo pipefail; \
echo "🏗️ Editing vault file"; \
$(VAULT) edit devops/ansible/inventories/production/group_vars/raspberry_water_system/vault.yml
# ────────────────────────────────────────────────────────────────
# 🏗️ Build & Deploy
# ────────────────────────────────────────────────────────────────
build: clean
@set -euo pipefail; \
echo "🏗️ Building ARM64 binary for Raspberry Pi..."; \
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 \
go build -a -ldflags "-s -w" -tags prod -buildvcs=false \
-o devops/ansible/assets/server ./cmd/server/
deploy: build
@set -euo pipefail; \
echo "🚚 Deploying with Ansible (production inventory)..."; \
ansible-playbook -i devops/ansible/inventories/production/hosts devops/ansible/deploy.yml --ask-vault-pass
# ────────────────────────────────────────────────────────────────
# ℹ️ Help
# ────────────────────────────────────────────────────────────────
help:
@echo "Available commands:"
@grep -E '^[a-zA-Z_-]+:' Makefile | awk -F':' '{print " - " $$1}'