-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
151 lines (125 loc) · 5.14 KB
/
Makefile
File metadata and controls
151 lines (125 loc) · 5.14 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
.PHONY: all install build run clean docker-build docker-up docker-down api-gen bump-patch bump-minor bump-major help test lint monitoring-up monitoring-down
# Project variables
APP_NAME := galvanize
INSTANCER_DIR := galvanize-instancer
DOCKER_IMAGE := galvanize-instancer
DOCKER_COMPOSE := docker-compose.yml
DOCKER_COMPOSE_LOCAL := docker-compose.local.yml
DOCKER_COMPOSE_MONITORING := docker-compose.monitoring.yml
# Go variables
GO := go
GOFLAGS := -v
# Default target
all: build
## help: Show this help message
help:
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@echo " all Build the project (default)"
@echo " install Install Go dependencies"
@echo " build Build the Go binary"
@echo " run Run the application locally"
@echo " clean Clean build artifacts"
@echo " test Run tests"
@echo " lint Run linter"
@echo ""
@echo " docker-build Build Docker image"
@echo " docker-up Start services with docker-compose"
@echo " docker-down Stop services with docker-compose"
@echo " docker-logs Show docker-compose logs"
@echo " docker-local Start services with local docker-compose"
@echo " monitoring-up Start instancer + Prometheus + Grafana (Grafana at http://localhost:3000)"
@echo " monitoring-down Stop monitoring stack"
@echo " monitoring-local-up Start local instancer + Prometheus + Grafana (Grafana at http://localhost:3000)"
@echo " monitoring-local-down Stop local monitoring stack"
@echo ""
@echo " api-gen Generate API code from OpenAPI spec"
@echo " api-spec Generate OpenAPI spec from template"
@echo ""
@echo " bump-patch Bump patch version and commit/tag/push (e.g., 1.2.0 -> 1.2.1)"
@echo " bump-minor Bump minor version and commit/tag/push (e.g., 1.2.0 -> 1.3.0)"
@echo " bump-major Bump major version and commit/tag/push (e.g., 1.2.0 -> 2.0.0)"
@echo ""
@echo " version Show current version"
@echo " tag Create and push a git tag for the current version (manual)"
## install: Install Go dependencies
install:
cd $(INSTANCER_DIR) && $(GO) mod download
cd $(INSTANCER_DIR) && $(GO) mod tidy
## build: Build the Go binary
build:
cd $(INSTANCER_DIR) && $(GO) build $(GOFLAGS) -o $(APP_NAME) .
## run: Run the application locally
run: build
cd $(INSTANCER_DIR) && ./$(APP_NAME) serve --port 8080 --config ../data/config.yaml
## clean: Clean build artifacts
clean:
cd $(INSTANCER_DIR) && rm -f $(APP_NAME)
cd $(INSTANCER_DIR) && $(GO) clean
## test: Run tests
test:
cd $(INSTANCER_DIR) && $(GO) test ./... -v -race -coverprofile=coverage.out
## lint: Run linter (requires golangci-lint)
lint:
cd $(INSTANCER_DIR) && golangci-lint run ./...
## docker-build: Build Docker image
docker-build:
docker build -t $(DOCKER_IMAGE) -f $(INSTANCER_DIR)/Dockerfile .
## docker-up: Start services with docker-compose
docker-up: docker-build
docker compose -f $(DOCKER_COMPOSE) up -d
## docker-down: Stop services with docker-compose
docker-down:
docker compose -f $(DOCKER_COMPOSE) down
## docker-logs: Show docker-compose logs
docker-logs:
docker compose -f $(DOCKER_COMPOSE) logs -f
## docker-local: Start services with local docker-compose
docker-local: docker-build
docker compose -f $(DOCKER_COMPOSE_LOCAL) up -d
## monitoring-up: Start instancer + Prometheus + Grafana (Grafana at http://localhost:3000)
monitoring-up: docker-build
docker compose -f $(DOCKER_COMPOSE) -f $(DOCKER_COMPOSE_MONITORING) up -d
## monitoring-down: Stop monitoring stack
monitoring-down:
docker compose -f $(DOCKER_COMPOSE) -f $(DOCKER_COMPOSE_MONITORING) down
## monitoring-up: Start instancer + Prometheus + Grafana (Grafana at http://localhost:3000)
monitoring-local-up: docker-build
docker compose -f $(DOCKER_COMPOSE_LOCAL) -f $(DOCKER_COMPOSE_MONITORING) up -d
## monitoring-down: Stop monitoring stack
monitoring-local-down:
docker compose -f $(DOCKER_COMPOSE_LOCAL) -f $(DOCKER_COMPOSE_MONITORING) down
## api-spec: Generate OpenAPI spec from template (copies .in to .yaml)
api-spec:
cp $(INSTANCER_DIR)/api/openapi.yaml.in $(INSTANCER_DIR)/api/openapi.yaml
## api-gen: Generate API code from OpenAPI spec
api-gen: api-spec
cd $(INSTANCER_DIR) && $(GO) generate ./api/...
## bump-patch: Bump patch version and commit/tag/push
bump-patch:
./scripts/bump_version.sh patch
## bump-minor: Bump minor version and commit/tag/push
bump-minor:
./scripts/bump_version.sh minor
## bump-major: Bump major version and commit/tag/push
bump-major:
./scripts/bump_version.sh major
## version: Show current version
version:
@grep -oP 'Version = "\K[0-9]+\.[0-9]+\.[0-9]+' $(INSTANCER_DIR)/constants.go
## tag: Create and push a git tag for the current version
tag:
@VERSION=$$(grep -oP 'Version = "\K[0-9]+\.[0-9]+\.[0-9]+' $(INSTANCER_DIR)/constants.go); \
BRANCH=$$(git rev-parse --abbrev-ref HEAD); \
if [ "$$BRANCH" != "master" ]; then \
echo "Error: Not on master branch (currently on $$BRANCH)"; \
exit 1; \
fi; \
if git rev-parse "v$$VERSION" >/dev/null 2>&1; then \
echo "Error: Tag v$$VERSION already exists"; \
exit 1; \
fi; \
git tag -a "v$$VERSION" -m "Release v$$VERSION"; \
git push origin "v$$VERSION"; \
echo "Tagged and pushed v$$VERSION"