Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
82 lines (67 loc) · 2.17 KB
/
Copy pathMakefile
File metadata and controls
82 lines (67 loc) · 2.17 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
include .env
export
.PHONY: help build run run-docker migrate-up migrate-down clean test
# Variables
APP_NAME := musi-be
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_DIR := bin
# Default target
help:
@echo "Available targets:"
@echo " help - Show this help message"
@echo " build - Build the application"
@echo " run - Run the application"
@echo " run-docker - Run the application using container"
@echo " migrate-up - Run database migrations"
@echo " migrate-down- Rollback database migrations"
@echo " clean - Clean build artifacts"
@echo " test - Run tests"
# Build application
build:
@echo "Building $(APP_NAME)..."
@mkdir -p $(BUILD_DIR)
@go build -o $(BUILD_DIR)/$(APP_NAME) ./cmd/api
# Run application
run:
@echo "Running $(APP_NAME)..."
@go run ./cmd/api
run-docker:
@echo "Running $(APP_NAME)..."
@docker compose up -d --build --force-recreate
# Run database migrations up
migrate-up:
@echo "Running database migrations..."
@migrate -path ./migrations -database "postgres://$(DB_USER):$(DB_PASSWORD)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=$(DB_SSLMODE)" up
# Rollback database migrations
migrate-down:
@echo "Rolling back database migrations..."
@migrate -path ./migrations -database "postgres://$(DB_USER):$(DB_PASSWORD)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=$(DB_SSLMODE)" down
# Create new migration
migrate-create:
@if [ -z "$(NAME)" ]; then echo "Usage: make migrate-create NAME=migration_name"; exit 1; fi
@migrate create -ext sql -dir ./migrations -seq $(NAME)
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR)
# Run tests
test:
@echo "Running tests..."
@go test -v ./...
# Install dependencies
deps:
@echo "Installing dependencies..."
@go mod tidy
@go mod download
# Generate Wire dependencies
generate:
@echo "Generating dependency injection code..."
@wire
# Development setup
dev-setup: deps
@echo "Setting up development environment..."
@cp .env.example .env 2>/dev/null || true
@echo "Please edit .env file with your database configuration"
# Development workflow
dev: generate build
@echo "Development setup complete!"