-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
84 lines (67 loc) · 2.04 KB
/
Makefile
File metadata and controls
84 lines (67 loc) · 2.04 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
.PHONY: run build test clean dev docker-build docker-run deploy-build
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GORUN=$(GOCMD) run
GOTEST=$(GOCMD) test
GOMOD=$(GOCMD) mod
BINARY_NAME=shotify
# Version info
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME ?= $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
LDFLAGS = -ldflags="-w -s -X main.Version=$(VERSION) -X main.GitCommit=$(GIT_COMMIT) -X main.BuildTime=$(BUILD_TIME)"
# Build the application
build:
$(GOBUILD) -o bin/$(BINARY_NAME) cmd/main.go
# Run the application
run:
$(GORUN) cmd/main.go
# Run with hot reload (requires air: go install github.com/cosmtrek/air@latest)
dev:
air
# Download dependencies
deps:
$(GOMOD) download
$(GOMOD) tidy
# Run tests
test:
$(GOTEST) -v -race ./...
# Run tests with coverage
test-coverage:
$(GOTEST) -v -race -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
# Run go vet
vet:
$(GOCMD) vet ./...
# Clean build files
clean:
rm -rf bin/ coverage.out coverage.html
# Build for production (Linux amd64)
build-prod:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -a -installsuffix cgo $(LDFLAGS) -o bin/$(BINARY_NAME) cmd/main.go
# Docker build with version info
docker-build:
docker build \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg BUILD_TIME=$(BUILD_TIME) \
-t shotify-backend:$(VERSION) \
-t shotify-backend:latest \
.
# Docker run
docker-run:
docker run -p 8080:8080 --env-file .env shotify-backend:latest
# Build and start production stack
deploy-local:
VERSION=$(VERSION) GIT_COMMIT=$(GIT_COMMIT) BUILD_TIME=$(BUILD_TIME) \
docker compose -f docker-compose.prod.yml up -d --build
# Stop production stack
deploy-stop:
docker compose -f docker-compose.prod.yml down
# View production logs
deploy-logs:
docker compose -f docker-compose.prod.yml logs -f
# Full CI check (what runs in pipeline)
ci: vet test build-prod
@echo "CI checks passed ✅"