-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
132 lines (99 loc) · 4.54 KB
/
Makefile
File metadata and controls
132 lines (99 loc) · 4.54 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
.PHONY: help db-start db-stop db-restart db-logs db-clean seed-data build run test clean docker-build docker-build-tag docker-push docker-build-push dev-sqlite dev-postgres
# Default target
help: ## Show this help message
@echo "Available commands:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
# Development environment setup
dev-postgres: ## Run the application locally with database
@echo "Setting up PostgreSQL development environment..."
@cp .env.production .env 2>/dev/null || true
@echo "Environment configured for PostgreSQL. Starting application..."
@echo "Starting database and waiting for it to be ready..."
make db-start
@sleep 3
go run ./cmd/api
# Database commands (PostgreSQL)
db-start: ## Start PostgreSQL database container
docker compose up -d postgres
db-stop: ## Stop PostgreSQL database container
docker compose stop postgres
db-restart: ## Restart PostgreSQL database container
docker compose restart postgres
db-logs: ## Show PostgreSQL database logs
docker compose logs -f postgres
db-clean: ## Stop and remove PostgreSQL container and volumes
docker compose down postgres
docker volume rm commercify_postgres_data 2>/dev/null || true
# Seed data
seed-data: ## Seed database with sample data
docker compose run --rm seed -all
# Application commands
build: ## Build the application
go build -o bin/api ./cmd/api
go build -o bin/seed ./cmd/seed
go build -o bin/expire-checkouts ./cmd/expire-checkouts
run:
@echo "Setting up SQLite development environment..."
@cp .env.local .env 2>/dev/null || true
@echo "Environment configured for SQLite. Starting application..."
go run ./cmd/api
run-docker: ## Run the entire application stack with Docker (PostgreSQL)
docker compose up -d
run-docker-sqlite: ## Run the application with Docker using SQLite
docker compose -f docker-compose.local.yml up -d
stop-docker: ## Stop the entire application stack
docker compose down
stop-docker-sqlite: ## Stop the SQLite application stack
docker compose -f docker-compose.local.yml down
logs: ## Show application logs
docker compose logs -f api
logs-sqlite: ## Show SQLite application logs
docker compose -f docker-compose.local.yml logs -f api
# Docker image commands
docker-build: ## Build Docker image
docker build -t ghcr.io/zenfulcode/commercifygo:latest .
docker-build-tag: ## Build Docker image with specific tag (use TAG=version)
@if [ -z "$(TAG)" ]; then echo "Error: TAG is required. Use: make docker-build-tag TAG=v1.0.0"; exit 1; fi
docker build -t ghcr.io/zenfulcode/commercifygo:$(TAG) -t ghcr.io/zenfulcode/commercifygo:latest -t ghcr.io/zenfulcode/commercifygo:dev .
docker-push: ## Push Docker image to registry (use REGISTRY and TAG)
@if [ -z "$(REGISTRY)" ]; then echo "Error: REGISTRY is required. Use: make docker-push REGISTRY=your-registry.com"; exit 1; fi
@if [ -z "$(TAG)" ]; then echo "Error: TAG is required. Use: make docker-push REGISTRY=your-registry.com TAG=v1.0.0"; exit 1; fi
# docker tag $(REGISTRY)commercifygo:$(TAG) $(REGISTRY)/commercifygo:$(TAG)
# docker tag $(REGISTRY)commercifygo:latest $(REGISTRY)/commercifygo:latest
docker push $(REGISTRY)/commercifygo:$(TAG)
docker push $(REGISTRY)/commercifygo:latest
docker push $(REGISTRY)/commercifygo:dev
docker-build-push: docker-build-tag docker-push ## Build and push Docker image (use REGISTRY and TAG)
docker-dev-push: ## Build Docker image for development
docker build -t ghcr.io/zenfulcode/commercifygo:v2-dev .
docker push ghcr.io/zenfulcode/commercifygo:v2-dev
test: ## Run tests with verbose output
go test -v ./...
clean: ## Clean build artifacts
rm -rf bin/
go clean
# Database setup commands
dev-setup: ## Setup development environment with PostgreSQL (start db, seed)
make db-start
@sleep 3
make seed-data
@echo "Development environment ready with PostgreSQL!"
dev-reset: db-clean db-start seed-data ## Reset PostgreSQL development environment
@echo "Development environment reset with PostgreSQL!"
dev-reset-sqlite: ## Reset SQLite development environment
@echo "Resetting SQLite development environment..."
@rm -f commercify.db 2>/dev/null || true
@cp .env.local .env 2>/dev/null || true
@echo "SQLite database reset!"
# Format and lint
fmt: ## Format Go code
go fmt ./...
vet: ## Run go vet
go vet ./...
tygo:
@tygo generate
# Maintenance commands
expire-checkouts: ## Expire old checkouts manually
go run ./cmd/expire-checkouts
force-delete-checkouts: ## Force delete all expired, abandoned, and old completed checkouts
go run ./cmd/expire-checkouts -force