-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
164 lines (138 loc) · 4.6 KB
/
Makefile
File metadata and controls
164 lines (138 loc) · 4.6 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
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
# Setting SHELL to sh for compatibility.
# Options are set to exit when a recipe line exits non-zero.
SHELL = /usr/bin/env sh
.SHELLFLAGS = -ec
GO?=go
GOFLAGS?=
# Default target
.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# Generate SQLC code
.PHONY: sqlc
sqlc: ## Generate Go code from SQL using SQLC
@echo "Generating SQLC code..."
$(GO) tool sqlc generate
# Generate Go code only
.PHONY: generate
generate: sqlc
@echo "Generating Go code..."
$(GO) generate ./...
# Generate code (including web client)
.PHONY: generate-webclient
generate-webclient:
@echo "Generating web client..."
rm -rf web/src/client/ && docker run --rm -v "$$(pwd):/local" openapitools/openapi-generator-cli generate \
-i /local/api/v1/openapi.yaml \
-g typescript-fetch \
-o /local/web/src/client
# Generate API documentation
.PHONY: generate-apidoc
generate-apidoc:
docker run --rm -v "$$(pwd):/local" openapitools/openapi-generator-cli generate \
-i /local/api/v1/openapi.yaml \
-g html2 \
-o /local/docs/api/
# Download dependencies
.PHONY: deps
deps: ## Download Go dependencies
@echo "Downloading dependencies..."
$(GO) mod download
$(GO) mod tidy
# Build the application
.PHONY: build
build: submodule-update deps generate ## Build the application
@echo "Building application..."
$(GO) build $(GOFLAGS) -o bin/threadmirror ./cmd/*.go
# Build for Docker (without web client generation)
.PHONY: build-docker
build-docker: submodule-update deps generate ## Build application for Docker
@echo "Building application for Docker..."
$(GO) build -o bin/threadmirror ./cmd/*.go
# Run the application
.PHONY: run
run: build ## Run the application
@echo "Running application..."
./bin/threadmirror server
# Run development server
.PHONY: dev
dev: ## Run development server
@echo "Starting development server..."
$(GO) run ./cmd/*.go --debug server
# Run tests with testcontainers (default)
.PHONY: test
test: ## Run tests with testcontainers (requires Docker)
@echo "Running tests with testcontainers..."
@echo "Note: Docker is required for these tests"
$(GO) test -v ./...
# Run unit tests without Docker
.PHONY: test-unit
test-unit: ## Run unit tests without Docker (skips integration tests)
@echo "Running unit tests (skipping Docker-dependent tests)..."
$(GO) test -short -v ./...
# Clean build artifacts
.PHONY: clean
clean: ## Clean build artifacts
@echo "Cleaning build artifacts..."
rm -rf bin/
# Lint code
.PHONY: lint
lint: ## Run linter
@echo "Running linter..."
$(GO) tool golangci-lint run
# Lint code and fixing it
.PHONY: lint-fix
lint-fix: ## Run linter and fixing it
@echo "Running linter and fixing it..."
$(GO) tool golangci-lint run --fix
# Development setup
.PHONY: setup
setup: deps generate ## Setup development environment
@echo "Development environment setup complete!"
# Database migration
.PHONY: migrate
migrate: build ## Run database migrations
@echo "Running database migrations..."
./bin/threadmirror migrate
# Docker variables
DOCKER_IMAGE_NAME ?= threadmirror
DOCKER_TAG ?= latest
DOCKER_REGISTRY ?= 0x5459
# Build Docker image
.PHONY: docker-build
docker-build: ## Build Docker image
@echo "Building Docker image..."
docker build --platform linux/amd64 -t $(DOCKER_IMAGE_NAME):$(DOCKER_TAG) .
# Run Docker container in background
.PHONY: docker-run
docker-run: ## Run Docker container in detached mode
@echo "Running Docker container in background..."
docker rm threadmirror-container || true
docker run -p 8080:8080 \
--name threadmirror-container \
-it --rm \
--env-file .env \
$(DOCKER_IMAGE_NAME):$(DOCKER_TAG)
# Push Docker image to registry
.PHONY: docker-push
docker-push: docker-build ## Push Docker image to registry
@echo "Pushing Docker image to registry..."
echo "Tagging and pushing to registry: $(DOCKER_REGISTRY)"
docker tag $(DOCKER_IMAGE_NAME):$(DOCKER_TAG) $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(DOCKER_TAG)
docker push $(DOCKER_REGISTRY)/$(DOCKER_IMAGE_NAME):$(DOCKER_TAG)
# Full Docker workflow
.PHONY: docker-all
docker-all: docker-build docker-run ## Clean, build and run Docker container
# Update git submodules
.PHONY: submodule-update
submodule-update: ## Update git submodules
@git submodule update --init --recursive
.PHONY: ruler
ruler:
npx --yes @intellectronica/ruler apply
.PHONY: fmt-sql
fmt-sql:
npx --yes pg-formatter -c .pg_format -i supabase/schemas/*.sql
npx --yes pg-formatter -c .pg_format -i supabase/schemas/*/*.sql
npx --yes pg-formatter -c .pg_format -i sql/queries/*.sql