-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
122 lines (92 loc) · 2.83 KB
/
Makefile
File metadata and controls
122 lines (92 loc) · 2.83 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
.PHONY: all build run clean test migrate-up migrate-down db-reset
# Application name
APP_NAME=chichi-api
# Main binary location
BINARY=cmd/server/main.go
# Build directory
BUILD_DIR=./build
# Configuration
ENV_FILE_DEV=.env.local
ENV_FILE_PROD=.env.prod
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOMOD=$(GOCMD) mod
GOGET=$(GOCMD) get
GORUN=$(GOCMD) run
MAIN_RUN = ./cmd/server/main.go
# Default target
all: test build
# Build the application
build:
mkdir -p $(BUILD_DIR)
$(GOBUILD) -o $(BUILD_DIR)/$(APP_NAME) $(BINARY)
@echo "Build successful!"
# Run the application
run:
$(GORUN) $(BINARY)
# Clean build artifacts
clean:
$(GOCLEAN)
rm -rf $(BUILD_DIR)
# Run tests
test:
$(GOTEST) -v ./...
# Download dependencies
deps:
$(GOMOD) tidy
# Database operations
migrate-up:
./scripts/db-migrate.sh migrate
migrate-down:
./scripts/db-migrate.sh drop
db-reset:
./scripts/db-migrate.sh reset
# Swagger documentation
swagger:
@echo "Generating Swagger documentation..."
swag init -g ./cmd/server/main.go -o ./cmd/swag/docs
# Development - live reload (requires air: https://github.com/cosmtrek/air)
dev:
air
# Docker commands
docker-build:
docker build -t $(APP_NAME):latest -f environment/prod/Dockerfile .
docker-run:
docker run -p 8800:8800 --env-file $(ENV_FILE_DEV) $(APP_NAME):latest
# Docker Compose Development commands
docker-dev-up:
docker compose --env-file $(ENV_FILE_DEV) -f environment/dev/docker-compose.yml up
docker-dev-build:
docker compose --env-file $(ENV_FILE_DEV) -f environment/dev/docker-compose.yml build
docker-dev-down:
docker compose --env-file $(ENV_FILE_DEV) -f environment/dev/docker-compose.yml down
docker-dev-logs:
docker compose --env-file $(ENV_FILE_DEV) -f environment/dev/docker-compose.yml logs -f
docker-dev-clean:
docker compose --env-file $(ENV_FILE_DEV) -f environment/dev/docker-compose.yml down -v --rmi all
# Docker Compose Production commands
docker-prod-up:
docker compose --env-file $(ENV_FILE_PROD) -f environment/prod/docker-compose.yml up -d
docker-prod-build:
docker compose --env-file $(ENV_FILE_PROD) -f environment/prod/docker-compose.yml build
docker-prod-down:
docker compose --env-file $(ENV_FILE_PROD) -f environment/prod/docker-compose.yml down
docker-prod-logs:
docker compose --env-file $(ENV_FILE_PROD) -f environment/prod/docker-compose.yml logs -f
docker-prod-clean:
docker compose --env-file $(ENV_FILE_PROD) -f environment/prod/docker-compose.yml down -v --rmi all
# Check production status
docker-prod-status:
docker ps | grep $(APP_NAME)
# Environment file helpers
show-env-dev:
cat $(ENV_FILE_DEV)
show-env-prod:
cat $(ENV_FILE_PROD)
create-env-prod-from-dev:
cp $(ENV_FILE_DEV) $(ENV_FILE_PROD)
@echo "Created $(ENV_FILE_PROD) from $(ENV_FILE_DEV). Please update it with production values."
docker logs $(APP_NAME)-prod -f